-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtree-sitter-sml.ebnf
571 lines (415 loc) · 8.02 KB
/
tree-sitter-sml.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
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
//
// From tree-sitter-sml/src/grammar.json
//
//
// EBNF to generate railroad diagram at
// (IPV6) https://www.bottlecaps.de/rr/ui
// (IPV4) https://rr.red-dove.com/ui
//
source_file ::=
( _exp | _sdec* ) ( ';' ( _exp | _sdec* ) )*
_sdec ::=
structure_dec
| signature_dec
| funsig_dec
| functor_dec
| local_dec
| _ldec
structure_dec ::=
'structure' strb ( 'and' strb )*
strb ::=
ident _sigconstraint_op? '=' _str
_sigconstraint_op ::=
transparent_sigconstraint_op
| opaque_sigconstraint_op
transparent_sigconstraint_op ::=
':' _sign
opaque_sigconstraint_op ::=
':>' _sign
_str ::=
var_struct
| base_struct
| app_struct
| let_struct
| constraint_struct
var_struct ::=
qident
base_struct ::=
'struct' ( ';' | _strdec )* 'end'
_strdec ::=
structure_dec_strdec
| functor_dec_strdec
| local_dec_strdec
| _ldec
structure_dec_strdec ::=
'structure' strb ( 'and' strb )*
functor_dec_strdec ::=
'functor' fctb ( 'and' fctb )*
local_dec_strdec ::=
'local' ( ';' | _strdec )* 'in' ( ';' | _strdec )* 'end'
app_struct ::=
qident arg_fct+
let_struct ::=
'let' ( ';' | _strdec )* 'in' _str 'end'
constraint_struct ::=
_str ( ':' | ':>' ) _sign
signature_dec ::=
'signature' sigb ( 'and' sigb )*
sigb ::=
ident '=' _sign
_sign ::=
var_sign
| base_sign
| aug_sign
var_sign ::=
ident
base_sign ::=
'sig' ( ';' | _spec )* 'end'
aug_sign ::=
_sign 'where' _whspec ( 'and' _whspec )*
_spec ::=
str_spec
| functor_spec
| datatype_repl_spec
| datatype_spec
| type_spec
| eqtype_spec
| val_spec
| exception_spec
| sharing_spec
| include_spec
str_spec ::=
'structure' strspec ( 'and' strspec )*
strspec ::=
ident ':' _sign ( '=' qident )?
functor_spec ::=
'functor' fctspec ( 'and' fctspec )*
fctspec ::=
ident _fsig
datatype_repl_spec ::=
'datatype' dtrepl
dtrepl ::=
_full_ident '=' 'datatype' con_ty
datatype_spec ::=
'datatype' db ( 'and' db )* ( 'withtype' tb ( 'and' tb )* )?
type_spec ::=
'type' tyspec ( 'and' tyspec )*
tyspec ::=
tyvar_seq? _full_ident ( '=' _ty )?
eqtype_spec ::=
'eqtype' tyspec ( 'and' tyspec )*
val_spec ::=
'val' valspec ( 'and' valspec )*
valspec ::=
'op'? _full_ident ':' _ty
exception_spec ::=
'exception' exnspec ( 'and' exnspec )*
exnspec ::=
_full_ident ( 'of' _ty )?
sharing_spec ::=
'sharing' sharespec ( 'and' sharespec )*
sharespec ::=
'type'? qident ( '=' qident )+
include_spec ::=
'include' ( _sign | ident ident+ )
_whspec ::=
type_whspec
| struct_whsepc
type_whspec ::=
'type' tyvar_seq? qident '=' _ty
struct_whsepc ::=
qident '=' qident
funsig_dec ::=
'funsig' fsigb ( 'and' fsigb )*
fsigb ::=
ident fparam+ '=' _sign
_fsig ::=
var_fsig
| base_fsig
var_fsig ::=
':' ident
base_fsig ::=
fparam+ ':' _sign
functor_dec ::=
'functor' fctb ( 'and' fctb )*
fctb ::=
ident fparam+ _sigconstraint_op? '=' _str
| ident _fsigconstraint_op? '=' _fct_exp
fparam ::=
'(' ident ':' _sign ')'
| '(' ( ';' | _spec )* ')'
_fsigconstraint_op ::=
transparent_fsigconstraint_op
| opaque_fsigconstraint_op
transparent_fsigconstraint_op ::=
':' ident
opaque_fsigconstraint_op ::=
':>' ident
_fct_exp ::=
var_fct_exp
| app_fct_exp
| let_fct_exp
var_fct_exp ::=
qident
app_fct_exp ::=
qident arg_fct+
arg_fct ::=
'(' ( ';' | _strdec )* ')'
| '(' _str ')'
let_fct_exp ::=
'let' ( ';' | _strdec )* 'in' _fct_exp 'end'
local_dec ::=
'local' ( ';' | _sdec )* 'in' ( ';' | _sdec )* 'end'
_ldec ::=
val_ldec
| fun_ldec
| type_ldec
| datatype_repl_ldec
| datatype_ldec
| abstype_ldec
| exception_ldec
| open_ldec
| fixity_ldec
| overload_ldec
val_ldec ::=
'val' tyvar_seq? 'rec'? vb ( 'and' vb )*
vb ::=
_pat '=' _exp
fun_ldec ::=
'fun' tyvar_seq? fb ( 'and' fb )*
fb ::=
clause ( '|' clause )*
clause ::=
_apat+ constraint? '=' _exp
constraint ::=
':' _ty
type_ldec ::=
'type' tb ( 'and' tb )*
tb ::=
tyvar_seq? _full_ident '=' _ty
datatype_repl_ldec ::=
'datatype' dtrepl
datatype_ldec ::=
'datatype' db ( 'and' db )* ( 'withtype' tb ( 'and' tb )* )?
db ::=
tyvar_seq? _full_ident '=' constr ( '|' constr )*
constr ::=
'op'? _full_ident ( 'of' _ty )?
abstype_ldec ::=
'abstype' db ( 'and' db )* ( 'withtype' tb ( 'and' tb )* )? 'with' ( ';' | _ldec | local_dec_let )* 'end'
exception_ldec ::=
'exception' eb ( 'and' eb )*
eb ::=
'op'? _full_ident ( exn_gen | exn_def )?
exn_gen ::=
'of' _ty
exn_def ::=
'=' qident
open_ldec ::=
'open' qident+
fixity_ldec ::=
( ( 'infix' | 'infixr' ) int_constant? | 'nonfix' ) _full_ident+
overload_ldec ::=
'overload' _full_ident ':' _ty 'as' _exp ( 'and' _exp )*
_pat ::=
as_pat
| constraint_pat
| app_pat
as_pat ::=
_pat 'as' _pat
constraint_pat ::=
_pat ':' _ty
app_pat ::=
_apat+
_apat ::=
_apat_
| paren_pat
| var_pat
| tuple_unit_pat
| tuple_pat
| or_pat
paren_pat ::=
'(' _pat ')'
var_pat ::=
_full_ident
tuple_unit_pat ::=
'(' ')'
tuple_pat ::=
'(' _pat ( ',' _pat )+ ')'
or_pat ::=
'(' _pat ( '|' _pat )+ ')'
_apat_ ::=
op_pat
| access_pat
| constant_pat
| wild_pat
| list_pat
| vector_pat
| rec_unit_pat
| rec_pat
op_pat ::=
'op' _full_ident
access_pat ::=
'op'? ident '.' qident
constant_pat ::=
_constant
wild_pat ::=
'_'
list_pat ::=
'[' ']'
| '[' _pat ( ',' _pat )* ']'
vector_pat ::=
'#[' ']'
| '#[' _pat ( ',' _pat )* ']'
rec_unit_pat ::=
'{' '}'
rec_pat ::=
'{' plabels '}'
plabels ::=
plabel ( ',' plabel )* ( ',' '...' )?
| '...'
plabel ::=
selector '=' _pat
| _full_ident ( ':' _ty )? ( 'as' _pat )?
match ::=
rule ( '|' rule )*
rule ::=
_pat '=>' _exp
_exp ::=
handle_exp
| orelse_exp
| andalso_exp
| constraint_exp
| app_exp
| fn_exp
| case_exp
| while_exp
| if_exp
| raise_exp
handle_exp ::=
_exp 'handle' match
orelse_exp ::=
_exp 'orelse' _exp
andalso_exp ::=
_exp 'andalso' _exp
constraint_exp ::=
_exp ':' _ty
app_exp ::=
( _aexp | var_exp )+
fn_exp ::=
'fn' match
case_exp ::=
'case' _exp 'of' match
while_exp ::=
'while' _exp 'do' _exp
if_exp ::=
'if' _exp 'then' _exp 'else' _exp
raise_exp ::=
'raise' _exp
var_exp ::=
_full_ident
_aexp ::=
op_exp
| access_exp
| constant_exp
| selector_exp
| rec_exp
| rec_unit_exp
| tuple_unit_exp
| seq_exp
| tuple_exp
| list_exp
| vector_exp
| let_exp
op_exp ::=
'op' _full_ident
access_exp ::=
'op'? ident '.' qident
constant_exp ::=
_constant
selector_exp ::=
'#' selector
rec_exp ::=
'{' elabel ( ',' elabel )* '}'
elabel ::=
selector '=' _exp
rec_unit_exp ::=
'{' '}'
tuple_unit_exp ::=
'(' ')'
seq_exp ::=
'(' _exp ( ';' _exp )* ')'
tuple_exp ::=
'(' _exp ( ',' _exp )+ ')'
list_exp ::=
'[' ']'
| '[' _exp ( ',' _exp )* ']'
vector_exp ::=
'#[' ']'
| '#[' _exp ( ',' _exp )* ']'
let_exp ::=
'let' ( _ldec | ';' | local_dec_let )* 'in' _exp ( ';' _exp )* 'end'
local_dec_let ::=
'local' ( _ldec | ';' | local_dec_let )* 'in' ( _ldec | ';' | local_dec_let )* 'end'
_constant ::=
int_constant
| word_constant
| float_constant
| char_constant
| string_constant
int_constant ::=
'~'?[0-9]+|'~'?'0x'[0-9A-Fa-f]+
word_constant ::=
'0w'[0-9]+|'0wx'[0-9A-Fa-f]+
float_constant ::=
'~'?[0-9]+'.'[0-9]+([Ee]'~'?[0-9]+)?
char_constant ::=
character
string_constant ::=
string
_ty ::=
tuple_ty
| arrow_ty
| _ty_
tuple_ty ::=
_ty_ ( '*' _ty_ )+
arrow_ty ::=
_ty '->' _ty
_ty_ ::=
var_ty
| rec_ty
| mark_ty
| paren_ty
var_ty ::=
tyvar
rec_ty ::=
'{' '}'
| '{' tlabel ( ',' tlabel )* '}'
tlabel ::=
selector ':' _ty
mark_ty ::=
( _ty_ | '(' _ty ( ',' _ty )+ ')' )? con_ty
con_ty ::=
qident
paren_ty ::=
'(' _ty ')'
tyvar_seq ::=
tyvar
| '(' tyvar ( ',' tyvar )+ ')'
selector ::=
_full_ident
| [0-9]+
tyvar ::=
"'"[A-Za-z0-9_']+
ident ::=
[A-Za-z][A-Za-z0-9_']*
symbolic ::=
[!%&$#x23+#x2D-/:<=>?@\~`^|*][!%&$#x23+#x2D-/:<=>?@\~`^|*][!%&$#x23+#x2D-/:<=>?@\~`^|*]+
| [!%&$#x23+/<>?@\~`^|*][!%&$#x23+#x2D-/:<=>?@\~`^|*]
| [#x2D-:=][!%&$#x23+#x2D-/:<=?@\~`^|*]
| [!%&$+#x2D-/<=>?@\~`^*]
_full_ident ::=
ident
| symbolic
qident ::=
( ident '.' )* _full_ident