-
Notifications
You must be signed in to change notification settings - Fork 2
/
tree-sitter-clojure.ebnf
353 lines (258 loc) · 5.13 KB
/
tree-sitter-clojure.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
//
// From tree-sitter-clojure/src/grammar.json
//
//
// EBNF to generate railroad diagram at
// (IPV6) https://www.bottlecaps.de/rr/ui
// (IPV4) https://rr.red-dove.com/ui
//
program ::=
_anything*
_anything ::=
_literals
| symbol
| interop
| _functions
| quote
| comment
| deref
| syntax_quote
| var_quote
| unquote
| unquote_splice
| gensym
| shorthand_function_arg
| reader_conditional
_literals ::=
nil
| boolean
| number
| symbolic_value
| character
| string
| regex
| keyword
| _collection_literals
| tagged_literal
_collection_literals ::=
metadata? ( list | vector | hash_map | set )
nil ::=
'nil'
boolean ::=
true
| false
true ::=
'true'
false ::=
'false'
number ::=
_number
_number ::=
number_long
| number_double
| number_bigint
| number_bigdecimal
| number_ratio
number_long ::=
_normal_long
| _number_hex
| _number_arbitrary_radix
| _number_octal
_normal_long ::=
[-+]?[0-9]+
_number_hex ::=
'-'?'0'[xX][0-9a-fA-F]+
_number_arbitrary_radix ::=
'-'?[0-9]+[rR][0-9a-zA-Z]+
_number_octal ::=
'-'?'0'[0-9]+
number_double ::=
( ( [0-9]+ ( '_'+ [0-9]+ )* ) '.' ( [0-9]+ ( '_'+ [0-9]+ )* )? ( [eE] ( '-' | '+' )? ( [0-9]+ ( '_'+ [0-9]+ )* ) )? [fFdD]? | '.' ( [0-9]+ ( '_'+ [0-9]+ )* ) ( [eE] ( '-' | '+' )? ( [0-9]+ ( '_'+ [0-9]+ )* ) )? [fFdD]? | ( [0-9]+ ( '_'+ [0-9]+ )* ) [eE] ( '-' | '+' )? ( [0-9]+ ( '_'+ [0-9]+ )* ) [fFdD]? | ( [0-9]+ ( '_'+ [0-9]+ )* ) ( [eE] ( '-' | '+' )? ( [0-9]+ ( '_'+ [0-9]+ )* ) )? [fFdD] )
number_bigint ::=
[-+]?[0-9]+'N'
number_bigdecimal ::=
'-'?[0-9]+'.'[0-9]+([eE][+-]?[0-9]+)?'M'
number_ratio ::=
[-+]?[0-9]+'\/'[0-9]+
symbolic_value ::=
'##' ( infinity | negative_infinity | not_a_number )
infinity ::=
'Inf'
negative_infinity ::=
'-Inf'
not_a_number ::=
'NaN'
character ::=
_character
_character ::=
'\\' ( _normal_char | _special_char | _unicode_char | _octal_char )
_normal_char ::=
'.'
_special_char ::=
'newline'
| 'space'
| 'tab'
| 'formfeed'
| 'backspace'
| 'return'
_unicode_char ::=
'u' _hex_char _hex_char _hex_char _hex_char
_hex_char ::=
[A-Fa-f0-9]
_octal_char ::=
'o' _octal_num
_octal_num ::=
[0-3][0-7][0-7]
| [0-7][0-7]
| [0-7]
string ::=
_string
_string ::=
'"' ( '\"' | [^"] )* '"'
regex ::=
_regex
_regex ::=
'#"' ( '\"' | [^"#x0A#x0D] )* '"'
quote ::=
_quote
_quote ::=
"'" _anything
| '(quote' _anything ')'
keyword ::=
_keyword
_keyword ::=
_unqualified_keyword
| qualified_keyword
_unqualified_keyword ::=
':' _keyword_chars
qualified_keyword ::=
'::' _keyword_chars
| '::' _keyword_chars '/' _keyword_chars
_keyword_chars ::=
[a-zA-Z0-9#x2D-_\!\+.][a-zA-Z0-9#x2D-_\!\+.:\?]*
symbol ::=
_symbol
_symbol ::=
threading_macro
| _symbol_chars
| qualified_symbol
threading_macro ::=
'->'
| '->>'
| 'as->'
| 'some->'
| 'some->>'
| 'cond->'
| 'cond->>'
_symbol_chars ::=
[a-zA-Z\*\+\!#x2D-_\?][a-zA-Z0-9\*\+\!#x2D-_\?\':]*
qualified_symbol ::=
_qualified_symbol
_qualified_symbol ::=
_symbol_chars '/' _symbol_chars
interop ::=
member_access
| field_access
| new_class
member_access ::=
'.'[a-zA-Z_][a-zA-Z_]*
field_access ::=
'.-'[a-zA-Z_][a-zA-Z_]*
new_class ::=
([a-zA-Z_][a-zA-Z_]*'.')([a-zA-Z_]+'.')*
list ::=
_list
_list ::=
'(' _anything* ')'
vector ::=
_vector
_vector ::=
'[' _anything* ']'
hash_map ::=
_hash_map
_hash_map ::=
'{' _hash_map_kv_pair* '}'
| namespace_map
namespace_map ::=
'#::{' _hash_map_kv_pair* '}'
| '\#:'[a-zA-Z\*\+\!#x2D-_\?][a-zA-Z0-9\*\+\!#x2D-_\?\':]* '{' _hash_map_kv_pair* '}'
_hash_map_kv_pair ::=
_hash_map_key _hash_map_value
_hash_map_key ::=
_anything
_hash_map_value ::=
_anything
set ::=
_set
_set ::=
'#{' _anything* '}'
comment ::=
semicolon
| shebang_line
| ignore_form
| comment_macro
semicolon ::=
';' '.'*
shebang_line ::=
'#!' '.'*
ignore_form ::=
'#_' _anything
comment_macro ::=
'(' 'comment' _anything* ')'
_functions ::=
anonymous_function
| shorthand_function
| defn
anonymous_function ::=
'(' 'fn' function_name? _after_the_fn_name ')'
_after_the_fn_name ::=
_single_arity_fn
| _multi_arity_fn
function_name ::=
symbol
_single_arity_fn ::=
params function_body?
_multi_arity_fn ::=
( '(' _single_arity_fn ')' )+
function_body ::=
_anything+
params ::=
vector
shorthand_function ::=
'#(' _anything* ')'
shorthand_function_arg ::=
'%'[1-9&]*
defn ::=
'(' ( 'defn' | 'defn-' ) metadata? function_name docstring? attr_map? _after_the_fn_name ')'
docstring ::=
string
attr_map ::=
hash_map
metadata ::=
metadata_shorthand+
| _metadata_map
_metadata_map ::=
'^' hash_map
metadata_shorthand ::=
'^:' _keyword_chars
| '^"' ( '\"' | [^"] )* '"'
| '^' _symbol_chars
syntax_quote ::=
'`' _anything
var_quote ::=
"#'" symbol
unquote ::=
'~' _anything
unquote_splice ::=
'~@' _anything
gensym ::=
[a-zA-Z\*\+\!#x2D-_\?][a-zA-Z0-9\*\+\!#x2D-_\?\':]*"\#"
deref ::=
'@' ( symbol | list )
tagged_literal ::=
'#' ( _symbol_chars | _qualified_symbol ) _anything
reader_conditional ::=
_reader_conditional_symbol '(' ( keyword _anything )* ')'
_reader_conditional_symbol ::=
'#?'
| '#?@'