-
Notifications
You must be signed in to change notification settings - Fork 2
/
tree-sitter-carp.ebnf
311 lines (234 loc) · 4.96 KB
/
tree-sitter-carp.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
//
// From tree-sitter-carp/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 ::=
_expr*
line_comment ::=
( ';' '.'* )
_expr ::=
_special_forms
| _literals
| _shorthand
| _identifier
| _defs
| _specials
| call
| array
| map
| register
| hidden
| doc
| signature
| private
call ::=
'(' _call_name _expr*? ')'
_call_name ::=
_identifier
| short_fn_ref
array ::=
'[' _expr*? ']'
map ::=
'{' ( _expr _expr )*? '}'
hidden ::=
'(' 'hidden' _identifier ')'
doc ::=
'(' 'doc' _identifier str_literal ')'
signature ::=
'(' 'sig' _identifier '(' interface_fn ')' ')'
private ::=
'(' 'private' _identifier ')'
register ::=
'(' 'register' _defs_name ( type | _shorthand ) _expr? ')'
_special_forms ::=
fn
| let
| do
| if
| while
| use
| with
| ref
| address
| set
| the
| match
fn ::=
'(' 'fn' _parameters _expr? ')'
_parameters ::=
_identifier
| parameters
| quote
| short_quote
parameters ::=
'[' _identifier*? ']'
let ::=
'(' 'let' _let_pairs _expr? ')'
_let_pairs ::=
_identifier
| call
| pairs
| quote
| short_quote
pairs ::=
'[' ( _expr _expr )* ']'
do ::=
'(' 'do' _expr* ')'
if ::=
'(' 'if' _expr _expr _expr ')'
while ::=
'(' 'while' _expr _expr? ')'
use ::=
'(' 'use' _use_module ')'
with ::=
'(' 'with' _use_module _expr* ')'
_use_module ::=
symbol
| scoped_identifier
| quote
| short_quote
| call
ref ::=
'(' 'ref' _expr? ')'
address ::=
'(' 'address' _expr ')'
set ::=
'(' 'set!' _expr _expr ')'
the ::=
'(' 'the' type _expr ')'
match ::=
'(' 'match' _expr match_case*? ')'
match_case ::=
_expr _expr
_defs ::=
def
| defn
| definterface
| defmacro
| defndynamic
| defmodule
| deftype
| deftemplate
def ::=
'(' 'def' _defs_name _expr ')'
defn ::=
'(' 'defn' _defs_name _parameters _expr? ')'
definterface ::=
'(' 'definterface' _defs_name ( _identifier | _sig ) ')'
_sig ::=
quote
| short_quote
| '(' interface_fn ')'
defmacro ::=
'(' 'defmacro' _defs_name _parameters _expr? ')'
defndynamic ::=
'(' 'defndynamic' _defs_name _parameters _expr? ')'
defmodule ::=
'(' 'defmodule' _defmodule_name _expr* ')'
_defmodule_name ::=
symbol
| quote
| short_quote
deftype ::=
'(' 'deftype' _deftype_names ( _deftype_struct | _deftype_enum1* | _deftype_enum2* ) ')'
_deftype_struct ::=
'[' ( _field type )* ']'
_deftype_enum1 ::=
'(' symbol '[' _field* ']' ')'
_deftype_enum2 ::=
symbol
_deftype_names ::=
symbol
| '(' symbol symbol*? ')'
_field ::=
symbol
| call
| quote
| short_quote
deftemplate ::=
'(' 'deftemplate' _defs_name type _deftemplate_str _deftemplate_str ')'
_deftemplate_str ::=
str_literal
| pattern_literal
| quote
| short_quote
_defs_name ::=
_identifier
| quote
| short_quote
_specials ::=
quote
quote ::=
'(' 'quote' _expr ')'
_shorthand ::=
short_ref
| short_copy
| short_fn_ref
| short_quote
short_ref ::=
'&' _expr
short_copy ::=
'@' _expr
short_fn_ref ::=
'~' _expr
short_quote ::=
"'" _expr
type ::=
( 'Bool' | 'Byte' | 'Char' | 'Int' | 'Long' | 'Float' | 'Double' | 'Vector2' | 'Vector3' | 'VectorN' | 'String' | 'Pattern' | 'Array' | 'Map' | 'Maybe' | 'Result' | 'Id' | 'Ptr' )
| complex_type
| symbol
complex_type ::=
'(' ( ( 'Bool' | 'Byte' | 'Char' | 'Int' | 'Long' | 'Float' | 'Double' | 'Vector2' | 'Vector3' | 'VectorN' | 'String' | 'Pattern' | 'Array' | 'Map' | 'Maybe' | 'Result' | 'Id' | 'Ptr' ) | complex_type | symbol | interface_fn | static_lifetime )* ')'
interface_fn ::=
( 'Fn' | 'λ' ) ( _type_parameters ) ( _shorthand | type )
_type_parameters ::=
symbol
| call
| type_parameters
| quote
| short_quote
static_lifetime ::=
'StaticLifetime'
type_parameters ::=
'[' ( type | _shorthand )* ']'
_literals ::=
unit
| str_literal
| char_literal
| pattern_literal
| bool_literal
| integer_literal
| float_literal
integer_literal ::=
( '-'? ( '0x'[0-9a-fA-F]+ | '0x'[0-9a-fA-F]+'l' | '0b'[01]+ | '0b'[01]+'l' | '0b'[01]+'b' | [0-9][0-9]* | [0-9][0-9]*'l' | [0-9][0-9]*'b' ) )
float_literal ::=
( '-'? ( [0-9][0-9]*'f' | [0-9][0-9]*'.'[0-9][0-9]*'f'? ) )
bool_literal ::=
'true'
| 'false'
str_literal ::=
'"' ( [^"\$]+ | escape_sequence | meta_symbol )* '"'
char_literal ::=
'\\' ( escape_sequence | [ #x09#x0A#x0B#x0C#x0D] | '.' )
pattern_literal ::=
'#"' ( [^"]+ )* '"'
meta_symbol ::=
'\$'[^({#x5B#x5D})"'@&|`;.,~#x23 #x09#x0A#x0B#x0C#x0D\:][^({#x5B#x5D})"'@&|`;.,~#x23 #x09#x0A#x0B#x0C#x0D\]*
escape_sequence ::=
( '\'[^xu] | '\u'[0-9a-fA-F]'{4}' | '\u{'[0-9a-fA-F]+'}' | '\x'[0-9a-fA-F]'{2}' )
unit ::=
'()'
_identifier ::=
keyword
| symbol
| scoped_identifier
scoped_identifier ::=
( scoped_identifier | symbol | keyword ) '.' _identifier
keyword ::=
':'[^({#x5B#x5D})"'@&|`;.,~#x23 #x09#x0A#x0B#x0C#x0D\]
symbol ::=
[^({#x5B#x5D})"'@&|`;.,~#x23 #x09#x0A#x0B#x0C#x0D\:][^({#x5B#x5D})"'@&|`;.,~#x23 #x09#x0A#x0B#x0C#x0D\]*