-
Notifications
You must be signed in to change notification settings - Fork 2
/
tree-sitter-erlang.ebnf
357 lines (259 loc) · 7.46 KB
/
tree-sitter-erlang.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
//
// From tree-sitter-erlang/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 ::=
_structure_item*
_structure_item ::=
expression
| _module
_module ::=
type_declaration
| function_spec
| function_declaration
| module_attribute
| module_name
| module_export
module_attribute ::=
'-' atom '(' expression ')' '.'
module_name ::=
'-' 'module' '(' atom ')' '.'
module_export ::=
'-' ( 'export' | 'export_type' ) '(' '[' ( atom '/' integer ( ',' atom '/' integer )* )? ']' ')' '.'
function_declaration ::=
function_clause ( ';' function_clause )* '.'
function_clause ::=
atom lambda_clause
comment ::=
'%.'*
type_declaration ::=
'-' ( 'type' | 'opaque' ) atom ( '(' ( variable ( ',' variable )* )? ')' ) '::' type_expression '.'
function_spec ::=
'-' ( 'spec' | 'callback' ) atom ( '(' ( type_expression ( ',' type_expression )* )? ')' ) '->' type_expression '.'
type_expression ::=
( type_atom | type_application | type_bitstring | type_fun | type_integer | type_map | type_record | type_tuple | type_variable | _type_list ) ( '|' ( type_atom | type_application | type_bitstring | type_fun | type_integer | type_map | type_record | type_tuple | type_variable | _type_list ) )*
type_variable ::=
variable
type_atom ::=
atom
type_application ::=
( atom ':' )? atom ( '(' ( type_expression ( ',' type_expression )* )? ')' )
type_bitstring ::=
'<<' ( '_' ':' variable | '_' ':' '_' '*' variable | '_' ':' variable '_' ':' '_' '*' variable | '>>' )
type_fun ::=
'fun' '(' ( '(' '...' ')' '->' type_expression | ( '(' ( type_expression ( ',' type_expression )* )? ')' ) '->' type_expression )? ')'
type_integer ::=
integer
| integer '..' integer
_type_list ::=
type_list
| type_nonempty_list
type_list ::=
'[' type_expression ']'
type_nonempty_list ::=
'[' type_expression ',' '...' ']'
type_tuple ::=
'{' ( type_expression ( ',' type_expression )* )? '}'
type_map ::=
'#' '{' ( type_map_entry ( ',' type_map_entry )* )? '}'
type_map_entry ::=
type_expression ( '=>' | ':=' ) type_expression
type_record ::=
'#' atom '{' ( type_record_field ( ',' type_record_field )* )? '}'
type_record_field ::=
type_expression '::' type_expression
pattern ::=
term | variable | pat_list | pat_tuple
pat_list ::=
'[' ( pattern ( ',' pattern )* )? ']' | pat_list_cons
pat_list_cons ::=
'[' ( pattern ( ',' pattern )* ) '|' pattern ']'
pat_tuple ::=
'{' ( pattern ( ',' pattern )* )? '}'
pat_map ::=
'#' '{' ( pat_map_entry ( ',' pat_map_entry )* )? '}'
pat_map_entry ::=
term ':=' pattern
expression ::=
'(' _expr ')'
| _expr
_expr ::=
expr_begin_block
| expr_bitstring_comprehension
| expr_case
| expr_catch
| expr_function_call
| expr_if
| expr_lambda
| expr_list
| expr_list_comprehension
| expr_macro_application
| expr_map_update
| expr_match
| expr_receive
| expr_record_access
| expr_record_update
| expr_send
| expr_throw
| expr_try
| expr_op
| term
| variable
expr_map_update ::=
expression map
expr_record_access ::=
expression '#' atom '.' atom
expr_record_update ::=
expression record
expr_try ::=
'try' expression ( 'of' case_clause ( ';' case_clause )* )? ( expr_try_catch | expr_try_after | _expr_try_catch_after ) 'end'
expr_try_catch ::=
'catch' catch_clause ( ';' catch_clause )*
expr_try_after ::=
'after' expression
_expr_try_catch_after ::=
expr_try_catch expr_try_after
catch_clause ::=
catch_pattern guard_clause? '->' ( expression ( ',' expression )* )
catch_pattern ::=
pattern ( ':' pattern )? ( ':' variable )?
expr_catch ::=
'catch' expression
expr_throw ::=
'throw' expression
expr_begin_block ::=
'begin' expression ( ',' expression )* 'end'
expr_list_comprehension ::=
'[' expression '||' expr_list_generator ( ',' expr_list_filter )? ']'
expr_list_generator ::=
expression '<-' expression
expr_list_filter ::=
expression ( ',' expression )*
expr_bitstring_comprehension ::=
'<<' term '||' expr_bitstring_generator ( ',' expr_bitstring_filter )? '>>'
expr_bitstring_generator ::=
'<<' expression '>>' '<=' expression
expr_bitstring_filter ::=
expression ( ',' expression )*
expr_op ::=
_expr_operator_unary
| _expr_operator_binary
_expr_operator_unary ::=
( '+' | '-' | 'bnot' | 'not' ) expression
_expr_operator_binary ::=
expression ( '*' | '+' | '-' | '/' | '/=' | '<' | '=/=' | '=:=' | '=<' | '==' | '>' | '>=' | 'and' | 'andalso' | 'band' | 'bor' | 'bsl' | 'bsr' | 'bxor' | 'div' | 'or' | 'orelse' | 'rem' | 'xor' ) expression
| expression ( '=!' | '++' | '--' ) expression
expr_send ::=
expression '!' expression
expr_receive ::=
'receive' ( case_clause ( ';' case_clause )* )? expr_receive_after? 'end'
expr_receive_after ::=
'after' case_clause
expr_if ::=
'if' if_clause ( ';' if_clause )* 'end'
if_clause ::=
guard_seq '->' ( expression ( ',' expression )* )
expr_list ::=
'[' ( expression ( ',' expression )* )? ']' | expr_list_cons
expr_list_cons ::=
'[' ( expression ( ',' expression )* ) '|' expression ']'
expr_case ::=
'case' expression 'of' case_clause ( ';' case_clause )* 'end'
case_clause ::=
pattern guard_clause? '->' ( expression ( ',' expression )* )
guard_clause ::=
'when' guard_seq
guard_seq ::=
guard ( ';' guard )*
guard ::=
expression ( ',' expression )*
expr_match ::=
expression '=' expression
expr_lambda ::=
'fun' lambda_clause ( ';' lambda_clause )* 'end'
lambda_clause ::=
( '(' ( pattern ( ',' pattern )* )? ')' ) guard_clause? '->' ( expression ( ',' expression )* )
expr_function_call ::=
_function_name ( '(' ( expression ( ',' expression )* )? ')' )
_function_name ::=
computed_function_name | qualified_function_name
qualified_function_name ::=
( variable | atom | '(' expression ')' ) ':' ( variable | atom | '(' expression ')' )
computed_function_name ::=
variable | atom | '(' expression ')'
expr_macro_application ::=
'?' _macro_name ( '(' ( expression ( ',' expression )* )? ')' )?
_macro_name ::=
variable
| atom
variable ::=
[_A-Z\xC0-\xD6\xD8-\xDE][_@a-zA-Z0-9\xC0-\xD6\xD8-\xDE\xDF-\xF6\xF8-\xFF]*
term ::=
atom
| binary_string
| char
| float
| integer
| list
| tuple
| map
| record
| string
list ::=
'[' ( expression ( ',' expression )* )? ']'
tuple ::=
'{' ( expression ( ',' expression )* )? '}'
atom ::=
( _unquoted_atom | _quoted_atom )
_unquoted_atom ::=
[a-z\xDF-\xF6\xF8-\xFF][_@a-zA-Z0-9\xC0-\xD6\xD8-\xDE\xDF-\xF6\xF8-\xFF]*
_quoted_atom ::=
"'" ( [^'\]+ | _escape )* "'"
integer ::=
'-'?'2#'[01_]+
| '-'?'16#'[a-fA-F0-9_]+
| '-'?([0-9*_]*'#')?[0-9_]+
float ::=
'-'?([0-9_]*'#')?[0-9_]+'.'[0-9_]+('e-'?[0-9_]+)?
string ::=
'"' ( [^"\]+ | _escape )* '"'
char ::=
'$' ( [^\] | _escape )
_escape ::=
( '\\' ( [0-7]'{1,3}' | 'x'[0-9a-fA-F]'{2}' | 'x{'[0-9a-fA-F]+'}' | '\n' | [nrtvbfesd] ) )
binary_string ::=
'<<' ( bin_part ( ',' bin_part )* )? '>>'
bin_part ::=
( integer | float | string ) bin_sized? bin_type_list?
| '(' expression ')' bin_sized? bin_type_list?
bin_sized ::=
':' integer
bin_type_list ::=
'\/' bin_type ( '-' bin_type )*
bin_type ::=
'big'
| 'binary'
| 'bits'
| 'bitstring'
| 'bytes'
| 'float'
| 'integer'
| 'little'
| 'native'
| 'signed'
| 'unsigned'
| 'utf16'
| 'utf32'
| 'utf8'
map ::=
'#' '{' ( map_entry ( ',' map_entry )* )? '}'
map_entry ::=
term ( '=>' | ':=' ) expression
record ::=
'#' atom '{' ( record_field ( ',' record_field )* )? '}'
record_field ::=
term '=' expression