-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtree-sitter-sourcepawn.ebnf
545 lines (407 loc) · 15.5 KB
/
tree-sitter-sourcepawn.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
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
//
// From tree-sitter-sourcepawn/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 ::=
( assertion | function_definition | function_declaration | enum | enum_struct | typedef | typeset | functag | funcenum | methodmap | struct | struct_declaration | global_variable_declaration | old_global_variable_declaration | hardcoded_symbol | alias_declaration | alias_assignment )*
_preproc_expression ::=
preproc_binary_expression
| preproc_unary_expression
| identifier
| _literal
| preproc_parenthesized_expression
| preproc_defined_condition
preproc_parenthesized_expression ::=
'(' _preproc_expression ')'
preproc_unary_expression ::=
( '!' | '~' | '-' | '+' ) _preproc_expression
preproc_binary_expression ::=
_preproc_expression '+' _preproc_expression
| _preproc_expression '-' _preproc_expression
| _preproc_expression '*' _preproc_expression
| _preproc_expression '/' _preproc_expression
| _preproc_expression '%' _preproc_expression
| _preproc_expression '||' _preproc_expression
| _preproc_expression '&&' _preproc_expression
| _preproc_expression '|' _preproc_expression
| _preproc_expression '^' _preproc_expression
| _preproc_expression '&' _preproc_expression
| _preproc_expression '==' _preproc_expression
| _preproc_expression '!=' _preproc_expression
| _preproc_expression '>' _preproc_expression
| _preproc_expression '>=' _preproc_expression
| _preproc_expression '<=' _preproc_expression
| _preproc_expression '<' _preproc_expression
| _preproc_expression '<<' _preproc_expression
| _preproc_expression '>>' _preproc_expression
| _preproc_expression '>>>' _preproc_expression
preproc_include ::=
'#include' ( string_literal | system_lib_string )
preproc_tryinclude ::=
'#tryinclude' ( string_literal | system_lib_string )
preproc_macro ::=
'#define' identifier ( '(' ( macro_param ( ',' macro_param )* )? ')' ) preproc_arg
macro_param ::=
( '%' [0-9] )
preproc_define ::=
'#define' identifier preproc_arg
preproc_undefine ::=
'#undef' identifier
preproc_if ::=
'#if' preproc_arg
preproc_elseif ::=
'#elseif' preproc_arg
preproc_assert ::=
'#assert' preproc_arg
preproc_defined_condition ::=
'defined' identifier
preproc_else ::=
'#else'
preproc_endif ::=
'#endif'
preproc_endinput ::=
'#endinput'
preproc_pragma ::=
'#pragma' preproc_arg
preproc_error ::=
'#error' preproc_arg
preproc_warning ::=
'#warning' preproc_arg
hardcoded_symbol ::=
'using __intrinsics__.Handle' _semicolon
assertion ::=
( 'assert' | 'static_assert' ) call_arguments _semicolon
function_definition ::=
visibility? ( type dimension* ) identifier parameter_declarations block
| visibility? old_type? identifier parameter_declarations _statement
function_declaration ::=
function_declaration_kind ( type dimension? | old_type )? identifier parameter_declarations ( '=' identifier )? _semicolon
function_declaration_kind ::=
'forward'
| 'native'
parameter_declarations ::=
'(' ( ( parameter_declaration | rest_parameter ) ( ',' ( parameter_declaration | rest_parameter ) )* )? ')'
parameter_declaration ::=
variable_storage_class? ( old_type? identifier ( dimension | fixed_dimension )* | '&' identifier | ( '&' old_type ) identifier | type '&' identifier | array_type identifier | type identifier ( dimension | fixed_dimension )* ) ( '=' _expression )?
rest_parameter ::=
( type | old_type ) '...'
alias_operator ::=
( '+' | '++' | '-' | '--' | '*' | '/' | '%' | '||' | '&&' | '|' | '^' | '&' | '==' | '!=' | '>' | '>=' | '<=' | '<' | '<<' | '>>' | '>>>' | '!' | '%' )
alias_declaration ::=
visibility? ( builtin_type | old_builtin_type ':' ) 'operator' alias_operator parameter_declarations _statement
| function_declaration_kind 'operator' alias_operator parameter_declarations _semicolon
alias_assignment ::=
function_declaration_kind? ( builtin_type | old_builtin_type ':' ) 'operator' alias_operator parameter_declarations '=' identifier _semicolon
global_variable_declaration ::=
visibility? variable_storage_class? type variable_declaration ( ',' variable_declaration )* _semicolon
variable_declaration_statement ::=
type dimension+ dynamic_array_declaration ( ',' dynamic_array_declaration )* _semicolon? | visibility? variable_storage_class? type variable_declaration ( ',' variable_declaration )* _semicolon?
variable_storage_class ::=
'const'
visibility ::=
'public'
| 'stock'
| 'static'
| 'public' 'static'
| 'stock' 'static'
| 'static' 'stock'
| 'static' 'public'
variable_declaration ::=
identifier ( dimension | fixed_dimension )* ( '=' _expression )?
dynamic_array_declaration ::=
identifier '=' ( dynamic_array | string_literal )
dynamic_array ::=
'new' ( builtin_type | identifier ) fixed_dimension+
new_expression ::=
'new' identifier call_arguments
old_global_variable_declaration ::=
( ( 'new' | 'decl' ) variable_storage_class? | variable_storage_class | visibility variable_storage_class? ) old_variable_declaration ( ',' old_variable_declaration )* _semicolon
| old_variable_declaration ( ',' old_variable_declaration )* _semicolon
old_variable_declaration_statement ::=
( ( 'new' | 'decl' ) variable_storage_class? | variable_storage_class | visibility variable_storage_class? ) old_variable_declaration ( ',' old_variable_declaration )* _semicolon?
old_variable_declaration ::=
old_type? identifier ( dimension | fixed_dimension )* ( '=' _expression )?
enum ::=
'enum' ( identifier ':'? )? ( '(' ( '=' | '+=' | '-=' | '*=' | '/=' | '|=' | '&=' | '^=' | '~=' | '<<=' | '>>=' ) _expression ')' )? enum_entries _semicolon?
enum_entries ::=
'{' enum_entry ( ',' enum_entry )* ','? '}'
enum_entry ::=
( ( builtin_type | identifier ) ':' )? identifier fixed_dimension? ( '=' _expression )?
enum_struct ::=
'enum' 'struct' identifier '{' ( enum_struct_field | enum_struct_method )* '}'
enum_struct_field ::=
type identifier fixed_dimension? _semicolon
enum_struct_method ::=
( type dimension* ) identifier parameter_declarations block
typedef ::=
'typedef' identifier '=' typedef_expression _semicolon
typeset ::=
'typeset' identifier '{' ( typedef_expression _semicolon? )+ '}' _semicolon?
typedef_expression ::=
'function' ( type ( dimension | fixed_dimension )* ) parameter_declarations
| '(' 'function' ( type ( dimension | fixed_dimension )* ) parameter_declarations ')'
funcenum ::=
'funcenum' identifier '{' funcenum_member ( ',' funcenum_member )* ','? '}' _semicolon?
funcenum_member ::=
old_type? 'public' parameter_declarations
functag ::=
'functag' 'public' old_type identifier parameter_declarations _semicolon?
| 'functag' identifier 'public' parameter_declarations _semicolon?
| 'functag' identifier old_type 'public' parameter_declarations _semicolon?
methodmap ::=
'methodmap' identifier ( '<' identifier | '__nullable__' )? '{' ( methodmap_alias | methodmap_native | methodmap_native_constructor | methodmap_native_destructor | methodmap_method | methodmap_method_constructor | methodmap_method_destructor | methodmap_property )* '}' _semicolon?
methodmap_alias ::=
methodmap_visibility '~'? identifier '(' ')' '=' identifier _semicolon?
methodmap_native ::=
methodmap_visibility 'static'? 'native' ( type dimension* ) identifier parameter_declarations _semicolon?
methodmap_native_constructor ::=
methodmap_visibility 'static'? 'native' identifier parameter_declarations _semicolon?
methodmap_native_destructor ::=
methodmap_visibility 'native' '~' identifier '(' ')' _semicolon?
methodmap_method ::=
methodmap_visibility 'static'? ( type dimension* ) identifier parameter_declarations block
methodmap_method_constructor ::=
methodmap_visibility identifier parameter_declarations block
methodmap_method_destructor ::=
methodmap_visibility '~' identifier '(' ')' block
methodmap_property ::=
'property' type identifier '{' ( methodmap_property_alias | methodmap_property_native | methodmap_property_method )+ '}'
methodmap_property_alias ::=
methodmap_visibility methodmap_property_getter '=' identifier _semicolon?
methodmap_property_native ::=
methodmap_visibility 'native' ( methodmap_property_getter | methodmap_property_setter ) _semicolon?
methodmap_property_method ::=
methodmap_visibility ( methodmap_property_getter | methodmap_property_setter ) block
methodmap_property_getter ::=
'get' '(' ')'
methodmap_property_setter ::=
'set' '(' variable_storage_class? type identifier ')'
methodmap_visibility ::=
'public'
struct ::=
'struct' identifier '{' struct_field* '}' _semicolon?
struct_field ::=
'public' 'const'? ( type ( dimension | fixed_dimension )* ) identifier _semicolon?
struct_declaration ::=
'public' ( identifier | identifier ':' ) identifier '=' struct_constructor _semicolon?
struct_constructor ::=
'{' ( struct_field_value ( ',' struct_field_value )* )? ','? '}'
struct_field_value ::=
identifier '=' _expression
type ::=
builtin_type
| identifier
| any_type
array_type ::=
type ( dimension | fixed_dimension )+
old_type ::=
( old_builtin_type | identifier | any_type ) ':'
dimension ::=
'[' ']'
fixed_dimension ::=
'[' _expression ']'
builtin_type ::=
'void'
| 'bool'
| 'int'
| 'float'
| 'char'
old_builtin_type ::=
'_'
| 'Float'
| 'bool'
| 'String'
any_type ::=
'any'
block ::=
'{' _statement* '}'
_statement ::=
block
| variable_declaration_statement
| old_variable_declaration_statement
| for_statement
| while_statement
| do_while_statement
| break_statement
| continue_statement
| condition_statement
| switch_statement
| return_statement
| delete_statement
| expression_statement
for_statement ::=
'for' '(' ( variable_declaration_statement | old_variable_declaration_statement | assignment_expression ( ',' assignment_expression )* )? _manual_semicolon _expression? _manual_semicolon ( _expression | comma_expression )? ')' _statement
while_statement ::=
'while' '(' _expression ')' _statement
do_while_statement ::=
'do' _statement 'while' '(' _expression ')' _semicolon?
break_statement ::=
'break' _semicolon?
continue_statement ::=
'continue' _semicolon?
condition_statement ::=
'if' '(' _expression ')' _statement ( 'else' _statement )?
switch_statement ::=
'switch' '(' _expression ')' '{' switch_case* '}'
switch_case ::=
( 'case' ( _case_expression ( ',' _case_expression )* ) ':' | 'default' ':' ) _statement
switch_default_case ::=
'default' ':' _statement break_statement?
expression_statement ::=
( _expression | comma_expression ) _semicolon?
return_statement ::=
'return' ( _expression | comma_expression )? _semicolon?
delete_statement ::=
'delete' _expression _semicolon?
_manual_semicolon ::=
';'
_semicolon ::=
_automatic_semicolon
| _manual_semicolon
_expression ::=
assignment_expression
| call_expression
| array_indexed_access
| ternary_expression
| field_access
| scope_access
| binary_expression
| unary_expression
| update_expression
| sizeof_expression
| view_as
| old_type_cast
| identifier
| _literal
| parenthesized_expression
| this
| new_expression
_case_expression ::=
scope_access
| case_binary_expression
| case_unary_expression
| sizeof_expression
| view_as
| identifier
| _literal
| parenthesized_expression
| new_expression
assignment_expression ::=
( array_indexed_access | view_as | field_access | scope_access | identifier | this ) ( '=' | '+=' | '-=' | '*=' | '/=' | '|=' | '&=' | '^=' | '~=' | '<<=' | '>>=' | '>>>=' | '%=' ) ( _expression | dynamic_array )
call_expression ::=
( identifier | field_access ) call_arguments
call_arguments ::=
'(' ( ( '&' identifier | _expression | named_arg | ignore_argument ) ( ',' ( '&' identifier | _expression | named_arg | ignore_argument ) )* )? ')'
named_arg ::=
'.' identifier '=' ( '&' identifier | _expression )
ignore_argument ::=
'_'
array_indexed_access ::=
( identifier | array_indexed_access | field_access ) '[' _expression ']'
parenthesized_expression ::=
'(' ( _expression | comma_expression ) ')'
comma_expression ::=
_expression ',' ( _expression | comma_expression )
ternary_expression ::=
_expression '?' _expression _ternary_colon _expression
field_access ::=
_expression '.' identifier
scope_access ::=
identifier '::' identifier
unary_expression ::=
( '!' | '~' | '-' | '+' ) _expression
case_unary_expression ::=
( '!' | '~' | '-' | '+' ) _case_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
| _expression '<' _expression
| _expression '<<' _expression
| _expression '>>' _expression
| _expression '>>>' _expression
case_binary_expression ::=
_case_expression '+' _case_expression
| _case_expression '-' _case_expression
| _case_expression '*' _case_expression
| _case_expression '/' _case_expression
| _case_expression '%' _case_expression
| _case_expression '||' _case_expression
| _case_expression '&&' _case_expression
| _case_expression '|' _case_expression
| _case_expression '^' _case_expression
| _case_expression '&' _case_expression
| _case_expression '==' _case_expression
| _case_expression '!=' _case_expression
| _case_expression '>' _case_expression
| _case_expression '>=' _case_expression
| _case_expression '<=' _case_expression
| _case_expression '<' _case_expression
| _case_expression '<<' _case_expression
| _case_expression '>>' _case_expression
| _case_expression '>>>' _case_expression
update_expression ::=
( '--' | '++' ) _expression | _expression ( '--' | '++' )
_sizeof_call_expression ::=
call_expression | identifier dimension* | array_indexed_access dimension* | field_access | scope_access | _literal | parenthesized_expression | this | array_scope_access
array_scope_access ::=
identifier dimension+ '.' identifier
sizeof_expression ::=
'sizeof' ( '(' _sizeof_call_expression ')' | _sizeof_call_expression )
view_as ::=
'view_as' '<' type '>' '(' _expression ')'
old_type_cast ::=
old_type _expression
array_literal ::=
'{' ( _literal | identifier | view_as | old_type_cast | unary_expression | binary_expression ) ( ',' ( _literal | identifier | view_as | old_type_cast | unary_expression | binary_expression ) )* ( ',' rest_operator? )? '}'
_literal ::=
int_literal
| float_literal
| char_literal
| string_literal
| concatenated_string
| bool_literal
| array_literal
| null
int_literal ::=
( ( [0-9]+ ( "'" [0-9]+ )* | '0b' [0-9]+ ( "'" [0-9]+ )* | '0x' [0-9a-fA-F]+ ( "'" [0-9a-fA-F]+ )* | '0o' [o0-7]+ ( "'" [o0-7]+ )* ) ( [eEpP] ( [-\+]? [0-9a-fA-F]+ ( "'" [0-9a-fA-F]+ )* )? )? )
float_literal ::=
( ( [0-9]+ ( "'" [0-9]+ )* ( '.' ( [0-9]+ ( "'" [0-9]+ )* )? )? | '.' [0-9]+ ( "'" [0-9]+ )* ) )
char_literal ::=
"'" ( escape_sequence | [^#x0A'] ) "'"
concatenated_string ::=
( string_literal | identifier ) '...' ( string_literal | identifier | concatenated_string )
string_literal ::=
'"' ( [^"\]|'\#x0D'?'#x0A' | escape_sequence )* '"'
escape_sequence ::=
'\\' ( (?':'[abefnrt'\"\]|(?":x"[a-zA-Z0-9]"{0,2}"|[0-9]+)";"?) )
bool_literal ::=
( 'true' | 'false' )
null ::=
'null'
this ::=
'this'
rest_operator ::=
'...'
system_lib_string ::=
( '<' ( [^>] | '\>' )* '>' )
identifier ::=
[a-zA-Z_][a-zA-Z_]*
comment ::=
( '//' '.'* | '/*' [^*]*'\'*+([^/*][^*]*'\'*+)* '/' )