-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtree-sitter-lean.ebnf
660 lines (482 loc) · 12.4 KB
/
tree-sitter-lean.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
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
//
// From tree-sitter-lean/src/grammar.json
//
//
// EBNF to generate railroad diagram at
// (IPV6) https://www.bottlecaps.de/rr/ui
// (IPV4) https://rr.red-dove.com/ui
//
module ::=
prelude? import* _command*
prelude ::=
'prelude'
import ::=
'import' identifier
parameters ::=
( identifier | hole | _bracketed_binder | anonymous_constructor )+
_expression ::=
apply
| comparison
| let
| tactics
| binary_expression
| neg
| quoted_tactic
| fun
| _term
| do
| unless
let ::=
'let' identifier parameters? ( ':' _expression )? ':=' _expression ( _newline | ';' ) _expression?
_do_seq ::=
_do_element ( _newline _do_element )* _newline?
do ::=
'do' _do_seq
conditional_when ::=
'if' _expression 'then' _do_element
for_in ::=
'for' ( identifier | anonymous_constructor ) 'in' _expression do
assign ::=
identifier ':=' _expression
let_mut ::=
'let' 'mut' parameters ( _left_arrow | ':=' ) _expression
let_bind ::=
'let' identifier _left_arrow _expression
unless ::=
'unless' _expression do
try ::=
'try' _do_element ( _newline _do_element )* _newline? ( catch finally? | finally )
catch ::=
'catch' _expression '=>' _do_element ( _newline _do_element )* _newline?
finally ::=
'finally' _do_element ( _newline _do_element )* _newline?
fun ::=
( 'fun' | 'λ' ) ( parameters '=>' _expression | ( '|' ( _expression ( ',' _expression )* ) '=>' _expression )* )
apply ::=
_apply
| _dollar
_apply ::=
( identifier | number | float | string | char | hole | synthetic_hole | sorry | cdot | parenthesized | anonymous_constructor | structure_instance | explicit | forall | true | false | borrowed | quoted_name | double_quoted_name | have | proj | arrow | _do_term | _command_term | _notation_term | _notation_extra_term | array | subarray | range | interpolated_string ) _argument+
_dollar ::=
_expression '$' _expression
neg ::=
'-' _expression
binary_expression ::=
_expression '^' _expression
| _expression '*' _expression
| _expression '/' _expression
| _expression '%' _expression
| _expression '+' _expression
| _expression '-' _expression
| _expression '∘' _expression
| _expression '∧' _expression
| _expression '∨' _expression
| _expression '/\' _expression
| _expression '\/' _expression
| _expression '↔' _expression
| _expression '||' _expression
| _expression '&&' _expression
| _expression '==' _expression
| _expression '++' _expression
| _expression '::' _expression
| _expression '|>' _expression
| _expression '|>.' _expression
| _expression '<|' _expression
| _expression '<|>' _expression
| _expression '>>' _expression
| _expression '>>=' _expression
| _expression '<*>' _expression
| _expression '<*' _expression
| _expression '*>' _expression
| _expression '<$>' _expression
| _expression '=' _expression
| _expression '≠' _expression
comparison ::=
_expression ( '<' | '>' | '≤' | '≥' | '<=' | '>=' ) _expression
comment ::=
( '--' '.'* | '/-' ( [^-] | '-'[^/] )* '-/' )
_identifier ::=
[_a-zA-ZͰ-ϿĀ-ſ\U0001D400-\U0001D7FF][_`'`a-zA-Z0-9Ͱ-ϿĀ-ſ∇!?\u2070-\u209F\U0001D400-\U0001D7FF]*
_escaped_identifier ::=
'«'[^»]*'»'
_attribute ::=
_simple_attribute
| _extern_attribute
_simple_attribute ::=
( identifier identifier? )
_extern_entry ::=
identifier? 'inline'? string
_extern_attribute ::=
'extern' number? _extern_entry*
_visibility ::=
'private'
| 'protected'
_decl_modifiers ::=
( attributes ( 'noncomputable' | 'partial' | _visibility | 'unsafe' )+? | attributes? ( 'noncomputable' | 'partial' | _visibility | 'unsafe' )+ )
_decl_id ::=
identifier
_decl_sig ::=
_simple_binder_without_type | _bracketed_binder* _type_spec
_opt_decl_sig ::=
_simple_binder_without_type | _bracketed_binder+ _type_spec? | _simple_binder_without_type | _bracketed_binder+? _type_spec
_decl_val_simple ::=
':=' _expression
_decl_val_equations ::=
_match_alts_where_decls
_decl_val ::=
( _decl_val_simple | _decl_val_equations | _where_decls )
abbrev ::=
'abbrev' _decl_id _opt_decl_sig? _decl_val
def ::=
'def' _decl_id _opt_decl_sig? _decl_val
theorem ::=
'theorem' _decl_id _decl_sig _decl_val
constant ::=
'constant' _decl_id _decl_sig _decl_val_simple?
instance ::=
'instance' _decl_id? _decl_sig _decl_val
axiom ::=
'axiom' _decl_id _decl_sig
example ::=
'example' _decl_sig _decl_val
constructor ::=
'|' identifier _opt_decl_sig?
_deriving ::=
( 'deriving' identifier ( ',' identifier )* )
inductive ::=
'inductive' _decl_id _opt_decl_sig? ( ':=' | 'where' )? constructor+? _deriving?
class_inductive ::=
'class' 'inductive' _decl_id _opt_decl_sig? ( ':=' | 'where' )? constructor+? _deriving?
_struct_explicit_binder ::=
'(' identifier+ _opt_decl_sig? _binder_default? ')'
_struct_implicit_binder ::=
'{' identifier+ _decl_sig '}'
_struct_instance_binder ::=
'[' identifier+ _decl_sig ']'
_struct_simple_binder ::=
identifier _opt_decl_sig? _binder_default?
_struct_field ::=
( _struct_explicit_binder | _struct_implicit_binder | _struct_instance_binder | _struct_simple_binder )
_struct_constructor ::=
identifier '::'
_extends ::=
( 'extends' _expression ( ',' _expression )* )
structure ::=
( 'structure' | 'class' ) _decl_id _bracketed_binder* _extends? _type_spec? ( ( ':=' | 'where' ) _struct_constructor? _struct_field* )? _deriving?
declaration ::=
_decl_modifiers? ( abbrev | def | theorem | constant | instance | axiom | example | inductive | class_inductive | structure )
section ::=
'section' identifier? _command* 'end' identifier?
namespace ::=
'namespace' identifier _command* 'end' identifier
variable ::=
'variable' _bracketed_binder+
universe ::=
'universe' identifier+
hash_command ::=
( '#check' | '#check_failure' | '#eval' | '#print' | '#reduce' ) _expression
attribute ::=
'attribute' '[' ( _attribute | '-' _attribute ) ( ',' ( _attribute | '-' _attribute ) )* ']' identifier
export ::=
'export' identifier '(' identifier+ ')'
open ::=
'open' identifier+ ( 'in' _command )?
quoted ::=
'`(' ( _term | _command+ ) ')'
_command_term ::=
quoted
builtin_initialize ::=
_visibility? 'builtin_initialize' ( identifier _type_spec _left_arrow )? _do_seq
_command ::=
declaration
| section
| namespace
| variable
| universe
| hash_command
| attribute
| export
| open
| builtin_initialize
| mixfix
| notation
| macro_rules
| syntax
| macro
| elab
_precedence ::=
':' ( number | 'max' | 'arg' | 'lead' | 'min' | 'min1' )
_syntax_cat ::=
identifier
_syntax_atom ::=
string
_syntax ::=
_syntax_cat
| _syntax_atom
mixfix ::=
_attr_kind? ( 'prefix' | 'infix' | 'infixl' | 'infixr' | 'postfix' ) _precedence string '=>' _term
notation ::=
_attr_kind? 'notation' _expression '=>' _expression
macro_rules ::=
_attr_kind? 'macro_rules' _match_alts
syntax ::=
_attr_kind? 'syntax' _syntax+ ':' identifier
_macro_arg ::=
( identifier ':' )? _syntax
_macro_tail_tactic ::=
' : ' 'tactic' '=>' '`(' _tactic+ ')'
_macro_tail_command ::=
' : ' 'command' '=>' '`(' _command+ ')'
_macro_tail_default ::=
' : ' identifier '=>' '`(' ( _tactic | _command )+ ')'
_macro_tail ::=
_macro_tail_tactic
| _macro_tail_command
macro ::=
_attr_kind? 'macro' _precedence? _macro_arg+ _macro_tail
_elab_arg ::=
_macro_arg
_elab_tail ::=
':' identifier ( '<=' identifier )? '=>' _expression
elab ::=
_attr_kind? 'elab' _precedence? _elab_arg+ _elab_tail
tactics ::=
'by' _tactic ( ';'? _newline _tactic )* ( ';'? _newline )?
apply_tactic ::=
'apply' _expression
rewrite ::=
( 'rewrite' | 'rw' ) _expression
term ::=
'exact' _expression
simp ::=
'simp' list?
trivial ::=
'trivial'
intro ::=
'intro' _expression*
rfl ::=
'rfl'
_user_tactic ::=
_expression
_tactic ::=
apply_tactic
| rewrite
| simp
| term
| trivial
| intro
| rfl
| _user_tactic
quoted_char ::=
( '\\' ( 'u'[a-fA-F0-9]'{4}' | 'x'[a-fA-F0-9]'{2}' | [\"'rnt] ) )
_left_arrow ::=
'<-'
| '←'
do_return ::=
'return' _expression?
_do_expression ::=
_expression
_do_element ::=
_do_expression
| assign
| for_in
| let_bind
| let_mut
| do_return
identifier ::=
_identifier ( '.' _identifier )*
| _identifier
| _escaped_identifier
number ::=
[0-9]+
float ::=
[0-9]+'.'[0-9]*
string ::=
'"' ( quoted_char | [^"#x0A\]+ )* '"'
char ::=
"'" ( quoted_char | [^'] ) "'"
hole ::=
'_'
synthetic_hole ::=
'?' ( identifier | hole )
sorry ::=
'sorry'
cdot ::=
'.'
| '·'
type_ascription ::=
':' _expression
tuple_tail ::=
',' _expression ( ',' _expression )*
parenthesized ::=
'(' ( _expression ( tuple_tail | type_ascription )? )? ')'
anonymous_constructor ::=
'⟨' ( _expression ( ',' _expression )* )? '⟩'
_structure_instance_field ::=
identifier ':=' _expression
structure_instance ::=
'{' ( _expression 'with' )? ( _structure_instance_field ( ',' _structure_instance_field )* ','? )? _type_spec? '}'
_type_spec ::=
( ':' _expression )
explicit ::=
'@' _term
_binder_ident ::=
identifier
| hole
_binder_default ::=
( ':=' _expression )
explicit_binder ::=
'(' _binder_ident+ _type_spec? ( _binder_default )? ')'
implicit_binder ::=
'{' _binder_ident+ _type_spec? '}'
instance_binder ::=
'[' ( identifier ':' )? _expression ']'
_bracketed_binder ::=
explicit_binder
| implicit_binder
| instance_binder
proj ::=
_term '.' ( identifier | number )
arrow ::=
_term ( '->' | '→' ) _expression
forall ::=
'∀' ( _simple_binder | _bracketed_binder )+ ',' _expression
_simple_binder ::=
_binder_ident+ _type_spec?
match_alt ::=
'|' ( _expression ( ',' _expression )* ) '=>' _expression
_match_alts ::=
match_alt+
_match_discr ::=
( identifier ':' )? _expression
true ::=
'true'
false ::=
'false'
match ::=
'match' ( _match_discr ( ', ' _match_discr )* ) _type_spec? 'with' _match_alts
borrowed ::=
'@&' _term
quoted_name ::=
'`' identifier
double_quoted_name ::=
'``' identifier
_simple_binder_without_type ::=
_binder_ident+
_let_id_lhs ::=
identifier ( _simple_binder_without_type | _bracketed_binder )* _type_spec?
_let_id_decl ::=
_let_id_lhs ':=' _expression
_let_pattern_decl ::=
_term _type_spec? ':=' _expression
_let_equations_decl ::=
_let_id_lhs _match_alts
_let_decl ::=
_let_id_decl
| _let_pattern_decl
| _let_equations_decl
_have_id_lhs ::=
identifier ( _simple_binder_without_type | _bracketed_binder )* _type_spec?
| ( identifier ( _simple_binder_without_type | _bracketed_binder )* )? _type_spec
_have_id_decl ::=
_have_id_lhs? ':=' _term
_have_eqns_decl ::=
_have_id_lhs? _match_alts
_have_decl ::=
_have_id_decl
| _let_pattern_decl
| _have_eqns_decl
have ::=
'have' _have_decl ';'? _term
_attr_kind ::=
'scoped'
| 'local'
_attr_instance ::=
_attr_kind? _attribute
attributes ::=
'@[' _attr_instance ( ',' _attr_instance )* ']'
_let_rec_decl ::=
_let_decl
_where_decls ::=
'where' ( _let_rec_decl )+
_match_alts_where_decls ::=
_match_alts _where_decls?
named_argument ::=
'(' identifier ':=' _expression ')'
ellipsis ::=
'..'
_argument ::=
named_argument
| ellipsis
| _expression
quoted_tactic ::=
'`(tactic|' _tactic ')'
_term ::=
identifier
| number
| float
| string
| char
| hole
| synthetic_hole
| sorry
| cdot
| parenthesized
| anonymous_constructor
| structure_instance
| explicit
| forall
| true
| false
| match
| borrowed
| quoted_name
| double_quoted_name
| have
| proj
| arrow
| _do_term
| _command_term
| _notation_term
| _notation_extra_term
| array
| subarray
| range
| interpolated_string
lift_method ::=
_left_arrow _term
_do_term ::=
lift_method
product ::=
_term '×' _term
unary_expression ::=
( '¬' | '!' ) _term
subtype ::=
'{' identifier ( ':' _term )? '//' _expression '}'
list ::=
'[' ( _expression ( ',' _expression )* )? ']'
assumption_literal ::=
'‹' _term '›'
if_then_else ::=
'if' _expression 'then' _expression 'else' _expression
_notation_term ::=
product
| unary_expression
| subtype
| if_then_else
| list
| assumption_literal
exists ::=
'∃' ( _simple_binder | _bracketed_binder )+ ',' _expression
_notation_extra_term ::=
exists
array ::=
'#[' ( _expression ( ',' _expression )* )? ']'
subarray ::=
_expression '[' ( _expression | _expression? ':' _expression | _expression ':' _expression? ) ']'
range ::=
'[' _expression? ':' _expression ( ':' _expression )? ']'
interpolated_string ::=
's!"' ( [^"] | quoted_char | interpolation )* '"'
interpolation ::=
'{' _expression '}'