-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtree-sitter-fennel.ebnf
254 lines (188 loc) · 4.66 KB
/
tree-sitter-fennel.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
//
// From tree-sitter-fennel/src/grammar.json
//
//
// EBNF to generate railroad diagram at
// (IPV6) https://www.bottlecaps.de/rr/ui
// (IPV4) https://rr.red-dove.com/ui
//
program ::=
_sexp*
_sexp ::=
_special_form
| symbol
| multi_symbol
| list
| sequential_table
| table
| _literal
_special_form ::=
fn
| lambda
| hashfn
| match
| let
| global
| local
| var
| set
| each
| collect
| icollect
| accumulate
| for
| quote
each ::=
'(' 'each' '[' iter_bindings ']' _sexp* ')'
iter_bindings ::=
_binding* _sexp ( ':until' _sexp )?
for ::=
'(' 'for' for_clause _sexp* ')'
for_clause ::=
'[' symbol _sexp _sexp _sexp? ']'
let ::=
'(' 'let' let_clause _sexp* ')'
let_clause ::=
'[' ( _binding _sexp )* ']'
global ::=
'(' 'global' _binding _sexp ')'
local ::=
'(' 'local' _binding _sexp ')'
var ::=
'(' 'var' _binding _sexp ')'
set ::=
'(' 'set' _assignment _sexp ')'
_binding ::=
multi_value_binding
| _non_multi_value_binding
multi_value_binding ::=
'(' _non_multi_value_binding* ')'
_non_multi_value_binding ::=
binding
| sequential_table_binding
| table_binding
binding ::=
symbol
sequential_table_binding ::=
'[' _non_multi_value_binding* ( '&' binding )? ']'
table_binding ::=
'{' ( ':' binding | '&as' binding | _sexp _non_multi_value_binding )* '}'
_assignment ::=
multi_value_assignment
| _non_multi_value_assignment
multi_value_assignment ::=
'(' _non_multi_value_assignment* ')'
_non_multi_value_assignment ::=
assignment
| sequential_table_assignment
| table_assignment
assignment ::=
symbol
| multi_symbol
sequential_table_assignment ::=
'[' _non_multi_value_assignment* ']'
table_assignment ::=
'{' ( ':' assignment | _sexp _non_multi_value_assignment )* '}'
hashfn ::=
'(' 'hashfn' _sexp* ')'
| '#' _sexp
fn ::=
'(' 'fn' _function_body ')'
lambda ::=
'(' ( 'lambda' | 'λ' ) _function_body ')'
_function_body ::=
( symbol | multi_symbol )? parameters ( string? _sexp+ )?
parameters ::=
'[' ( _binding | vararg )* ']'
match ::=
'(' 'match' _sexp ( _pattern _sexp )* ')'
_pattern ::=
_simple_pattern
| where_pattern
| guard_pattern
_simple_pattern ::=
multi_value_pattern
| _non_multi_value_pattern
guard_pattern ::=
'(' _simple_pattern '?' _sexp+ ')'
where_pattern ::=
'(' 'where' ( _simple_pattern | '(' 'or' _simple_pattern* ')' ) _sexp* ')'
multi_value_pattern ::=
'(' _non_multi_value_pattern* ')'
_non_multi_value_pattern ::=
_literal
| symbol
| multi_symbol
| sequential_table_pattern
| table_pattern
sequential_table_pattern ::=
'[' _non_multi_value_pattern* ']'
table_pattern ::=
'{' ( ':' _simple_pattern | _sexp _non_multi_value_pattern )* '}'
collect ::=
'(' 'collect' '[' iter_bindings ']' _sexp* ')'
icollect ::=
'(' 'icollect' '[' iter_bindings ']' _sexp* ')'
accumulate ::=
'(' 'accumulate' '[' _binding _sexp iter_bindings ']' _sexp* ')'
quote ::=
'(' 'quote' _quoted_sexp ')'
| ( "'" | '`' ) _quoted_sexp
unquote ::=
',' _sexp
_quoted_sexp ::=
unquote
| symbol
| multi_symbol
| multi_symbol_method
| quoted_list
| quoted_sequential_table
| quoted_table
| _literal
quoted_list ::=
'(' _quoted_sexp* ')'
quoted_sequential_table ::=
'[' _quoted_sexp* ']'
quoted_table ::=
'{' _quoted_sexp* '}'
list ::=
'(' ( _sexp | multi_symbol_method ) _sexp* ')'
sequential_table ::=
'[' _sexp* ']'
table_pair ::=
':' binding | string _sexp | ( symbol | multi_symbol ) _sexp
table ::=
'{' table_pair* '}'
_literal ::=
string
| number
| boolean
| vararg
| nil
| nil_safe
nil ::=
'nil'
nil_safe ::=
'?.'
vararg ::=
'...'
boolean ::=
'true'
| 'false'
string ::=
':'[^(){}#x5B#x5D"'~;,@` #x09#x0A#x0B#x0C#x0D]+
| '"' ( [^"\]+ | escape_sequence )* '"'
escape_sequence ::=
( '\\' ( [^xu0-9] | [0-9]'{1,3}' | 'x'[0-9a-fA-F]'{2}' | 'u{'[0-9a-fA-F]+'}' ) )
number ::=
( ( '-' | '+' )? ( [0-9][_0-9]* | '.' [0-9][_0-9]* | [0-9][_0-9]* '.' [0-9][_0-9]*? ) ( ( 'e' | 'E' ) ( '-' | '+' )? [0-9][_0-9]* )? | ( '-' | '+' )? ( '0x' | '0X' ) ( [a-fA-F0-9][_a-fA-F0-9]* | '.' [a-fA-F0-9][_a-fA-F0-9]* | [a-fA-F0-9][_a-fA-F0-9]* '.' [a-fA-F0-9][_a-fA-F0-9]*? ) ( ( 'p' | 'P' ) ( '-' | '+' )? [a-fA-F0-9][_a-fA-F0-9]* )? )
multi_symbol ::=
symbol ( '.' symbol_immediate )+
multi_symbol_method ::=
( symbol | multi_symbol ) ':' symbol_immediate
symbol ::=
( ':' | '.' [^(){}#x5B#x5D"'~;,@` #x09#x0A#x0B#x0C#x0D]* | [^#x23(){}#x5B#x5D"'~;,@`.: #x09#x0A#x0B#x0C#x0D][^(){}#x5B#x5D"'~;,@`.: #x09#x0A#x0B#x0C#x0D]* )
symbol_immediate ::=
( ':' | '.' [^(){}#x5B#x5D"'~;,@` #x09#x0A#x0B#x0C#x0D]* | [^#x23(){}#x5B#x5D"'~;,@`.: #x09#x0A#x0B#x0C#x0D][^(){}#x5B#x5D"'~;,@`.: #x09#x0A#x0B#x0C#x0D]* )
comment ::=
( ';' '.'* )