-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtree-sitter-lua.ebnf
250 lines (187 loc) · 4.75 KB
/
tree-sitter-lua.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
//
// From tree-sitter-lua/src/grammar.json
//
//
// EBNF to generate railroad diagram at
// (IPV6) https://www.bottlecaps.de/rr/ui
// (IPV4) https://rr.red-dove.com/ui
//
chunk ::=
shebang? _block?
shebang ::=
'#!.'*
block ::=
_block
_block ::=
return_statement
| statement+ return_statement?
return_statement ::=
'return' expression_list? empty_statement?
statement ::=
empty_statement
| variable_assignment
| local_variable_declaration
| call
| label_statement
| goto_statement
| break_statement
| do_statement
| while_statement
| repeat_statement
| if_statement
| for_numeric_statement
| for_generic_statement
| function_definition_statement
| local_function_definition_statement
local_function_definition_statement ::=
'local' 'function' identifier _function_body
function_definition_statement ::=
'function' ( identifier | _table_function_variable ) _function_body
_table_function_variable ::=
_table_identifier ( _named_field_identifier | _method_identifier )
_table_identifier ::=
( identifier | _table_field_variable )
_table_field_variable ::=
_table_identifier _named_field_identifier
for_generic_statement ::=
'for' _name_list 'in' _value_list 'do' block? 'end'
_name_list ::=
identifier ( ',' identifier )*
_value_list ::=
expression ( ',' expression )*
for_numeric_statement ::=
'for' identifier '=' expression ',' expression ( ',' expression )? 'do' block? 'end'
if_statement ::=
'if' expression 'then' block? elseif_clause* else_clause? 'end'
elseif_clause ::=
'elseif' expression 'then' block?
else_clause ::=
'else' block?
repeat_statement ::=
'repeat' block? 'until' expression
while_statement ::=
'while' expression 'do' block? 'end'
do_statement ::=
'do' block? 'end'
break_statement ::=
'break'
goto_statement ::=
'goto' identifier
label_statement ::=
'::' identifier '::'
local_variable_declaration ::=
'local' _local_variable_list ( '=' _value_list )?
_local_variable_list ::=
_local_variable ( ',' _local_variable )*
_local_variable ::=
identifier attribute?
attribute ::=
'<' identifier '>'
variable_assignment ::=
variable_list '=' _value_list
variable_list ::=
variable ( ',' variable )*
empty_statement ::=
';'
expression ::=
nil
| false
| true
| number
| string
| vararg_expression
| function_definition
| prefix_expression
| table
| unary_expression
| binary_expression
binary_expression ::=
expression 'or' expression
| expression 'and' 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
unary_expression ::=
'not' expression
| '#' expression
| '-' expression
| '~' expression
table ::=
'{' field_list? '}'
field_list ::=
field ( field_separator field )* field_separator?
field ::=
( ( identifier | '[' expression ']' ) '=' )? expression
field_separator ::=
','
| ';'
prefix ::=
variable
| call
| parenthesized_expression
prefix_expression ::=
prefix
_prefix_expression ::=
prefix
parenthesized_expression ::=
'(' expression ')'
call ::=
( _prefix_expression | _table_method_variable ) argument_list
_table_method_variable ::=
prefix_expression _method_identifier
_method_identifier ::=
':' identifier
argument_list ::=
'(' expression_list? ')'
| table
| string
expression_list ::=
expression ( ',' expression )*
variable ::=
identifier
| _table_variable
_table_variable ::=
( identifier | _table_variable | call | parenthesized_expression ) ( _indexed_field_identifier | _named_field_identifier )
_named_field_identifier ::=
'.' identifier
_indexed_field_identifier ::=
'[' expression ']'
function_definition ::=
'function' _function_body
_function_body ::=
'(' parameter_list? ')' block? 'end'
parameter_list ::=
identifier ( ',' identifier )* ( ',' vararg_expression )?
| vararg_expression
vararg_expression ::=
'...'
string ::=
_string_start _string_content? _string_end
number ::=
( '-'? ( ( [0-9]+ | [0-9]+ '.' [0-9]* | [0-9]* '.' [0-9]+ ) ( ( 'e' | 'E' ) ( '+' | '-' )? [0-9]+ )? | ( '0x' | '0X' ) ( [0-9a-fA-F]+ | [0-9a-fA-F]+ '.' [0-9a-fA-F]* | [0-9a-fA-F]* '.' [0-9a-fA-F]+ ) ( ( 'p' | 'P' ) ( '+' | '-' )? [0-9]+ )? ) )
true ::=
'true'
false ::=
'false'
nil ::=
'nil'
identifier ::=
[a-zA-Z_][0-9a-zA-Z_]*
comment ::=
_comment_start _comment_content? _comment_end