-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathparser_env.mli
283 lines (165 loc) · 6.09 KB
/
parser_env.mli
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
(*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*)
(* This module provides a layer between the lexer and the parser which includes
* some parser state and some lexer state *)
module SSet : Set.S with type elt = string
module Lex_mode : sig
type t =
| NORMAL
| TYPE
| JSX_TAG
| JSX_CHILD
| TEMPLATE
| REGEXP
val debug_string_of_lex_mode : t -> string
end
type token_sink_result = {
token_loc: Loc.t;
token: Token.t;
token_context: Lex_mode.t;
}
type parse_options = {
enums: bool; (** enable parsing of Flow enums *)
esproposal_decorators: bool; (** enable parsing of decorators *)
types: bool; (** enable parsing of Flow types *)
use_strict: bool; (** treat the file as strict, without needing a "use strict" directive *)
}
val default_parse_options : parse_options
type env
type allowed_super =
| No_super
| Super_prop
| Super_prop_or_call
(* constructor: *)
val init_env :
?token_sink:(token_sink_result -> unit) option ->
?parse_options:parse_options option ->
File_key.t option ->
string ->
env
(* getters: *)
val in_strict_mode : env -> bool
val last_loc : env -> Loc.t option
val last_token : env -> Token.t option
val in_export : env -> bool
val in_export_default : env -> bool
val labels : env -> SSet.t
val comments : env -> Loc.t Flow_ast.Comment.t list
val in_loop : env -> bool
val in_switch : env -> bool
val in_formal_parameters : env -> bool
val in_function : env -> bool
val allow_yield : env -> bool
val allow_await : env -> bool
val allow_directive : env -> bool
val allow_super : env -> allowed_super
val has_simple_parameters : env -> bool
val no_in : env -> bool
val no_call : env -> bool
val no_let : env -> bool
val no_anon_function_type : env -> bool
val no_new : env -> bool
val errors : env -> (Loc.t * Parse_error.t) list
val parse_options : env -> parse_options
val source : env -> File_key.t option
val should_parse_types : env -> bool
val get_unexpected_error : ?expected:string -> Token.t -> Parse_error.t
(* mutators: *)
val error_at : env -> Loc.t * Parse_error.t -> unit
val error : env -> Parse_error.t -> unit
val error_unexpected : ?expected:string -> env -> unit
val error_on_decorators : env -> (Loc.t * 'a) list -> unit
val error_nameless_declaration : env -> string -> unit
val strict_error : env -> Parse_error.t -> unit
val strict_error_at : env -> Loc.t * Parse_error.t -> unit
val function_as_statement_error_at : env -> Loc.t -> unit
val error_list : env -> (Loc.t * Parse_error.t) list -> unit
val enter_class : env -> unit
val exit_class : env -> unit
val add_declared_private : env -> string -> unit
val add_used_private : env -> string -> Loc.t -> unit
val consume_comments_until : env -> Loc.position -> unit
(* functional operations -- these return shallow copies, so future mutations to
* the returned env will also affect the original: *)
val with_strict : bool -> env -> env
val with_in_formal_parameters : bool -> env -> env
val with_in_function : bool -> env -> env
val with_allow_yield : bool -> env -> env
val with_allow_await : bool -> env -> env
val with_allow_directive : bool -> env -> env
val with_allow_super : allowed_super -> env -> env
val with_no_let : bool -> env -> env
val with_in_loop : bool -> env -> env
val with_no_in : bool -> env -> env
val with_no_anon_function_type : bool -> env -> env
val with_no_new : bool -> env -> env
val with_in_switch : bool -> env -> env
val with_in_export : bool -> env -> env
val with_in_export_default : bool -> env -> env
val with_no_call : bool -> env -> env
val with_error_callback : (env -> Parse_error.t -> unit) -> env -> env
val without_error_callback : env -> env
val add_label : env -> string -> env
val enter_function : env -> async:bool -> generator:bool -> simple_params:bool -> env
val is_reserved : string -> bool
val token_is_reserved : Token.t -> bool
val is_future_reserved : string -> bool
val is_strict_reserved : string -> bool
val token_is_strict_reserved : Token.t -> bool
val is_restricted : string -> bool
val is_reserved_type : string -> bool
val token_is_restricted : Token.t -> bool
module Peek : sig
val token : env -> Token.t
val loc : env -> Loc.t
val loc_skip_lookahead : env -> Loc.t
val errors : env -> (Loc.t * Parse_error.t) list
val comments : env -> Loc.t Flow_ast.Comment.t list
val has_eaten_comments : env -> bool
val is_line_terminator : env -> bool
val is_implicit_semicolon : env -> bool
val is_identifier : env -> bool
val is_type_identifier : env -> bool
val is_identifier_name : env -> bool
val is_function : env -> bool
val is_class : env -> bool
val ith_token : i:int -> env -> Token.t
val ith_loc : i:int -> env -> Loc.t
val ith_errors : i:int -> env -> (Loc.t * Parse_error.t) list
val ith_comments : i:int -> env -> Loc.t Flow_ast.Comment.t list
val ith_is_line_terminator : i:int -> env -> bool
val ith_is_implicit_semicolon : i:int -> env -> bool
val ith_is_identifier : i:int -> env -> bool
val ith_is_identifier_name : i:int -> env -> bool
val ith_is_type_identifier : i:int -> env -> bool
end
module Eat : sig
val token : env -> unit
val maybe : env -> Token.t -> bool
val push_lex_mode : env -> Lex_mode.t -> unit
val pop_lex_mode : env -> unit
val double_pop_lex_mode : env -> unit
val trailing_comments : env -> Loc.t Flow_ast.Comment.t list
val comments_until_next_line : env -> Loc.t Flow_ast.Comment.t list
val program_comments : env -> Loc.t Flow_ast.Comment.t list
end
module Expect : sig
val get_error : env -> Token.t -> Loc.t * Parse_error.t
val error : env -> Token.t -> unit
val token : env -> Token.t -> unit
val token_opt : env -> Token.t -> unit
val token_maybe : env -> Token.t -> bool
val identifier : env -> string -> unit
end
module Try : sig
type 'a parse_result =
| ParsedSuccessfully of 'a
| FailedToParse
exception Rollback
val to_parse : env -> (env -> 'a) -> 'a parse_result
val or_else : env -> fallback:'a -> (env -> 'a) -> 'a
end