-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtree-sitter-reason.ebnf
374 lines (273 loc) · 6.61 KB
/
tree-sitter-reason.ebnf
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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
//
// From tree-sitter-reason/src/grammar.json
//
//
// EBNF to generate railroad diagram at
// (IPV6) https://www.bottlecaps.de/rr/ui
// (IPV4) https://rr.red-dove.com/ui
//
program ::=
hash_bang_line? structure_item*
structure_item ::=
str_open
| str_eval
| str_value
| str_type
hash_bang_line ::=
'#!.'*
str_eval ::=
expr
str_value ::=
'let' 'rec'? value_binding ( 'and' value_binding )*
str_open ::=
'open' ident ';'?
value_binding ::=
pattern '=' expr
pattern ::=
pat_any
| pat_var
| pat_alias
| pat_interval
| pat_tuple
| pat_array
| pat_or
| pat_lazy
| pat_open
| pat_exception
| pat_unpack
pat_any ::=
'_'
pat_var ::=
lower_ident
pat_alias ::=
pattern 'as' lower_ident
pat_interval ::=
constant '..' constant
pat_tuple ::=
'(' pattern ( ',' pattern )* ','? ')'
pat_array ::=
'[|' pattern ( ',' pattern )* ','? '|]'
pat_or ::=
pattern '|' pattern
pat_lazy ::=
'lazy' pattern
pat_open ::=
module_ident '.' '(' pattern ')'
pat_exception ::=
'exception' pattern
pat_unpack ::=
'(' 'module' upper_ident ')'
braced_expr ::=
'{' expr '}'
parenthesized_expr ::=
'(' expr ')'
expr ::=
exp_ident
| exp_constant
| exp_let
| exp_function
| exp_unreachable
| exp_lazy
| braced_expr
| exp_apply
| exp_fun
| exp_tuple
| exp_infix
| exp_prefix
| expr_jsx
| exp_ifthenelse
| exp_assert
| exp_while
| exp_for
expr_jsx ::=
jsx_element
| jsx_element_self_closing
| jsx_fragment
| jsx_fragment_self_closing
jsx_fragment ::=
'<' '>' exp_jsx* '<' '/' '>'
jsx_fragment_self_closing ::=
'<' '/' '>'
jsx_element ::=
jsx_start_tag exp_jsx* jsx_closing_tag
exp_jsx ::=
exp_ident
| exp_constant
| exp_let
| exp_unreachable
| exp_lazy
| exp_tuple
| exp_jsx_parens
exp_jsx_parens ::=
'(' ( exp_apply | exp_fun | exp_function | exp_ident | exp_constant | exp_let | exp_unreachable | exp_lazy | exp_tuple ) ')'
jsx_attr ::=
lower_ident ( '=' exp_jsx )?
jsx_start_tag ::=
'<' ( lower_ident | upper_ident ) jsx_attr* '>'
jsx_closing_tag ::=
'<' '/' ( lower_ident | upper_ident ) '>'
jsx_element_self_closing ::=
'<' ( lower_ident | upper_ident ) jsx_attr* '/' '>'
exp_constant ::=
constant
exp_ident ::=
ident
exp_tuple ::=
'(' expr ( ',' expr )+ ','? ')'
exp_let ::=
'let' 'rec'? value_binding ( 'and' value_binding )* expr
exp_function ::=
'fun' case*
exp_fun ::=
es6_args '=>' expr
exp_infix ::=
expr hash_operator expr
| expr shift_operator expr | 'lsl' | 'lsr' | 'asr'
| expr mult_operator expr | 'mod' | 'land' | 'lor' | 'lxor'
| expr add_operator expr
| expr concat_operator expr
| expr equal_operator expr
| expr ( '&' | '&&' ) expr
| expr ( 'or' | '||' ) expr
exp_prefix ::=
prefix_operator expr
| ( '-' | '-.' ) expr
exp_ifthenelse ::=
'if' parenthesized_expr braced_expr ( 'else if' parenthesized_expr braced_expr )* ( 'else' braced_expr )?
exp_while ::=
'while' parenthesized_expr braced_expr
exp_assert ::=
'assert' parenthesized_expr
exp_for ::=
'for' '(' pattern 'in' expr ( 'to' | 'downto' ) expr ')' expr
es6_args ::=
'(' parameter ( ',' parameter )* ','? ')'
parameter ::=
pattern
| param_labeled
| param_labeled_punned
| param_labeled_constraint
| param_optional
| param_optional_punned
param_labeled ::=
'~' lower_ident 'as' lower_ident
param_labeled_punned ::=
'~' lower_ident
param_labeled_constraint ::=
'~' lower_ident ':' core_type
param_optional_punned ::=
'~' lower_ident '=' '?'
param_optional ::=
'~' lower_ident 'as' pattern ( ':' core_type )? '=' ( '?' | expr )
exp_lazy ::=
'lazy' parenthesized_expr
exp_unreachable ::=
'.'
exp_apply ::=
lower_ident '(' argument* ')'
argument ::=
expr
| arg_labeled
| arg_labeled_punned
| arg_optional
| arg_optional_punned
arg_labeled ::=
'~' lower_ident '=' expr
arg_labeled_punned ::=
'~' ident
arg_optional ::=
'~' lower_ident '=' '?' expr
arg_optional_punned ::=
'~' lower_ident '?'
case ::=
'|' pattern guard? '=>' expr
guard ::=
'when' expr
constant ::=
const_integer
| const_char
| const_string
| const_float
const_char ::=
char
const_string ::=
string
const_integer ::=
number
| number [G-Zg-z]
const_float ::=
float
| float [G-Zg-z]
string ::=
'"' ( [^\"#x0A] | '\'('.'|'#x0A') )* '"'
char ::=
"'" [A-Za-z0-9] "'"
number ::=
[+#x2D-]?[0-9]+
float ::=
[+#x2D-]?[0-9]+('.'[0-9]+)('e'[+/-]?[0-9]*)?
ident ::=
upper_ident
| lower_ident
module_ident ::=
upper_ident
| module_ident '.' upper_ident
upper_ident ::=
[A-Z][a-z]+
lower_ident ::=
[a-z]+
str_type ::=
'type' 'rec'? type_declaration ( 'and' type_declaration )* ';'?
type_declaration ::=
lower_ident type_params? type_manifest? type_representation? type_constraint*
type_constraint ::=
'optional' lower_ident '=' core_type
type_representation ::=
'=' ( '|'? constr_decl ( '|' constr_decl )* | record_decl )
constr_decl ::=
upper_ident constr_args
constr_args ::=
'(' core_type ( ',' core_type )* ','? ')'
record_decl ::=
'{' field_decl ( ',' field_decl )* ','? '}'
field_decl ::=
'mutable'? lower_ident ':' core_type
type_manifest ::=
'=' core_type
type_params ::=
'(' type_param* ')'
type_param ::=
( '+' | '-' )? "'" lower_ident
type_open ::=
'..'
core_type ::=
core_type_desc
core_type_desc ::=
typ_any
| typ_var
| typ_tuple
| typ_alias
typ_any ::=
'_'
typ_var ::=
lower_ident
typ_tuple ::=
'(' core_type ( ',' core_type )* ','? ')'
typ_alias ::=
core_type 'as' lower_ident
typ_poly ::=
lower_ident+ '.' core_type
hash_operator ::=
( '#' ( '!' | '$' | '%' | '&' | '*' | '+' | '-' | '.' | '/' | ':' | '<' | '=' | '>' | '?' | '@' | '^' | '|' | '~' )+ )
prefix_operator ::=
( '!' ( '!' | '$' | '%' | '&' | '*' | '+' | '-' | '.' | '/' | ':' | '<' | '=' | '>' | '?' | '@' | '^' | '|' | '~' )* | ( '?' | '~' ) ( '!' | '$' | '%' | '&' | '*' | '+' | '-' | '.' | '/' | ':' | '<' | '=' | '>' | '?' | '@' | '^' | '|' | '~' )+ )
shift_operator ::=
( '**' ( '!' | '$' | '%' | '&' | '*' | '+' | '-' | '.' | '/' | ':' | '<' | '=' | '>' | '?' | '@' | '^' | '|' | '~' )* )
mult_operator ::=
( ( '*' | '/' | '%' ) ( '!' | '$' | '%' | '&' | '*' | '+' | '-' | '.' | '/' | ':' | '<' | '=' | '>' | '?' | '@' | '^' | '|' | '~' )* )
add_operator ::=
( ( '+' | '-' ) ( '!' | '$' | '%' | '&' | '*' | '+' | '-' | '.' | '/' | ':' | '<' | '=' | '>' | '?' | '@' | '^' | '|' | '~' )* )
concat_operator ::=
( ( '@' | '^' ) ( '!' | '$' | '%' | '&' | '*' | '+' | '-' | '.' | '/' | ':' | '<' | '=' | '>' | '?' | '@' | '^' | '|' | '~' )* )
equal_operator ::=
( ( '=' | '<' | '>' | '|' | '&' | '$' ) ( '!' | '$' | '%' | '&' | '*' | '+' | '-' | '.' | '/' | ':' | '<' | '=' | '>' | '?' | '@' | '^' | '|' | '~' )* | '!=' )