-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtree-sitter-agda.ebnf
489 lines (368 loc) · 9.74 KB
/
tree-sitter-agda.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
//
// From tree-sitter-agda/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 ::=
( _declaration _newline )*
_FORALL ::=
'forall'
| '∀'
_ARROW ::=
'->'
| '→'
_LAMBDA ::=
'\\'
| 'λ'
_ELLIPSIS ::=
'...'
| '…'
_declaration_block ::=
_indent ( _declaration _newline )+ _dedent
_declaration ::=
fields
| function
| data
| data_signature
| record
| record_signature
| infix
| generalize
| mutual
| abstract
| private
| instance
| macro
| postulate
| primitive
| open
| import
| module_macro
| module
| pragma
| syntax
| pattern
| unquote_decl
fields ::=
'field' _signature_block
_signature_block ::=
_indent ( signature _newline )+ _dedent
signature ::=
'overlap'? _modal_arg_ids ':' expr
| 'instance' _signature_block
_modal_arg_ids ::=
attribute* _arg_ids
function ::=
attributes? lhs_decl rhs_decl? where?
| attributes? lhs_defn rhs_defn? where?
lhs_decl ::=
_with_exprs rewrite_equations? with_expressions?
lhs_defn ::=
_with_exprs rewrite_equations? with_expressions?
rhs_decl ::=
':' expr
rhs_defn ::=
'=' expr
with_expressions ::=
'with' expr
rewrite_equations ::=
'rewrite' _with_exprs
where ::=
( 'module' bid )? 'where' _declaration_block?
data_name ::=
id
data ::=
( 'data' | 'codata' ) data_name _typed_untyped_bindings? ( ':' expr )? 'where' _declaration_block?
data_signature ::=
'data' data_name _typed_untyped_bindings? ':' expr
record ::=
'record' _atom_no_curly _typed_untyped_bindings? ( ':' expr )? record_declarations_block
record_declarations_block ::=
'where' _indent ( _record_directive _newline )* ( _declaration _newline )* _dedent
_record_directive ::=
record_constructor
| record_constructor_instance
| record_induction
| record_eta
record_constructor ::=
'constructor' id
record_constructor_instance ::=
'instance' _indent ( record_constructor _newline )+ _dedent
record_induction ::=
'inductive'
| 'coinductive'
record_eta ::=
'eta-equality'
| 'no-eta-equality'
record_signature ::=
'record' _atom_no_curly _typed_untyped_bindings? ':' expr
infix ::=
( 'infix' | 'infixl' | 'infixr' ) integer bid+
generalize ::=
'variable' _signature_block?
mutual ::=
'mutual' _declaration_block?
abstract ::=
'abstract' _declaration_block?
private ::=
'private' _declaration_block?
instance ::=
'instance' _declaration_block?
macro ::=
'macro' _declaration_block?
postulate ::=
'postulate' _declaration_block?
primitive ::=
'primitive' _type_signature_block?
_type_signature_block ::=
_indent ( type_signature _newline )+ _dedent
type_signature ::=
_field_names ':' expr
open ::=
'open' ( import | module_name ) _atoms? _import_directives?
import ::=
'import' module_name
module_name ::=
_qid
_import_directives ::=
import_directive+
import_directive ::=
'public'
| 'using' '(' _comma_import_names ')'
| 'hiding' '(' _comma_import_names ')'
| 'renaming' '(' renaming ( ';' renaming )* ')'
| 'using' '(' ')'
| 'hiding' '(' ')'
| 'renaming' '(' ')'
_comma_import_names ::=
_import_name ( ';' _import_name )*
renaming ::=
'module'? id 'to' id
_import_name ::=
'module'? id
module_macro ::=
( 'module' _qid | 'open' 'module' _qid ) _typed_untyped_bindings? '=' module_application import_directive*
module_application ::=
module_name ( '{{' _ELLIPSIS '}}' | '⦃' _ELLIPSIS '⦄' | _atoms )
module ::=
'module' ( _qid | '_' ) _typed_untyped_bindings? 'where' _declaration_block?
pragma ::=
( '{-#' ( [^#x23] | '#'[^-] | '##x2D-'[^}] )* '#-}' )
catchall_pragma ::=
'{-#' 'CATCHALL' '#-}'
syntax ::=
'syntax' id hole_names '=' id+
hole_names ::=
hole_name+
hole_name ::=
_simple_top_hole
| '{' _simple_hole '}'
| '{{' _simple_hole '}}'
| '⦃' _simple_hole '⦄'
| '{' id '=' _simple_hole '}'
| '{{' id '=' _simple_hole '}}'
| '⦃' id '=' _simple_hole '⦄'
_simple_top_hole ::=
id
| '(' _LAMBDA bid _ARROW id ')'
_simple_hole ::=
id
| _LAMBDA bid _ARROW id
pattern ::=
'pattern' id _lambda_bindings? '=' expr
unquote_decl ::=
'unquoteDecl' '=' expr
| 'unquoteDecl' _ids '=' expr
| 'unquoteDef' _ids '=' expr
id ::=
([^ #x09#x0A#x0B#x0C#x0D\.\"\(\)\{\}@\'\_]|"\"[^ #x09#x0A#x0B#x0C#x0Da-zA-Z]|"_"[^ #x09#x0A#x0B#x0C#x0D;.\"\(\)\{\}@])[^ #x09#x0A#x0B#x0C#x0D;.\"\(\)\{\}@]*
_qid ::=
(([^ #x09#x0A#x0B#x0C#x0D;.\"\(\)\{\}@\'\_]|"\"[^ #x09#x0A#x0B#x0C#x0Da-zA-Z]|"_"[^ #x09#x0A#x0B#x0C#x0D;.\"\(\)\{\}@])[^ #x09#x0A#x0B#x0C#x0D;.\"\(\)\{\}@]*".")*([^ #x09#x0A#x0B#x0C#x0D;.\"\(\)\{\}@\'\_]|"\"[^ #x09#x0A#x0B#x0C#x0Da-zA-Z]|"_"[^ #x09#x0A#x0B#x0C#x0D;.\"\(\)\{\}@])[^ #x09#x0A#x0B#x0C#x0D;.\"\(\)\{\}@]* | id
bid ::=
( '_' | id )
_ids ::=
id+
_field_name ::=
id
_field_names ::=
_field_name+
_maybe_dotted_id ::=
_field_name
| '.' _field_name
| '..' _field_name
_maybe_dotted_ids ::=
_maybe_dotted_id+
_arg_ids ::=
_arg_id+
_arg_id ::=
_maybe_dotted_id
| '{' _maybe_dotted_ids '}'
| '{{' _maybe_dotted_ids '}}'
| '⦃' _maybe_dotted_ids '⦄'
| '.' ( '{' _field_names '}' )
| '.' ( '{{' _field_names '}}' | '⦃' _field_names '⦄' )
| '..' ( '{' _field_names '}' )
| '..' ( '{{' _field_names '}}' | '⦃' _field_names '⦄' )
_binding_ids_and_absurds ::=
_application | _qid '=' _qid | _qid '=' '_' | '-' '=' _qid | '-' '=' '_'
attribute ::=
'@' _expr_or_attr
attributes ::=
attribute+
expr ::=
_typed_bindings _ARROW expr
| attributes? _atoms _ARROW expr
| _with_exprs '=' expr
| _with_exprs
stmt ::=
_typed_bindings _ARROW expr
| attributes? _atoms _ARROW expr
| _with_exprs '=' expr
| _with_exprs_stmt
_with_exprs ::=
( _atoms '|' )* _application
_with_exprs_stmt ::=
( _atoms '|' )* _application_stmt
_expr_or_attr ::=
literal
| _qid
| '(' expr ')'
_application ::=
_atoms? _expr2
_application_stmt ::=
_atoms? _expr2_stmt
_expr2_without_let ::=
lambda
| lambda_extended_or_absurd
| forall
| do
| atom
| 'quoteGoal' id 'in' expr
| 'tactic' _atoms
| 'tactic' _atoms '|' _with_exprs
_expr2 ::=
_expr2_without_let
| let
_expr2_stmt ::=
_expr2_without_let
| let_in_do
atom ::=
_atom_curly
| _atom_no_curly
_atoms ::=
atom+
_atom_curly ::=
'{' expr? '}'
_atom_no_curly ::=
'_'
| 'Prop'
| SetN
| 'quote'
| 'quoteTerm'
| 'quoteContext'
| 'unquote'
| PropN
| '{{' expr '}}'
| '⦃' expr '⦄'
| '(|' expr '|)'
| '⦇' expr '⦈'
| '(' ')'
| '{{' '}}'
| '⦃' '⦄'
| id '@' atom
| '.' atom
| record_assignments
| field_assignments
| _ELLIPSIS
| _expr_or_attr
forall ::=
_FORALL _typed_untyped_bindings _ARROW expr
let ::=
'let' _indent? ( _declaration _newline )* _declaration _newline? _let_body
let_in_do ::=
'let' _indent? ( _declaration _newline )* _declaration ( _newline _dedent | _newline _let_body | _let_body )
_let_body ::=
'in' expr
lambda ::=
_LAMBDA _lambda_bindings _ARROW expr
_lambda_bindings ::=
_typed_untyped_binding* ( _typed_untyped_binding | '(' ')' | '{' '}' | '{{' '}}' | '⦃' '⦄' )
lambda_extended_or_absurd ::=
_LAMBDA ( '{' lambda_clause '}' | '{' _lambda_clauses '}' | 'where' _lambda_clauses | _lambda_bindings )
_lambda_clauses ::=
( _lambda_clause_maybe_absurd ';' )* _lambda_clause_maybe_absurd
_lambda_clause_maybe_absurd ::=
lambda_clause_absurd | lambda_clause
lambda_clause_absurd ::=
catchall_pragma? _application
lambda_clause ::=
catchall_pragma? _atoms? _ARROW expr
do ::=
'do' _indent ( _do_stmt _newline )+ _dedent
_do_stmt ::=
stmt do_where?
do_where ::=
'where' _lambda_clauses
record_assignments ::=
'record' ( '{' _record_assignments? '}' )
field_assignments ::=
'record' _atom_no_curly ( '{' _field_assignments? '}' )
_record_assignments ::=
( _record_assignment ';' )* _record_assignment
_field_assignments ::=
( field_assignment ';' )* field_assignment
_record_assignment ::=
field_assignment
| module_assignment
field_assignment ::=
id '=' expr
module_assignment ::=
module_name _atoms? _import_directives?
_typed_bindings ::=
typed_binding+
typed_binding ::=
'(' _application ':' expr ')'
| '{' _binding_ids_and_absurds ':' expr '}'
| '{{' _binding_ids_and_absurds ':' expr '}}'
| '⦃' _binding_ids_and_absurds ':' expr '⦄'
| '.' ( '(' _application ':' expr ')' | '{' _binding_ids_and_absurds ':' expr '}' | '{{' _binding_ids_and_absurds ':' expr '}}' | '⦃' _binding_ids_and_absurds ':' expr '⦄' )
| '..' ( '(' _application ':' expr ')' | '{' _binding_ids_and_absurds ':' expr '}' | '{{' _binding_ids_and_absurds ':' expr '}}' | '⦃' _binding_ids_and_absurds ':' expr '⦄' )
| '(' attributes _application ':' expr ')'
| '{' attributes _binding_ids_and_absurds ':' expr '}'
| '{{' attributes _binding_ids_and_absurds ':' expr '}}'
| '⦃' attributes _binding_ids_and_absurds ':' expr '⦄'
| '(' open ')'
| '(' 'let' _declaration_block ')'
_typed_untyped_bindings ::=
_typed_untyped_binding+
_typed_untyped_binding ::=
untyped_binding
| typed_binding
untyped_binding ::=
bid
| '{' _binding_ids_and_absurds '}'
| '{{' _binding_ids_and_absurds '}}'
| '⦃' _binding_ids_and_absurds '⦄'
| '.' ( bid | '{' _binding_ids_and_absurds '}' | '{{' _binding_ids_and_absurds '}}' | '⦃' _binding_ids_and_absurds '⦄' )
| '..' ( bid | '{' _binding_ids_and_absurds '}' | '{{' _binding_ids_and_absurds '}}' | '⦃' _binding_ids_and_absurds '⦄' )
| '(' _binding_ids_and_absurds ')'
| '(' attributes _binding_ids_and_absurds ')'
| '{' attributes _binding_ids_and_absurds '}'
| '{{' attributes _binding_ids_and_absurds '}}'
| '⦃' attributes _binding_ids_and_absurds '⦄'
integer ::=
'#x2D-'?('0x'[0-9a-fA-F]+|[0-9]+)
string ::=
'\".'*'\"'
literal ::=
'#x2D-'?('0x'[0-9a-fA-F]+|[0-9]+)
| '\".'*'\"'
comment ::=
( '--' '.'* | '{--}' | '{-' [^#x23] ( [^-] | '-'[^}] )* '-}' )
SetN ::=
'Set' atom?
PropN ::=
'propN'