-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathparser_env.mli
149 lines (130 loc) · 4.39 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
(*
* Copyright (c) 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the "flow" directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*)
(* 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 t = Set.Make(String).t
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: Lexer_flow.Token.t;
token_context: Lex_mode.t;
token_value: string;
}
type parse_options = {
esproposal_class_instance_fields: bool;
esproposal_class_static_fields: bool;
esproposal_decorators: bool;
esproposal_export_star_as: bool;
types: bool;
use_strict: bool;
}
val default_parse_options : parse_options
type env
(* constructor: *)
val init_env :
?token_sink:(token_sink_result -> unit) option
-> ?parse_options:parse_options option
-> Loc.filename option
-> string
-> env
(* getters: *)
val in_strict_mode : env -> bool
val last_loc : env -> Loc.t option
val in_export : env -> bool
val labels : env -> SSet.t
val comments : env -> Spider_monkey_ast.Comment.t list
val in_loop : env -> bool
val in_switch : env -> bool
val in_function : env -> bool
val allow_yield : env -> bool
val allow_await: 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 -> Loc.filename option
val should_parse_types : env -> bool
(* mutators: *)
val error_at : env -> Loc.t * Parse_error.t -> unit
val error : env -> Parse_error.t -> unit
val error_unexpected : env -> unit
val error_on_decorators : env -> (Loc.t * 'a) list -> unit
val strict_error : env -> Parse_error.t -> unit
val strict_error_at : env -> Loc.t * Parse_error.t -> unit
val get_unexpected_error : Lexer_flow.Token.t * string -> Parse_error.t
val comment_list : env -> Spider_monkey_ast.Comment.t list -> unit
val error_list : env -> (Loc.t * Parse_error.t) list -> unit
val record_export: env -> Loc.t * string -> 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_function : bool -> env -> env
val with_allow_yield : bool -> env -> env
val with_allow_await : bool -> 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_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 -> env
val is_future_reserved : string -> bool
val is_strict_reserved : string -> bool
val is_restricted : string -> bool
module Peek : sig
val token : ?i:int -> env -> Lexer_flow.Token.t
val value : ?i:int -> env -> string
val loc : ?i:int -> env -> Loc.t
val errors : ?i:int -> env -> (Loc.t * Parse_error.t) list
val comments : ?i:int -> env -> Spider_monkey_ast.Comment.t list
val is_line_terminator : env -> bool
val is_implicit_semicolon : env -> bool
val semicolon_loc : ?i:int -> env -> Loc.t option
val is_identifier : ?i:int -> env -> bool
val is_literal_property_name : ?i:int -> env -> bool
val is_function : ?i:int -> env -> bool
val is_class : ?i:int -> env -> bool
end
module Eat : sig
val token : env -> unit
val push_lex_mode : env -> Lex_mode.t -> unit
val pop_lex_mode : env -> unit
val double_pop_lex_mode : env -> unit
val semicolon : env -> unit
end
module Expect : sig
val token : env -> Lexer_flow.Token.t -> unit
val maybe : env -> Lexer_flow.Token.t -> bool
val contextual : 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
end