2 * Performs a regular parse, but determines whether the coroutine keyword
3 * appears in the file so that we know whether to lower coroutines through
4 * a conversion of the positioned syntax to an editable positioned syntax
8 module ParserEnv
= Full_fidelity_parser_env
9 module TokenKind
= Full_fidelity_token_kind
11 let ppl_macro_string = "__PPL"
13 module WithSyntax
(Syntax
: Positioned_syntax_sig.PositionedSyntax_S
) = struct
15 type r
= Syntax.t
[@@deriving show
]
17 type t
= bool [@@deriving show
]
19 let env : ParserEnv.t
ref = ref @@ ParserEnv.make
()
25 let next state _
= state
28 module SyntaxSC_
= SyntaxSmartConstructors.WithSyntax
(Syntax
)
29 module SyntaxSC
= SyntaxSC_.WithState
(State
)
31 include SyntaxSC.WithRustParser
(struct
36 let rust_parse = Syntax.rust_parse_with_coroutine_sc
39 let is_coroutine = Syntax.is_coroutine
41 let make_token token state
=
43 if ParserEnv.codegen
!State.env then
44 Token.with_trailing
[] @@ Token.with_leading
[] token
48 (state
, Syntax.make_token token)
50 let make_function_declaration_header
51 modifiers r2 r3 r4 r5 r6 r7 r8 r9 r10 state
=
54 || Syntax.syntax_node_to_list modifiers
|> List.exists ~f
:is_coroutine
57 Syntax.make_function_declaration_header
69 let make_closure_type_specifier r1 r3 r4 r5 r6 r7 r8 r9
state =
70 (state, Syntax.make_closure_type_specifier r1 r3 r4 r5 r6 r7 r8 r9
)
72 let make_anonymous_function r1 r2 r3 r5 r6 r7 r8 r9 r10 r11 r12
state =
73 (state, Syntax.make_anonymous_function r1 r2 r3 r5 r6 r7 r8 r9 r10 r11 r12
)
75 let make_lambda_expression r1 r2 r3 r4 r5
state =
76 (state, Syntax.make_lambda_expression r1 r2 r3 r4 r5
)
78 let make_awaitable_creation_expression r1 r2 r4
state =
79 (state, Syntax.make_awaitable_creation_expression r1 r2 r4
)
81 let make_old_attribute_specification left attribute_name right
state =
83 let is_ppl_attribute_folder has_seen_ppl constructor_call
=
87 match Syntax.syntax constructor_call
with
88 | Syntax.ConstructorCall
90 constructor_call_type
;
91 constructor_call_left_paren
;
92 constructor_call_argument_list
;
93 constructor_call_right_paren
;
95 Syntax.is_missing constructor_call_left_paren
96 && Syntax.is_missing constructor_call_argument_list
97 && Syntax.is_missing constructor_call_right_paren
99 (Syntax.extract_text constructor_call_type
)
101 ~f
:(fun text
-> String.equal text
ppl_macro_string)
108 ~f
:is_ppl_attribute_folder
111 (state, Syntax.make_old_attribute_specification left attribute_name right
))