-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhaxe.ebnf
244 lines (191 loc) · 4.66 KB
/
haxe.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
/*
The begning of a HAXE grammar
*/
program ::= stmt*
stmt ::=
var_decl
| 'using' access_field
| 'import' access_field ('.*')? (('in' | 'as') ID)?
| class_decl
| interface_decl
| enum_decl
| function_decl ';'
| structure_type
| abstract_decl
| '@' ':'? anotation_id ('(' expr ')')?
| '#' ('if' expr | 'else' | 'elseif' expr | 'end')
class_decl ::= 'extern'? 'final'? 'class' ID type_paramter? extends* implements* '{' class_members '}'
interface_decl ::= 'final'? 'interface' ID extends* '{' interface_members '}'
enum_decl ::= 'enum' ID type_paramter? '{' enum_item_list '}'
type_paramter ::= '<' one_type_param (',' one_type_param)* '>'
one_type_param ::= ID (':' type)?
type ::=
Void
| Bool
| Float
| Int
| Dynamic
| ID type_paramter?
anotation_id ::=
'access'
| 'allow'
| 'arrayAccess'
| 'author'
| 'broken'
| 'coreType'
| 'enum'
| 'forward'
| 'from'
| 'generic'
| 'keep'
| 'native'
| 'notNull'
| 'noUsing'
| 'op'
| 'range'
| 'to'
| 'using'
var_decl ::= ('var' | 'final') ID (':' type)? '=' expr
extends ::= 'extends' ID
implements ::= 'implements' ID
class_members ::=
('var' | 'final') ID ('(' ID ',' ID ')')? (':' type)? '=' expr
| function_decl
interface_members ::=
function_decl
enum_item_list ::= enum_item+
enum_item ::= ID ';'
function_def ::= function_decl block_stmt
function_decl ::= 'static'? 'inline'? ('public' | 'private')? ('override' | 'final')? 'dynamic'? 'extern'? function_id_decl
function_id_decl ::= 'function' ID type_paramter? '(' param_decl_list? ')' (':' type)?
lambda_decl ::= 'function' '(' param_decl_list? ')' (':' type)?
param_decl_list ::= param_decl (',' param_decl)*
param_decl ::= '?'? ID ':' type ('=' literal_expr)?
structure_type ::= 'typedef' ID type_paramter? '=' struct_type_def
struct_type_def ::=
'{' ('>' ID ',')? structure_type_member_list '}'
| ID '&' '{' structure_type_member_list '}'
| ID type_paramter
| function_id_decl
structure_type_member_list ::= structure_type_member (',' structure_type_member)*
structure_type_member ::= ('var' | 'final') '?'? ID ':' type
abstract_decl ::= 'enum'? 'abstract' ID '(' type ')' ('from' type 'to' type)? '{' stmt '}'
block_stmt ::=
var_decl
| if_stmt
| switch_stmt
| 'return' expr
| for_stmt
| while_stmt
| do_while_stmt
| debug_stmt
| throw_stmt
| try_catch_stmt
| 'break'
| 'continue'
if_stmt ::= 'if' '(' expr ')' block_stmt ('else' block_stmt)?
while_stmt ::= 'while' '(' expr ')' block_stmt
do_while_stmt ::= 'do' block_stmt 'while' '(' expr ')'
for_stmt ::= 'for' '(' ID ('=>' ID)? 'in' (range_def | ID) ')' block_stmt
range_def ::= expr '...' expr
throw_stmt ::= 'throw' expr
try_catch_stmt ::= 'try' block_stmt catch_clause+
catch_clause ::= 'catch' '(' ID (':' type)? ')' block_stmt
switch_stmt ::= 'switch' '(' expr ')' switch_body switch_default?
switch_body ::=
'case' (literal_expr ('|' literal_expr)* | ID | ('{' structure_type_member (',' structure_type_member)* '}') | ('[' (literal_expr | '_') (',' (literal_expr | '_'))* ']') | '_') ('if' expr)? ':' block_stmt*
switch_default ::= 'default' block_stmt
debug_stmt ::= '$' function_call
literal_expr ::=
BOOLEAN
| INTEGER
| FLOAT
| STRING
expr ::=
ID
| 'null'
| 'new' ID
| literal_expr
| function_call
| 'new' type
| anonymous_struct
| literal_array
| access_field
| expr op_binary expr
| lambda_decl
| 'cast' (expr | '(' expr ',' type ')')
| '(' expr ':' type ')' // compile time type check
| 'inline' expr
| '[' (for_stmt | while_stmt) ']'
| switch_stmt
op_binary ::=
'='
| '||' //Logical or
| '&&' //Logical and
| '>=' //Comparison and equality
| '>'
| '<'
| '<='
| '=='
| '!='
| '&' | '|' | '^' //Bitwise and, or, xor
| '<<' | '>>' //Bitwise shifts
| '+' | '-' //Plus, minus
| '%' | '*' | '/' //Modulo, multiply, divide
function_call ::= ID '(' param_list? ')'
param_list ::= param (',' param)*
param ::= expr
anonymous_struct ::= '{' anonymous_struct_member_list '}'
anonymous_struct_member_list ::= anonymous_struct_member (',' anonymous_struct_member)*
anonymous_struct_member ::=
(ID | STRING) ':' expr
| '?'? ID ':' type
literal_array ::= '[' expr_list? ']'
expr_list ::= expr (',' expr)*
access_field ::= ID ('.' ID)+
keywords ::=
'abstract'
| 'break'
| 'case'
| 'cast'
| 'catch'
| 'class'
| 'continue'
| 'default'
| 'do'
| 'dynamic'
| 'else'
| 'enum'
| 'extends'
| 'extern'
| 'false'
| 'final'
| 'for'
| 'function'
| 'if'
| 'implements'
| 'import'
| 'in'
| 'inline'
| 'interface'
| 'macro'
| 'new'
| 'null'
| 'operator'
| 'overload'
| 'override'
| 'package'
| 'private'
| 'public'
| 'return'
| 'static'
| 'switch'
| 'this'
| 'throw'
| 'true'
| 'try'
| 'typedef'
| 'untyped'
| 'using'
| 'var'
| 'while'