-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtree-sitter-quakec.ebnf
273 lines (205 loc) · 6.07 KB
/
tree-sitter-quakec.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
//
// From tree-sitter-quakec/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 ::=
_top_level*
_top_level ::=
function_declaration
| variable_definition
| field_definition
| function_definition
| enum_definition
| modelgen_pragma
| _preprocessor_top_level
function_declaration ::=
simple_type ( identifier parameter_list | parameter_list identifier ) ';'
function_definition ::=
simple_type ( parameter_list identifier | identifier parameter_list ) '='? _frame_specifier? ( builtin_literal | _statement ) ';'?
enum_definition ::=
'enum' ( 'class' identifier )? ( ':' simple_type )? '{' ( _enum_constant_specifier ( ',' _enum_constant_specifier )* )* '}' ';'?
_enum_constant_specifier ::=
identifier ( '=' _expression )?
_frame_specifier ::=
'[' ( frame_identifier | integer_frame_literal ) ',' identifier ']'
variable_definition ::=
_type_modifier*? simple_type ( _variable_name_specifier ( '=' _expression )? ) ( ',' ( _variable_name_specifier ( '=' _expression )? ) )* ';'
_variable_name_specifier ::=
identifier _array_declarator?
_variable_def_type ::=
simple_type
| function_ref_type
_array_declarator ::=
'[' _expression? ']'
field_definition ::=
'.' ( _field_variable_definition | _field_function_definition ) ';'
_field_variable_definition ::=
simple_type identifier ( ',' identifier )*
_field_function_definition ::=
simple_type parameter_list identifier ( ',' identifier )*
parameter_list ::=
'(' ( parameter ( ',' parameter )* )? ( ','? '...' )? ')'
parameter ::=
( simple_type | field_ptr_type | function_ref_type ) identifier ( '=' _parameter_initializer )?
_parameter_initializer ::=
_literal
| identifier
modelgen_pragma ::=
'$' ( 'flags' | 'base' | 'cd' | 'frame' | 'modelname' | 'origin' | 'scale' | 'skin' | 'spritename' | 'type' | 'load' ) [^#x0A]+
_preprocessor_top_level ::=
preproc_ifdef_top_level
| preproc_def
| preproc_undef
_preprocessor_local ::=
preproc_ifdef_local
| preproc_def
| preproc_undef
preproc_ifdef_top_level ::=
( '#ifdef' | '#ifndef' ) identifier '#x0D'?'#x0A' _top_level* ( '#else' '#x0D'?'#x0A' _top_level* )? '#endif' '#x0D'?'#x0A'
preproc_ifdef_local ::=
( '#ifdef' | '#ifndef' ) identifier '#x0D'?'#x0A' _simple_statement* ( '#else' '#x0D'?'#x0A' _simple_statement* )? '#endif' '#x0D'?'#x0A'
preproc_def ::=
'#define' identifier _preproc_arg? '#x0D'?'#x0A'
preproc_undef ::=
'#undef' identifier '#x0D'?'#x0A'
_preproc_arg ::=
'\S'([^/#x0A]|'\/'[^*]|'\#x0D'?'#x0A')*
_statement ::=
case_statement
| _non_case_statement
_non_case_statement ::=
compound_statement
| _simple_statement
compound_statement ::=
'{' _statement* '}'
_simple_statement ::=
switch_statement
| break_statement
| continue_statement
| if_statement
| for_statement
| while_statement
| do_while_statement
| return_statement
| _variable_definition_statement
| _expression_statement
| _preprocessor_local
switch_statement ::=
'switch' _parenthesized_expression compound_statement
case_statement ::=
( 'case' _expression | 'default' ) ':' _non_case_statement*
break_statement ::=
'break' ';'
continue_statement ::=
'continue' ';'
for_statement ::=
'for' '(' _expression ';' _expression ';' _expression ')' _statement
if_statement ::=
'if' _parenthesized_expression _statement ( 'else' _statement )?
while_statement ::=
'while' _parenthesized_expression _statement
do_while_statement ::=
'do' _statement 'while' _parenthesized_expression ';'
return_statement ::=
'return' _expression? ';'
_variable_definition_statement ::=
variable_definition
_expression_statement ::=
_expression ';'
_expression ::=
identifier
| frame_identifier
| _literal
| unary_expression
| update_expression
| binary_expression
| conditional_expression
| assignment_expression
| field_expression
| funcall_expression
| subscript_expression
| _parenthesized_expression
update_expression ::=
( '--' | '++' ) _expression | _expression ( '--' | '++' )
unary_expression ::=
( '-' | '+' | '~' | '!' ) _expression
binary_expression ::=
_expression '+' _expression
| _expression '-' _expression
| _expression '*' _expression
| _expression '/' _expression
| _expression '%' _expression
| _expression '||' _expression
| _expression '&&' _expression
| _expression '|' _expression
| _expression '&' _expression
| _expression '==' _expression
| _expression '!=' _expression
| _expression '>' _expression
| _expression '>=' _expression
| _expression '<=' _expression
| _expression '<' _expression
conditional_expression ::=
_expression '?' _expression? ':' _expression
assignment_expression ::=
( identifier | field_expression ) ( '=' | '+=' | '-=' | '*=' | '/=' | '|=' | '&=' | '&~=' | '%=' | '(-)' | '(+)' | '^=' ) _expression
subscript_expression ::=
_expression '[' _expression ']'
field_expression ::=
_expression ( '.' | '->' ) identifier
funcall_expression ::=
_expression '(' ( _expression ( ',' _expression )* )? ')'
_parenthesized_expression ::=
'(' _expression ')'
_type_modifier ::=
'var'
| 'const'
| 'static'
| 'nosave'
| 'local'
simple_type ::=
'void'
| 'entity'
| 'float'
| 'vector'
| 'string'
| 'int'
| 'integer'
field_ptr_type ::=
'.' simple_type
function_ref_type ::=
simple_type parameter_list
identifier ::=
[a-zA-Z_][a-zA-Z0-9_]*
frame_identifier ::=
'$' [a-zA-Z_][a-zA-Z0-9_.]*
_literal ::=
numeric_literal
| vector_literal
| array_literal
| string_literal
numeric_literal ::=
_integer_literal
| _float_literal
_integer_literal ::=
'-'?[0-9]+'i'?
_float_literal ::=
'-'?([0-9]+)?'.'([0-9]+'f'?)?
vector_literal ::=
"'" numeric_literal numeric_literal numeric_literal "'"
array_literal ::=
'{' _expression ( ',' _expression )* '}'
string_literal ::=
'"' ( [^\"#x0A]+ | _escape_sequence )* [^"]* '"'
_escape_sequence ::=
'\\' ( 'n' | 'r' | '"' | "'" | '\\' | [0-9] )
builtin_literal ::=
'#'[0-9]+(':'[a-zA-Z_][a-zA-Z0-9_]*)?
integer_frame_literal ::=
_integer_literal
comment ::=
( '//' '.'* | '/*' [^*]*'\'*+([^/*][^*]*'\'*+)* '/' )