aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2023-01-19 15:29:34 +0800
committerLi Jin <dragon-fly@qq.com>2023-01-19 15:29:34 +0800
commitee9f984341a3e5b52ae97573d97e20cde57ada94 (patch)
treec206d779381c39447a763d90590765fede7da5f0
parent3adc0c485a9e514f26c6eb799d21ebcd7560c38e (diff)
downloadyuescript-ee9f984341a3e5b52ae97573d97e20cde57ada94.tar.gz
yuescript-ee9f984341a3e5b52ae97573d97e20cde57ada94.tar.bz2
yuescript-ee9f984341a3e5b52ae97573d97e20cde57ada94.zip
make syntax rule names consistent.
-rw-r--r--src/yuescript/yue_ast.h402
-rw-r--r--src/yuescript/yue_compiler.cpp504
-rw-r--r--src/yuescript/yue_parser.cpp684
-rw-r--r--src/yuescript/yue_parser.h220
4 files changed, 924 insertions, 886 deletions
diff --git a/src/yuescript/yue_ast.h b/src/yuescript/yue_ast.h
index 076d5f4..9101b2f 100644
--- a/src/yuescript/yue_ast.h
+++ b/src/yuescript/yue_ast.h
@@ -60,37 +60,37 @@ AST_NODE(LuaKeyword)
60 AST_MEMBER(LuaKeyword, &name) 60 AST_MEMBER(LuaKeyword, &name)
61AST_END(LuaKeyword, "lua_keyword"sv) 61AST_END(LuaKeyword, "lua_keyword"sv)
62 62
63AST_LEAF(self) 63AST_LEAF(Self)
64AST_END(self, "self"sv) 64AST_END(Self, "self"sv)
65 65
66AST_NODE(self_name) 66AST_NODE(SelfName)
67 ast_ptr<true, Name_t> name; 67 ast_ptr<true, Name_t> name;
68 AST_MEMBER(self_name, &name) 68 AST_MEMBER(SelfName, &name)
69AST_END(self_name, "self_name"sv) 69AST_END(SelfName, "self_name"sv)
70 70
71AST_LEAF(self_class) 71AST_LEAF(SelfClass)
72AST_END(self_class, "self_name"sv) 72AST_END(SelfClass, "self_class"sv)
73 73
74AST_NODE(self_class_name) 74AST_NODE(SelfClassName)
75 ast_ptr<true, Name_t> name; 75 ast_ptr<true, Name_t> name;
76 AST_MEMBER(self_class_name, &name) 76 AST_MEMBER(SelfClassName, &name)
77AST_END(self_class_name, "self_class_name"sv) 77AST_END(SelfClassName, "self_class_name"sv)
78 78
79AST_NODE(SelfName) 79AST_NODE(SelfItem)
80 ast_sel<true, self_class_name_t, self_class_t, self_name_t, self_t> name; 80 ast_sel<true, SelfClassName_t, SelfClass_t, SelfName_t, Self_t> name;
81 AST_MEMBER(SelfName, &name) 81 AST_MEMBER(SelfItem, &name)
82AST_END(SelfName, "self_item"sv) 82AST_END(SelfItem, "self_item"sv)
83 83
84AST_NODE(KeyName) 84AST_NODE(KeyName)
85 ast_sel<true, SelfName_t, Name_t> name; 85 ast_sel<true, SelfItem_t, Name_t> name;
86 AST_MEMBER(KeyName, &name) 86 AST_MEMBER(KeyName, &name)
87AST_END(KeyName, "key_name"sv) 87AST_END(KeyName, "key_name"sv)
88 88
89AST_LEAF(VarArg) 89AST_LEAF(VarArg)
90AST_END(VarArg, "var_arg"sv) 90AST_END(VarArg, "var_arg"sv)
91 91
92AST_LEAF(local_flag) 92AST_LEAF(LocalFlag)
93AST_END(local_flag, "local_flag"sv) 93AST_END(LocalFlag, "local_flag"sv)
94 94
95AST_LEAF(Seperator) 95AST_LEAF(Seperator)
96AST_END(Seperator, "seperator"sv) 96AST_END(Seperator, "seperator"sv)
@@ -105,14 +105,14 @@ class ExpListLow_t;
105class TableBlock_t; 105class TableBlock_t;
106class Attrib_t; 106class Attrib_t;
107 107
108AST_NODE(local_values) 108AST_NODE(LocalValues)
109 ast_ptr<true, NameList_t> nameList; 109 ast_ptr<true, NameList_t> nameList;
110 ast_sel<false, TableBlock_t, ExpListLow_t> valueList; 110 ast_sel<false, TableBlock_t, ExpListLow_t> valueList;
111 AST_MEMBER(local_values, &nameList, &valueList) 111 AST_MEMBER(LocalValues, &nameList, &valueList)
112AST_END(local_values, "local_values"sv) 112AST_END(LocalValues, "local_values"sv)
113 113
114AST_NODE(Local) 114AST_NODE(Local)
115 ast_sel<true, local_flag_t, local_values_t> item; 115 ast_sel<true, LocalFlag_t, LocalValues_t> item;
116 std::list<std::string> forceDecls; 116 std::list<std::string> forceDecls;
117 std::list<std::string> decls; 117 std::list<std::string> decls;
118 bool collected = false; 118 bool collected = false;
@@ -120,35 +120,35 @@ AST_NODE(Local)
120 AST_MEMBER(Local, &item) 120 AST_MEMBER(Local, &item)
121AST_END(Local, "local"sv) 121AST_END(Local, "local"sv)
122 122
123AST_LEAF(const_attrib) 123AST_LEAF(ConstAttrib)
124AST_END(const_attrib, "const"sv) 124AST_END(ConstAttrib, "const"sv)
125 125
126AST_LEAF(close_attrib) 126AST_LEAF(CloseAttrib)
127AST_END(close_attrib, "close"sv) 127AST_END(CloseAttrib, "close"sv)
128 128
129class simple_table_t; 129class SimpleTable_t;
130class TableLit_t; 130class TableLit_t;
131class Assign_t; 131class Assign_t;
132 132
133AST_NODE(LocalAttrib) 133AST_NODE(LocalAttrib)
134 ast_sel<true, const_attrib_t, close_attrib_t> attrib; 134 ast_sel<true, ConstAttrib_t, CloseAttrib_t> attrib;
135 ast_ptr<true, Seperator_t> sep; 135 ast_ptr<true, Seperator_t> sep;
136 ast_sel_list<true, Variable_t, simple_table_t, TableLit_t> leftList; 136 ast_sel_list<true, Variable_t, SimpleTable_t, TableLit_t> leftList;
137 ast_ptr<true, Assign_t> assign; 137 ast_ptr<true, Assign_t> assign;
138 AST_MEMBER(LocalAttrib, &attrib, &sep, &leftList, &assign) 138 AST_MEMBER(LocalAttrib, &attrib, &sep, &leftList, &assign)
139AST_END(LocalAttrib, "local_attrib"sv) 139AST_END(LocalAttrib, "local_attrib"sv)
140 140
141AST_NODE(colon_import_name) 141AST_NODE(ColonImportName)
142 ast_ptr<true, Variable_t> name; 142 ast_ptr<true, Variable_t> name;
143 AST_MEMBER(colon_import_name, &name) 143 AST_MEMBER(ColonImportName, &name)
144AST_END(colon_import_name, "colon_import_name"sv) 144AST_END(ColonImportName, "colon_import_name"sv)
145 145
146AST_LEAF(import_literal_inner) 146AST_LEAF(ImportLiteralInner)
147AST_END(import_literal_inner, "import_literal_inner"sv) 147AST_END(ImportLiteralInner, "import_literal_inner"sv)
148 148
149AST_NODE(ImportLiteral) 149AST_NODE(ImportLiteral)
150 ast_ptr<true, Seperator_t> sep; 150 ast_ptr<true, Seperator_t> sep;
151 ast_sel_list<true, import_literal_inner_t> inners; 151 ast_sel_list<true, ImportLiteralInner_t> inners;
152 AST_MEMBER(ImportLiteral, &sep, &inners) 152 AST_MEMBER(ImportLiteral, &sep, &inners)
153AST_END(ImportLiteral, "import_literal"sv) 153AST_END(ImportLiteral, "import_literal"sv)
154 154
@@ -156,36 +156,36 @@ class Exp_t;
156 156
157AST_NODE(ImportFrom) 157AST_NODE(ImportFrom)
158 ast_ptr<true, Seperator_t> sep; 158 ast_ptr<true, Seperator_t> sep;
159 ast_sel_list<true, colon_import_name_t, Variable_t> names; 159 ast_sel_list<true, ColonImportName_t, Variable_t> names;
160 ast_ptr<true, Exp_t> exp; 160 ast_ptr<true, Exp_t> exp;
161 AST_MEMBER(ImportFrom, &sep, &names, &exp) 161 AST_MEMBER(ImportFrom, &sep, &names, &exp)
162AST_END(ImportFrom, "import_from"sv) 162AST_END(ImportFrom, "import_from"sv)
163 163
164class MacroName_t; 164class MacroName_t;
165 165
166AST_NODE(macro_name_pair) 166AST_NODE(MacroNamePair)
167 ast_ptr<true, MacroName_t> key; 167 ast_ptr<true, MacroName_t> key;
168 ast_ptr<true, MacroName_t> value; 168 ast_ptr<true, MacroName_t> value;
169 AST_MEMBER(macro_name_pair, &key, &value) 169 AST_MEMBER(MacroNamePair, &key, &value)
170AST_END(macro_name_pair, "macro_name_pair"sv) 170AST_END(MacroNamePair, "macro_name_pair"sv)
171 171
172AST_LEAF(import_all_macro) 172AST_LEAF(ImportAllMacro)
173AST_END(import_all_macro, "import_all_macro"sv) 173AST_END(ImportAllMacro, "import_all_macro"sv)
174 174
175class variable_pair_t; 175class VariablePair_t;
176class normal_pair_t; 176class NormalPair_t;
177class meta_variable_pair_t; 177class MetaVariablePair_t;
178class meta_normal_pair_t; 178class MetaNormalPair_t;
179 179
180AST_NODE(ImportTabLit) 180AST_NODE(ImportTabLit)
181 ast_ptr<true, Seperator_t> sep; 181 ast_ptr<true, Seperator_t> sep;
182 ast_sel_list<false, variable_pair_t, normal_pair_t, MacroName_t, macro_name_pair_t, import_all_macro_t, Exp_t, meta_variable_pair_t, meta_normal_pair_t> items; 182 ast_sel_list<false, VariablePair_t, NormalPair_t, MacroName_t, MacroNamePair_t, ImportAllMacro_t, Exp_t, MetaVariablePair_t, MetaNormalPair_t> items;
183 AST_MEMBER(ImportTabLit, &sep, &items) 183 AST_MEMBER(ImportTabLit, &sep, &items)
184AST_END(ImportTabLit, "import_tab_lit"sv) 184AST_END(ImportTabLit, "import_tab_lit"sv)
185 185
186AST_NODE(ImportAs) 186AST_NODE(ImportAs)
187 ast_ptr<true, ImportLiteral_t> literal; 187 ast_ptr<true, ImportLiteral_t> literal;
188 ast_sel<false, Variable_t, ImportTabLit_t, import_all_macro_t> target; 188 ast_sel<false, Variable_t, ImportTabLit_t, ImportAllMacro_t> target;
189 AST_MEMBER(ImportAs, &literal, &target) 189 AST_MEMBER(ImportAs, &literal, &target)
190AST_END(ImportAs, "import_as"sv) 190AST_END(ImportAs, "import_as"sv)
191 191
@@ -211,14 +211,14 @@ AST_END(ShortTabAppending, "short_table_appending"sv)
211 211
212class FnArgsDef_t; 212class FnArgsDef_t;
213 213
214AST_LEAF(fn_arrow_back) 214AST_LEAF(FnArrowBack)
215AST_END(fn_arrow_back, "fn_arrow_back"sv) 215AST_END(FnArrowBack, "fn_arrow_back"sv)
216 216
217class ChainValue_t; 217class ChainValue_t;
218 218
219AST_NODE(Backcall) 219AST_NODE(Backcall)
220 ast_ptr<false, FnArgsDef_t> argsDef; 220 ast_ptr<false, FnArgsDef_t> argsDef;
221 ast_ptr<true, fn_arrow_back_t> arrow; 221 ast_ptr<true, FnArrowBack_t> arrow;
222 ast_ptr<true, ChainValue_t> value; 222 ast_ptr<true, ChainValue_t> value;
223 AST_MEMBER(Backcall, &argsDef, &arrow, &value) 223 AST_MEMBER(Backcall, &argsDef, &arrow, &value)
224AST_END(Backcall, "backcall"sv) 224AST_END(Backcall, "backcall"sv)
@@ -243,13 +243,13 @@ AST_NODE(Return)
243 AST_MEMBER(Return, &valueList) 243 AST_MEMBER(Return, &valueList)
244AST_END(Return, "return"sv) 244AST_END(Return, "return"sv)
245 245
246class existential_op_t; 246class ExistentialOp_t;
247class Assign_t; 247class Assign_t;
248class Block_t; 248class Block_t;
249class Statement_t; 249class Statement_t;
250 250
251AST_NODE(With) 251AST_NODE(With)
252 ast_ptr<false, existential_op_t> eop; 252 ast_ptr<false, ExistentialOp_t> eop;
253 ast_ptr<true, ExpList_t> valueList; 253 ast_ptr<true, ExpList_t> valueList;
254 ast_ptr<false, Assign_t> assigns; 254 ast_ptr<false, Assign_t> assigns;
255 ast_sel<true, Block_t, Statement_t> body; 255 ast_sel<true, Block_t, Statement_t> body;
@@ -276,14 +276,14 @@ AST_NODE(Switch)
276 AST_MEMBER(Switch, &target, &sep, &branches, &lastBranch) 276 AST_MEMBER(Switch, &target, &sep, &branches, &lastBranch)
277AST_END(Switch, "switch"sv) 277AST_END(Switch, "switch"sv)
278 278
279AST_NODE(assignment) 279AST_NODE(Assignment)
280 ast_ptr<true, ExpList_t> expList; 280 ast_ptr<true, ExpList_t> expList;
281 ast_ptr<true, Assign_t> assign; 281 ast_ptr<true, Assign_t> assign;
282 AST_MEMBER(assignment, &expList, &assign) 282 AST_MEMBER(Assignment, &expList, &assign)
283AST_END(assignment, "assignment"sv) 283AST_END(Assignment, "assignment"sv)
284 284
285AST_NODE(IfCond) 285AST_NODE(IfCond)
286 ast_sel<true, Exp_t, assignment_t> condition; 286 ast_sel<true, Exp_t, Assignment_t> condition;
287 AST_MEMBER(IfCond, &condition) 287 AST_MEMBER(IfCond, &condition)
288AST_END(IfCond, "if_cond"sv) 288AST_END(IfCond, "if_cond"sv)
289 289
@@ -314,26 +314,26 @@ AST_NODE(Repeat)
314 AST_MEMBER(Repeat, &body, &condition) 314 AST_MEMBER(Repeat, &body, &condition)
315AST_END(Repeat, "repeat"sv) 315AST_END(Repeat, "repeat"sv)
316 316
317AST_NODE(for_step_value) 317AST_NODE(ForStepValue)
318 ast_ptr<true, Exp_t> value; 318 ast_ptr<true, Exp_t> value;
319 AST_MEMBER(for_step_value, &value) 319 AST_MEMBER(ForStepValue, &value)
320AST_END(for_step_value, "for_step_value"sv) 320AST_END(ForStepValue, "for_step_value"sv)
321 321
322AST_NODE(For) 322AST_NODE(For)
323 ast_ptr<true, Variable_t> varName; 323 ast_ptr<true, Variable_t> varName;
324 ast_ptr<true, Exp_t> startValue; 324 ast_ptr<true, Exp_t> startValue;
325 ast_ptr<true, Exp_t> stopValue; 325 ast_ptr<true, Exp_t> stopValue;
326 ast_ptr<false, for_step_value_t> stepValue; 326 ast_ptr<false, ForStepValue_t> stepValue;
327 ast_sel<true, Block_t, Statement_t> body; 327 ast_sel<true, Block_t, Statement_t> body;
328 AST_MEMBER(For, &varName, &startValue, &stopValue, &stepValue, &body) 328 AST_MEMBER(For, &varName, &startValue, &stopValue, &stepValue, &body)
329AST_END(For, "for"sv) 329AST_END(For, "for"sv)
330 330
331class AssignableNameList_t; 331class AssignableNameList_t;
332class star_exp_t; 332class StarExp_t;
333 333
334AST_NODE(ForEach) 334AST_NODE(ForEach)
335 ast_ptr<true, AssignableNameList_t> nameList; 335 ast_ptr<true, AssignableNameList_t> nameList;
336 ast_sel<true, star_exp_t, ExpList_t> loopValue; 336 ast_sel<true, StarExp_t, ExpList_t> loopValue;
337 ast_sel<true, Block_t, Statement_t> body; 337 ast_sel<true, Block_t, Statement_t> body;
338 AST_MEMBER(ForEach, &nameList, &loopValue, &body) 338 AST_MEMBER(ForEach, &nameList, &loopValue, &body)
339AST_END(ForEach, "for_each"sv) 339AST_END(ForEach, "for_each"sv)
@@ -343,15 +343,15 @@ AST_NODE(Do)
343 AST_MEMBER(Do, &body) 343 AST_MEMBER(Do, &body)
344AST_END(Do, "do"sv) 344AST_END(Do, "do"sv)
345 345
346AST_NODE(catch_block) 346AST_NODE(CatchBlock)
347 ast_ptr<true, Variable_t> err; 347 ast_ptr<true, Variable_t> err;
348 ast_ptr<true, Block_t> body; 348 ast_ptr<true, Block_t> body;
349 AST_MEMBER(catch_block, &err, &body) 349 AST_MEMBER(CatchBlock, &err, &body)
350AST_END(catch_block, "catch_block"sv) 350AST_END(CatchBlock, "catch_block"sv)
351 351
352AST_NODE(Try) 352AST_NODE(Try)
353 ast_sel<true, Block_t, Exp_t> func; 353 ast_sel<true, Block_t, Exp_t> func;
354 ast_ptr<false, catch_block_t> catchBlock; 354 ast_ptr<false, CatchBlock_t> catchBlock;
355 AST_MEMBER(Try, &func, &catchBlock) 355 AST_MEMBER(Try, &func, &catchBlock)
356AST_END(Try, "try"sv) 356AST_END(Try, "try"sv)
357 357
@@ -363,26 +363,26 @@ AST_NODE(Comprehension)
363 AST_MEMBER(Comprehension, &value, &forLoop) 363 AST_MEMBER(Comprehension, &value, &forLoop)
364AST_END(Comprehension, "comp"sv) 364AST_END(Comprehension, "comp"sv)
365 365
366AST_NODE(comp_value) 366AST_NODE(CompValue)
367 ast_ptr<true, Exp_t> value; 367 ast_ptr<true, Exp_t> value;
368 AST_MEMBER(comp_value, &value) 368 AST_MEMBER(CompValue, &value)
369AST_END(comp_value, "comp_value"sv) 369AST_END(CompValue, "comp_value"sv)
370 370
371AST_NODE(TblComprehension) 371AST_NODE(TblComprehension)
372 ast_ptr<true, Exp_t> key; 372 ast_ptr<true, Exp_t> key;
373 ast_ptr<false, comp_value_t> value; 373 ast_ptr<false, CompValue_t> value;
374 ast_ptr<true, CompInner_t> forLoop; 374 ast_ptr<true, CompInner_t> forLoop;
375 AST_MEMBER(TblComprehension, &key, &value, &forLoop) 375 AST_MEMBER(TblComprehension, &key, &value, &forLoop)
376AST_END(TblComprehension, "tbl_comp"sv) 376AST_END(TblComprehension, "tbl_comp"sv)
377 377
378AST_NODE(star_exp) 378AST_NODE(StarExp)
379 ast_ptr<true, Exp_t> value; 379 ast_ptr<true, Exp_t> value;
380 AST_MEMBER(star_exp, &value) 380 AST_MEMBER(StarExp, &value)
381AST_END(star_exp, "star_exp"sv) 381AST_END(StarExp, "star_exp"sv)
382 382
383AST_NODE(CompForEach) 383AST_NODE(CompForEach)
384 ast_ptr<true, AssignableNameList_t> nameList; 384 ast_ptr<true, AssignableNameList_t> nameList;
385 ast_sel<true, star_exp_t, Exp_t> loopValue; 385 ast_sel<true, StarExp_t, Exp_t> loopValue;
386 AST_MEMBER(CompForEach, &nameList, &loopValue) 386 AST_MEMBER(CompForEach, &nameList, &loopValue)
387AST_END(CompForEach, "comp_for_each"sv) 387AST_END(CompForEach, "comp_for_each"sv)
388 388
@@ -390,7 +390,7 @@ AST_NODE(CompFor)
390 ast_ptr<true, Variable_t> varName; 390 ast_ptr<true, Variable_t> varName;
391 ast_ptr<true, Exp_t> startValue; 391 ast_ptr<true, Exp_t> startValue;
392 ast_ptr<true, Exp_t> stopValue; 392 ast_ptr<true, Exp_t> stopValue;
393 ast_ptr<false, for_step_value_t> stepValue; 393 ast_ptr<false, ForStepValue_t> stepValue;
394 AST_MEMBER(CompFor, &varName, &startValue, &stopValue, &stepValue) 394 AST_MEMBER(CompFor, &varName, &startValue, &stopValue, &stepValue)
395AST_END(CompFor, "comp_for"sv) 395AST_END(CompFor, "comp_for"sv)
396 396
@@ -408,11 +408,11 @@ AST_NODE(Assign)
408 AST_MEMBER(Assign, &sep, &values) 408 AST_MEMBER(Assign, &sep, &values)
409AST_END(Assign, "assign"sv) 409AST_END(Assign, "assign"sv)
410 410
411AST_LEAF(update_op) 411AST_LEAF(UpdateOp)
412AST_END(update_op, "update_op"sv) 412AST_END(UpdateOp, "update_op"sv)
413 413
414AST_NODE(Update) 414AST_NODE(Update)
415 ast_ptr<true, update_op_t> op; 415 ast_ptr<true, UpdateOp_t> op;
416 ast_ptr<true, Exp_t> value; 416 ast_ptr<true, Exp_t> value;
417 AST_MEMBER(Update, &op, &value) 417 AST_MEMBER(Update, &op, &value)
418AST_END(Update, "update"sv) 418AST_END(Update, "update"sv)
@@ -420,28 +420,28 @@ AST_END(Update, "update"sv)
420AST_LEAF(BinaryOperator) 420AST_LEAF(BinaryOperator)
421AST_END(BinaryOperator, "binary_op"sv) 421AST_END(BinaryOperator, "binary_op"sv)
422 422
423AST_LEAF(unary_operator) 423AST_LEAF(UnaryOperator)
424AST_END(unary_operator, "unary_op"sv) 424AST_END(UnaryOperator, "unary_op"sv)
425 425
426class AssignableChain_t; 426class AssignableChain_t;
427 427
428AST_NODE(Assignable) 428AST_NODE(Assignable)
429 ast_sel<true, AssignableChain_t, Variable_t, SelfName_t> item; 429 ast_sel<true, AssignableChain_t, Variable_t, SelfItem_t> item;
430 AST_MEMBER(Assignable, &item) 430 AST_MEMBER(Assignable, &item)
431AST_END(Assignable, "assignable"sv) 431AST_END(Assignable, "assignable"sv)
432 432
433class unary_exp_t; 433class UnaryExp_t;
434 434
435AST_NODE(exp_op_value) 435AST_NODE(ExpOpValue)
436 ast_ptr<true, BinaryOperator_t> op; 436 ast_ptr<true, BinaryOperator_t> op;
437 ast_list<true, unary_exp_t> pipeExprs; 437 ast_list<true, UnaryExp_t> pipeExprs;
438 AST_MEMBER(exp_op_value, &op, &pipeExprs) 438 AST_MEMBER(ExpOpValue, &op, &pipeExprs)
439AST_END(exp_op_value, "exp_op_value"sv) 439AST_END(ExpOpValue, "exp_op_value"sv)
440 440
441AST_NODE(Exp) 441AST_NODE(Exp)
442 ast_ptr<true, Seperator_t> sep; 442 ast_ptr<true, Seperator_t> sep;
443 ast_list<true, unary_exp_t> pipeExprs; 443 ast_list<true, UnaryExp_t> pipeExprs;
444 ast_list<false, exp_op_value_t> opValues; 444 ast_list<false, ExpOpValue_t> opValues;
445 ast_ptr<false, Exp_t> nilCoalesed; 445 ast_ptr<false, Exp_t> nilCoalesed;
446 AST_MEMBER(Exp, &sep, &pipeExprs, &opValues, &nilCoalesed) 446 AST_MEMBER(Exp, &sep, &pipeExprs, &opValues, &nilCoalesed)
447AST_END(Exp, "exp"sv) 447AST_END(Exp, "exp"sv)
@@ -450,82 +450,82 @@ class Parens_t;
450class MacroName_t; 450class MacroName_t;
451 451
452AST_NODE(Callable) 452AST_NODE(Callable)
453 ast_sel<true, Variable_t, SelfName_t, VarArg_t, Parens_t, MacroName_t> item; 453 ast_sel<true, Variable_t, SelfItem_t, VarArg_t, Parens_t, MacroName_t> item;
454 AST_MEMBER(Callable, &item) 454 AST_MEMBER(Callable, &item)
455AST_END(Callable, "callable"sv) 455AST_END(Callable, "callable"sv)
456 456
457AST_NODE(variable_pair) 457AST_NODE(VariablePair)
458 ast_ptr<true, Variable_t> name; 458 ast_ptr<true, Variable_t> name;
459 AST_MEMBER(variable_pair, &name) 459 AST_MEMBER(VariablePair, &name)
460AST_END(variable_pair, "variable_pair"sv) 460AST_END(VariablePair, "variable_pair"sv)
461 461
462AST_NODE(variable_pair_def) 462AST_NODE(VariablePairDef)
463 ast_ptr<true, variable_pair_t> pair; 463 ast_ptr<true, VariablePair_t> pair;
464 ast_ptr<false, Exp_t> defVal; 464 ast_ptr<false, Exp_t> defVal;
465 AST_MEMBER(variable_pair_def, &pair, &defVal) 465 AST_MEMBER(VariablePairDef, &pair, &defVal)
466AST_END(variable_pair_def, "variable_pair_def"sv) 466AST_END(VariablePairDef, "variable_pair_def"sv)
467 467
468class String_t; 468class String_t;
469 469
470AST_NODE(normal_pair) 470AST_NODE(NormalPair)
471 ast_sel<true, KeyName_t, Exp_t, String_t> key; 471 ast_sel<true, KeyName_t, Exp_t, String_t> key;
472 ast_sel<true, Exp_t, TableBlock_t> value; 472 ast_sel<true, Exp_t, TableBlock_t> value;
473 AST_MEMBER(normal_pair, &key, &value) 473 AST_MEMBER(NormalPair, &key, &value)
474AST_END(normal_pair, "normal_pair"sv) 474AST_END(NormalPair, "normal_pair"sv)
475 475
476AST_NODE(normal_pair_def) 476AST_NODE(NormalPairDef)
477 ast_ptr<true, normal_pair_t> pair; 477 ast_ptr<true, NormalPair_t> pair;
478 ast_ptr<false, Exp_t> defVal; 478 ast_ptr<false, Exp_t> defVal;
479 AST_MEMBER(normal_pair_def, &pair, &defVal) 479 AST_MEMBER(NormalPairDef, &pair, &defVal)
480AST_END(normal_pair_def, "normal_pair_def"sv) 480AST_END(NormalPairDef, "normal_pair_def"sv)
481 481
482AST_NODE(normal_def) 482AST_NODE(NormalDef)
483 ast_ptr<true, Exp_t> item; 483 ast_ptr<true, Exp_t> item;
484 ast_ptr<true, Seperator_t> sep; 484 ast_ptr<true, Seperator_t> sep;
485 ast_ptr<false, Exp_t> defVal; 485 ast_ptr<false, Exp_t> defVal;
486 AST_MEMBER(normal_def, &item, &sep, &defVal) 486 AST_MEMBER(NormalDef, &item, &sep, &defVal)
487AST_END(normal_def, "normal_def") 487AST_END(NormalDef, "normal_def")
488 488
489AST_NODE(meta_variable_pair) 489AST_NODE(MetaVariablePair)
490 ast_ptr<true, Variable_t> name; 490 ast_ptr<true, Variable_t> name;
491 AST_MEMBER(meta_variable_pair, &name) 491 AST_MEMBER(MetaVariablePair, &name)
492AST_END(meta_variable_pair, "meta_variable_pair"sv) 492AST_END(MetaVariablePair, "meta_variable_pair"sv)
493 493
494AST_NODE(meta_variable_pair_def) 494AST_NODE(MetaVariablePairDef)
495 ast_ptr<true, meta_variable_pair_t> pair; 495 ast_ptr<true, MetaVariablePair_t> pair;
496 ast_ptr<false, Exp_t> defVal; 496 ast_ptr<false, Exp_t> defVal;
497 AST_MEMBER(meta_variable_pair_def, &pair, &defVal) 497 AST_MEMBER(MetaVariablePairDef, &pair, &defVal)
498AST_END(meta_variable_pair_def, "meta_variable_pair_def"sv) 498AST_END(MetaVariablePairDef, "meta_variable_pair_def"sv)
499 499
500AST_NODE(meta_normal_pair) 500AST_NODE(MetaNormalPair)
501 ast_sel<false, Name_t, Exp_t, String_t> key; 501 ast_sel<false, Name_t, Exp_t, String_t> key;
502 ast_sel<true, Exp_t, TableBlock_t> value; 502 ast_sel<true, Exp_t, TableBlock_t> value;
503 AST_MEMBER(meta_normal_pair, &key, &value) 503 AST_MEMBER(MetaNormalPair, &key, &value)
504AST_END(meta_normal_pair, "meta_normal_pair"sv) 504AST_END(MetaNormalPair, "meta_normal_pair"sv)
505 505
506AST_NODE(meta_normal_pair_def) 506AST_NODE(MetaNormalPairDef)
507 ast_ptr<true, meta_normal_pair_t> pair; 507 ast_ptr<true, MetaNormalPair_t> pair;
508 ast_ptr<false, Exp_t> defVal; 508 ast_ptr<false, Exp_t> defVal;
509 AST_MEMBER(meta_normal_pair_def, &pair, &defVal) 509 AST_MEMBER(MetaNormalPairDef, &pair, &defVal)
510AST_END(meta_normal_pair_def, "meta_normal_pair_def"sv) 510AST_END(MetaNormalPairDef, "meta_normal_pair_def"sv)
511 511
512AST_NODE(simple_table) 512AST_NODE(SimpleTable)
513 ast_ptr<true, Seperator_t> sep; 513 ast_ptr<true, Seperator_t> sep;
514 ast_sel_list<true, variable_pair_t, normal_pair_t, meta_variable_pair_t, meta_normal_pair_t> pairs; 514 ast_sel_list<true, VariablePair_t, NormalPair_t, MetaVariablePair_t, MetaNormalPair_t> pairs;
515 AST_MEMBER(simple_table, &sep, &pairs) 515 AST_MEMBER(SimpleTable, &sep, &pairs)
516AST_END(simple_table, "simple_table"sv) 516AST_END(SimpleTable, "simple_table"sv)
517 517
518class const_value_t; 518class ConstValue_t;
519class ClassDecl_t; 519class ClassDecl_t;
520class unary_value_t; 520class UnaryValue_t;
521class FunLit_t; 521class FunLit_t;
522 522
523AST_NODE(SimpleValue) 523AST_NODE(SimpleValue)
524 ast_sel<true, 524 ast_sel<true,
525 TableLit_t, const_value_t, 525 TableLit_t, ConstValue_t,
526 If_t, Switch_t, With_t, ClassDecl_t, 526 If_t, Switch_t, With_t, ClassDecl_t,
527 ForEach_t, For_t, While_t, Do_t, Try_t, 527 ForEach_t, For_t, While_t, Do_t, Try_t,
528 unary_value_t, 528 UnaryValue_t,
529 TblComprehension_t, Comprehension_t, 529 TblComprehension_t, Comprehension_t,
530 FunLit_t, Num_t> value; 530 FunLit_t, Num_t> value;
531 AST_MEMBER(SimpleValue, &value) 531 AST_MEMBER(SimpleValue, &value)
@@ -550,17 +550,17 @@ AST_END(LuaString, "lua_string"sv)
550AST_LEAF(SingleString) 550AST_LEAF(SingleString)
551AST_END(SingleString, "single_string"sv) 551AST_END(SingleString, "single_string"sv)
552 552
553AST_LEAF(double_string_inner) 553AST_LEAF(DoubleStringInner)
554AST_END(double_string_inner, "double_string_inner"sv) 554AST_END(DoubleStringInner, "double_string_inner"sv)
555 555
556AST_NODE(double_string_content) 556AST_NODE(DoubleStringContent)
557 ast_sel<true, double_string_inner_t, Exp_t> content; 557 ast_sel<true, DoubleStringInner_t, Exp_t> content;
558 AST_MEMBER(double_string_content, &content) 558 AST_MEMBER(DoubleStringContent, &content)
559AST_END(double_string_content, "double_string_content"sv) 559AST_END(DoubleStringContent, "double_string_content"sv)
560 560
561AST_NODE(DoubleString) 561AST_NODE(DoubleString)
562 ast_ptr<true, Seperator_t> sep; 562 ast_ptr<true, Seperator_t> sep;
563 ast_list<false, double_string_content_t> segments; 563 ast_list<false, DoubleStringContent_t> segments;
564 AST_MEMBER(DoubleString, &sep, &segments) 564 AST_MEMBER(DoubleString, &sep, &segments)
565AST_END(DoubleString, "double_string"sv) 565AST_END(DoubleString, "double_string"sv)
566 566
@@ -588,12 +588,12 @@ AST_NODE(ColonChainItem)
588 AST_MEMBER(ColonChainItem, &name) 588 AST_MEMBER(ColonChainItem, &name)
589AST_END(ColonChainItem, "colon_chain_item"sv) 589AST_END(ColonChainItem, "colon_chain_item"sv)
590 590
591class default_value_t; 591class DefaultValue_t;
592 592
593AST_NODE(Slice) 593AST_NODE(Slice)
594 ast_sel<true, Exp_t, default_value_t> startValue; 594 ast_sel<true, Exp_t, DefaultValue_t> startValue;
595 ast_sel<true, Exp_t, default_value_t> stopValue; 595 ast_sel<true, Exp_t, DefaultValue_t> stopValue;
596 ast_sel<true, Exp_t, default_value_t> stepValue; 596 ast_sel<true, Exp_t, DefaultValue_t> stepValue;
597 AST_MEMBER(Slice, &startValue, &stopValue, &stepValue) 597 AST_MEMBER(Slice, &startValue, &stopValue, &stepValue)
598AST_END(Slice, "slice"sv) 598AST_END(Slice, "slice"sv)
599 599
@@ -608,17 +608,17 @@ AST_NODE(Invoke)
608 AST_MEMBER(Invoke, &sep, &args) 608 AST_MEMBER(Invoke, &sep, &args)
609AST_END(Invoke, "invoke"sv) 609AST_END(Invoke, "invoke"sv)
610 610
611AST_LEAF(existential_op) 611AST_LEAF(ExistentialOp)
612AST_END(existential_op, "existential_op"sv) 612AST_END(ExistentialOp, "existential_op"sv)
613 613
614AST_LEAF(table_appending_op) 614AST_LEAF(TableAppendingOp)
615AST_END(table_appending_op, "table_appending_op"sv) 615AST_END(TableAppendingOp, "table_appending_op"sv)
616 616
617class InvokeArgs_t; 617class InvokeArgs_t;
618 618
619AST_NODE(ChainValue) 619AST_NODE(ChainValue)
620 ast_ptr<true, Seperator_t> sep; 620 ast_ptr<true, Seperator_t> sep;
621 ast_sel_list<true, Callable_t, Invoke_t, DotChainItem_t, ColonChainItem_t, Slice_t, Exp_t, String_t, InvokeArgs_t, existential_op_t, table_appending_op_t> items; 621 ast_sel_list<true, Callable_t, Invoke_t, DotChainItem_t, ColonChainItem_t, Slice_t, Exp_t, String_t, InvokeArgs_t, ExistentialOp_t, TableAppendingOp_t> items;
622 AST_MEMBER(ChainValue, &sep, &items) 622 AST_MEMBER(ChainValue, &sep, &items)
623AST_END(ChainValue, "chain_value"sv) 623AST_END(ChainValue, "chain_value"sv)
624 624
@@ -629,12 +629,12 @@ AST_NODE(AssignableChain)
629AST_END(AssignableChain, "assignable_chain"sv) 629AST_END(AssignableChain, "assignable_chain"sv)
630 630
631AST_NODE(Value) 631AST_NODE(Value)
632 ast_sel<true, SimpleValue_t, simple_table_t, ChainValue_t, String_t> item; 632 ast_sel<true, SimpleValue_t, SimpleTable_t, ChainValue_t, String_t> item;
633 AST_MEMBER(Value, &item) 633 AST_MEMBER(Value, &item)
634AST_END(Value, "value"sv) 634AST_END(Value, "value"sv)
635 635
636AST_LEAF(default_value) 636AST_LEAF(DefaultValue)
637AST_END(default_value, "default_value"sv) 637AST_END(DefaultValue, "default_value"sv)
638 638
639AST_NODE(SpreadExp) 639AST_NODE(SpreadExp)
640 ast_ptr<true, Exp_t> exp; 640 ast_ptr<true, Exp_t> exp;
@@ -646,36 +646,36 @@ class TableBlockIndent_t;
646AST_NODE(TableLit) 646AST_NODE(TableLit)
647 ast_ptr<true, Seperator_t> sep; 647 ast_ptr<true, Seperator_t> sep;
648 ast_sel_list<false, 648 ast_sel_list<false,
649 variable_pair_def_t, normal_pair_def_t, SpreadExp_t, normal_def_t, 649 VariablePairDef_t, NormalPairDef_t, SpreadExp_t, NormalDef_t,
650 meta_variable_pair_def_t, meta_normal_pair_def_t, 650 MetaVariablePairDef_t, MetaNormalPairDef_t,
651 variable_pair_t, normal_pair_t, Exp_t, TableBlockIndent_t, 651 VariablePair_t, NormalPair_t, Exp_t, TableBlockIndent_t,
652 meta_variable_pair_t, meta_normal_pair_t> values; 652 MetaVariablePair_t, MetaNormalPair_t> values;
653 AST_MEMBER(TableLit, &sep, &values) 653 AST_MEMBER(TableLit, &sep, &values)
654AST_END(TableLit, "table_lit"sv) 654AST_END(TableLit, "table_lit"sv)
655 655
656AST_NODE(TableBlockIndent) 656AST_NODE(TableBlockIndent)
657 ast_ptr<true, Seperator_t> sep; 657 ast_ptr<true, Seperator_t> sep;
658 ast_sel_list<false, 658 ast_sel_list<false,
659 variable_pair_t, normal_pair_t, Exp_t, TableBlockIndent_t, 659 VariablePair_t, NormalPair_t, Exp_t, TableBlockIndent_t,
660 meta_variable_pair_t, meta_normal_pair_t> values; 660 MetaVariablePair_t, MetaNormalPair_t> values;
661 AST_MEMBER(TableBlockIndent, &sep, &values) 661 AST_MEMBER(TableBlockIndent, &sep, &values)
662AST_END(TableBlockIndent, "table_block_indent"sv) 662AST_END(TableBlockIndent, "table_block_indent"sv)
663 663
664AST_NODE(TableBlock) 664AST_NODE(TableBlock)
665 ast_ptr<true, Seperator_t> sep; 665 ast_ptr<true, Seperator_t> sep;
666 ast_sel_list<false, variable_pair_t, normal_pair_t, TableBlockIndent_t, Exp_t, TableBlock_t, SpreadExp_t, meta_variable_pair_t, meta_normal_pair_t> values; 666 ast_sel_list<false, VariablePair_t, NormalPair_t, TableBlockIndent_t, Exp_t, TableBlock_t, SpreadExp_t, MetaVariablePair_t, MetaNormalPair_t> values;
667 AST_MEMBER(TableBlock, &sep, &values) 667 AST_MEMBER(TableBlock, &sep, &values)
668AST_END(TableBlock, "table_block"sv) 668AST_END(TableBlock, "table_block"sv)
669 669
670AST_NODE(class_member_list) 670AST_NODE(ClassMemberList)
671 ast_ptr<true, Seperator_t> sep; 671 ast_ptr<true, Seperator_t> sep;
672 ast_sel_list<true, variable_pair_t, normal_pair_t, meta_variable_pair_t, meta_normal_pair_t> values; 672 ast_sel_list<true, VariablePair_t, NormalPair_t, MetaVariablePair_t, MetaNormalPair_t> values;
673 AST_MEMBER(class_member_list, &sep, &values) 673 AST_MEMBER(ClassMemberList, &sep, &values)
674AST_END(class_member_list, "class_member_list"sv) 674AST_END(ClassMemberList, "class_member_list"sv)
675 675
676AST_NODE(ClassBlock) 676AST_NODE(ClassBlock)
677 ast_ptr<true, Seperator_t> sep; 677 ast_ptr<true, Seperator_t> sep;
678 ast_sel_list<true, class_member_list_t, Statement_t> contents; 678 ast_sel_list<true, ClassMemberList_t, Statement_t> contents;
679 AST_MEMBER(ClassBlock, &sep, &contents) 679 AST_MEMBER(ClassBlock, &sep, &contents)
680AST_END(ClassBlock, "class_block"sv) 680AST_END(ClassBlock, "class_block"sv)
681 681
@@ -687,35 +687,35 @@ AST_NODE(ClassDecl)
687 AST_MEMBER(ClassDecl, &name, &extend, &mixes, &body) 687 AST_MEMBER(ClassDecl, &name, &extend, &mixes, &body)
688AST_END(ClassDecl, "class_decl"sv) 688AST_END(ClassDecl, "class_decl"sv)
689 689
690AST_NODE(global_values) 690AST_NODE(GlobalValues)
691 ast_ptr<true, NameList_t> nameList; 691 ast_ptr<true, NameList_t> nameList;
692 ast_sel<false, TableBlock_t, ExpListLow_t> valueList; 692 ast_sel<false, TableBlock_t, ExpListLow_t> valueList;
693 AST_MEMBER(global_values, &nameList, &valueList) 693 AST_MEMBER(GlobalValues, &nameList, &valueList)
694AST_END(global_values, "global_values"sv) 694AST_END(GlobalValues, "global_values"sv)
695 695
696AST_LEAF(global_op) 696AST_LEAF(GlobalOp)
697AST_END(global_op, "global_op"sv) 697AST_END(GlobalOp, "global_op"sv)
698 698
699AST_NODE(Global) 699AST_NODE(Global)
700 ast_sel<true, ClassDecl_t, global_op_t, global_values_t> item; 700 ast_sel<true, ClassDecl_t, GlobalOp_t, GlobalValues_t> item;
701 AST_MEMBER(Global, &item) 701 AST_MEMBER(Global, &item)
702AST_END(Global, "global"sv) 702AST_END(Global, "global"sv)
703 703
704AST_LEAF(export_default) 704AST_LEAF(ExportDefault)
705AST_END(export_default, "export_default"sv) 705AST_END(ExportDefault, "export_default"sv)
706 706
707class Macro_t; 707class Macro_t;
708 708
709AST_NODE(Export) 709AST_NODE(Export)
710 ast_ptr<false, export_default_t> def; 710 ast_ptr<false, ExportDefault_t> def;
711 ast_sel<true, ExpList_t, Exp_t, Macro_t> target; 711 ast_sel<true, ExpList_t, Exp_t, Macro_t> target;
712 ast_ptr<false, Assign_t> assign; 712 ast_ptr<false, Assign_t> assign;
713 AST_MEMBER(Export, &def, &target, &assign) 713 AST_MEMBER(Export, &def, &target, &assign)
714AST_END(Export, "export"sv) 714AST_END(Export, "export"sv)
715 715
716AST_NODE(FnArgDef) 716AST_NODE(FnArgDef)
717 ast_sel<true, Variable_t, SelfName_t> name; 717 ast_sel<true, Variable_t, SelfItem_t> name;
718 ast_ptr<false, existential_op_t> op; 718 ast_ptr<false, ExistentialOp_t> op;
719 ast_ptr<false, Exp_t> defaultValue; 719 ast_ptr<false, Exp_t> defaultValue;
720 AST_MEMBER(FnArgDef, &name, &op, &defaultValue) 720 AST_MEMBER(FnArgDef, &name, &op, &defaultValue)
721AST_END(FnArgDef, "fn_arg_def"sv) 721AST_END(FnArgDef, "fn_arg_def"sv)
@@ -727,23 +727,23 @@ AST_NODE(FnArgDefList)
727 AST_MEMBER(FnArgDefList, &sep, &definitions, &varArg) 727 AST_MEMBER(FnArgDefList, &sep, &definitions, &varArg)
728AST_END(FnArgDefList, "fn_arg_def_list"sv) 728AST_END(FnArgDefList, "fn_arg_def_list"sv)
729 729
730AST_NODE(outer_var_shadow) 730AST_NODE(OuterVarShadow)
731 ast_ptr<false, NameList_t> varList; 731 ast_ptr<false, NameList_t> varList;
732 AST_MEMBER(outer_var_shadow, &varList) 732 AST_MEMBER(OuterVarShadow, &varList)
733AST_END(outer_var_shadow, "outer_var_shadow"sv) 733AST_END(OuterVarShadow, "outer_var_shadow"sv)
734 734
735AST_NODE(FnArgsDef) 735AST_NODE(FnArgsDef)
736 ast_ptr<false, FnArgDefList_t> defList; 736 ast_ptr<false, FnArgDefList_t> defList;
737 ast_ptr<false, outer_var_shadow_t> shadowOption; 737 ast_ptr<false, OuterVarShadow_t> shadowOption;
738 AST_MEMBER(FnArgsDef, &defList, &shadowOption) 738 AST_MEMBER(FnArgsDef, &defList, &shadowOption)
739AST_END(FnArgsDef, "fn_args_def"sv) 739AST_END(FnArgsDef, "fn_args_def"sv)
740 740
741AST_LEAF(fn_arrow) 741AST_LEAF(FnArrow)
742AST_END(fn_arrow, "fn_arrow"sv) 742AST_END(FnArrow, "fn_arrow"sv)
743 743
744AST_NODE(FunLit) 744AST_NODE(FunLit)
745 ast_ptr<false, FnArgsDef_t> argsDef; 745 ast_ptr<false, FnArgsDef_t> argsDef;
746 ast_ptr<true, fn_arrow_t> arrow; 746 ast_ptr<true, FnArrow_t> arrow;
747 ast_ptr<false, Body_t> body; 747 ast_ptr<false, Body_t> body;
748 AST_MEMBER(FunLit, &argsDef, &arrow, &body) 748 AST_MEMBER(FunLit, &argsDef, &arrow, &body)
749AST_END(FunLit, "fun_lit"sv) 749AST_END(FunLit, "fun_lit"sv)
@@ -787,20 +787,20 @@ AST_NODE(InvokeArgs)
787 AST_MEMBER(InvokeArgs, &sep, &args) 787 AST_MEMBER(InvokeArgs, &sep, &args)
788AST_END(InvokeArgs, "invoke_args"sv) 788AST_END(InvokeArgs, "invoke_args"sv)
789 789
790AST_LEAF(const_value) 790AST_LEAF(ConstValue)
791AST_END(const_value, "const_value"sv) 791AST_END(ConstValue, "const_value"sv)
792 792
793AST_NODE(unary_value) 793AST_NODE(UnaryValue)
794 ast_list<true, unary_operator_t> ops; 794 ast_list<true, UnaryOperator_t> ops;
795 ast_ptr<true, Value_t> value; 795 ast_ptr<true, Value_t> value;
796 AST_MEMBER(unary_value, &ops, &value) 796 AST_MEMBER(UnaryValue, &ops, &value)
797AST_END(unary_value, "unary_value"sv) 797AST_END(UnaryValue, "unary_value"sv)
798 798
799AST_NODE(unary_exp) 799AST_NODE(UnaryExp)
800 ast_list<false, unary_operator_t> ops; 800 ast_list<false, UnaryOperator_t> ops;
801 ast_list<true, Value_t> expos; 801 ast_list<true, Value_t> expos;
802 AST_MEMBER(unary_exp, &ops, &expos) 802 AST_MEMBER(UnaryExp, &ops, &expos)
803AST_END(unary_exp, "unary_exp"sv) 803AST_END(UnaryExp, "unary_exp"sv)
804 804
805AST_NODE(ExpListAssign) 805AST_NODE(ExpListAssign)
806 ast_ptr<true, ExpList_t> expList; 806 ast_ptr<true, ExpList_t> expList;
@@ -808,34 +808,34 @@ AST_NODE(ExpListAssign)
808 AST_MEMBER(ExpListAssign, &expList, &action) 808 AST_MEMBER(ExpListAssign, &expList, &action)
809AST_END(ExpListAssign, "exp_list_assign"sv) 809AST_END(ExpListAssign, "exp_list_assign"sv)
810 810
811AST_NODE(if_line) 811AST_NODE(IfLine)
812 ast_ptr<true, IfType_t> type; 812 ast_ptr<true, IfType_t> type;
813 ast_ptr<true, IfCond_t> condition; 813 ast_ptr<true, IfCond_t> condition;
814 AST_MEMBER(if_line, &type, &condition) 814 AST_MEMBER(IfLine, &type, &condition)
815AST_END(if_line, "if_line"sv) 815AST_END(IfLine, "if_line"sv)
816 816
817AST_NODE(while_line) 817AST_NODE(WhileLine)
818 ast_ptr<true, WhileType_t> type; 818 ast_ptr<true, WhileType_t> type;
819 ast_ptr<true, Exp_t> condition; 819 ast_ptr<true, Exp_t> condition;
820 AST_MEMBER(while_line, &type, &condition) 820 AST_MEMBER(WhileLine, &type, &condition)
821AST_END(while_line, "while_line"sv) 821AST_END(WhileLine, "while_line"sv)
822 822
823AST_LEAF(BreakLoop) 823AST_LEAF(BreakLoop)
824AST_END(BreakLoop, "break_loop"sv) 824AST_END(BreakLoop, "break_loop"sv)
825 825
826AST_NODE(PipeBody) 826AST_NODE(PipeBody)
827 ast_ptr<true, Seperator_t> sep; 827 ast_ptr<true, Seperator_t> sep;
828 ast_list<true, unary_exp_t> values; 828 ast_list<true, UnaryExp_t> values;
829 AST_MEMBER(PipeBody, &sep, &values) 829 AST_MEMBER(PipeBody, &sep, &values)
830AST_END(PipeBody, "pipe_body"sv) 830AST_END(PipeBody, "pipe_body"sv)
831 831
832AST_NODE(statement_appendix) 832AST_NODE(StatementAppendix)
833 ast_sel<true, if_line_t, while_line_t, CompInner_t> item; 833 ast_sel<true, IfLine_t, WhileLine_t, CompInner_t> item;
834 AST_MEMBER(statement_appendix, &item) 834 AST_MEMBER(StatementAppendix, &item)
835AST_END(statement_appendix, "statement_appendix"sv) 835AST_END(StatementAppendix, "statement_appendix"sv)
836 836
837AST_LEAF(statement_sep) 837AST_LEAF(StatementSep)
838AST_END(statement_sep, "statement_sep"sv) 838AST_END(StatementSep, "statement_sep"sv)
839 839
840AST_LEAF(YueLineComment) 840AST_LEAF(YueLineComment)
841AST_END(YueLineComment, "comment"sv) 841AST_END(YueLineComment, "comment"sv)
@@ -859,8 +859,8 @@ AST_NODE(Statement)
859 BreakLoop_t, Label_t, Goto_t, ShortTabAppending_t, 859 BreakLoop_t, Label_t, Goto_t, ShortTabAppending_t,
860 Backcall_t, LocalAttrib_t, PipeBody_t, ExpListAssign_t, ChainAssign_t 860 Backcall_t, LocalAttrib_t, PipeBody_t, ExpListAssign_t, ChainAssign_t
861 > content; 861 > content;
862 ast_ptr<false, statement_appendix_t> appendix; 862 ast_ptr<false, StatementAppendix_t> appendix;
863 ast_ptr<false, statement_sep_t> needSep; 863 ast_ptr<false, StatementSep_t> needSep;
864 AST_MEMBER(Statement, &sep, &comments, &content, &appendix, &needSep) 864 AST_MEMBER(Statement, &sep, &comments, &content, &appendix, &needSep)
865AST_END(Statement, "statement"sv) 865AST_END(Statement, "statement"sv)
866 866
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp
index b47da6c..6fd43d0 100644
--- a/src/yuescript/yue_compiler.cpp
+++ b/src/yuescript/yue_compiler.cpp
@@ -141,15 +141,15 @@ public:
141 case id<Export_t>(): 141 case id<Export_t>():
142 if (auto importNode = stmt->content.as<Import_t>()) { 142 if (auto importNode = stmt->content.as<Import_t>()) {
143 if (auto importAs = importNode->content.as<ImportAs_t>()) { 143 if (auto importAs = importNode->content.as<ImportAs_t>()) {
144 if (importAs->target.is<import_all_macro_t>()) { 144 if (importAs->target.is<ImportAllMacro_t>()) {
145 break; 145 break;
146 } else if (auto tab = importAs->target.as<ImportTabLit_t>()) { 146 } else if (auto tab = importAs->target.as<ImportTabLit_t>()) {
147 bool macroImportingOnly = true; 147 bool macroImportingOnly = true;
148 for (auto item : tab->items.objects()) { 148 for (auto item : tab->items.objects()) {
149 if (!ast_is< 149 if (!ast_is<
150 MacroName_t, 150 MacroName_t,
151 macro_name_pair_t, 151 MacroNamePair_t,
152 import_all_macro_t>(item)) { 152 ImportAllMacro_t>(item)) {
153 macroImportingOnly = false; 153 macroImportingOnly = false;
154 } 154 }
155 } 155 }
@@ -653,7 +653,7 @@ private:
653 return result; 653 return result;
654 } 654 }
655 655
656 unary_exp_t* singleUnaryExpFrom(ast_node* item) const { 656 UnaryExp_t* singleUnaryExpFrom(ast_node* item) const {
657 Exp_t* exp = nullptr; 657 Exp_t* exp = nullptr;
658 switch (item->getId()) { 658 switch (item->getId()) {
659 case id<Exp_t>(): 659 case id<Exp_t>():
@@ -680,8 +680,8 @@ private:
680 } 680 }
681 break; 681 break;
682 } 682 }
683 case id<unary_exp_t>(): { 683 case id<UnaryExp_t>(): {
684 auto unary = static_cast<unary_exp_t*>(item); 684 auto unary = static_cast<UnaryExp_t*>(item);
685 if (unary->expos.size() == 1) { 685 if (unary->expos.size() == 1) {
686 return unary; 686 return unary;
687 } 687 }
@@ -694,7 +694,7 @@ private:
694 BREAK_IF(exp->nilCoalesed); 694 BREAK_IF(exp->nilCoalesed);
695 BREAK_IF(!exp->opValues.empty()); 695 BREAK_IF(!exp->opValues.empty());
696 BREAK_IF(exp->pipeExprs.size() != 1); 696 BREAK_IF(exp->pipeExprs.size() != 1);
697 auto unary = static_cast<unary_exp_t*>(exp->pipeExprs.back()); 697 auto unary = static_cast<UnaryExp_t*>(exp->pipeExprs.back());
698 BREAK_IF(unary->expos.size() != 1); 698 BREAK_IF(unary->expos.size() != 1);
699 return unary; 699 return unary;
700 BLOCK_END 700 BLOCK_END
@@ -729,7 +729,7 @@ private:
729 } 729 }
730 730
731 ast_ptr<false, Exp_t> newExp(Value_t* value, ast_node* x) { 731 ast_ptr<false, Exp_t> newExp(Value_t* value, ast_node* x) {
732 auto unary = x->new_ptr<unary_exp_t>(); 732 auto unary = x->new_ptr<UnaryExp_t>();
733 unary->expos.push_back(value); 733 unary->expos.push_back(value);
734 auto exp = x->new_ptr<Exp_t>(); 734 auto exp = x->new_ptr<Exp_t>();
735 exp->pipeExprs.push_back(unary); 735 exp->pipeExprs.push_back(unary);
@@ -737,11 +737,11 @@ private:
737 } 737 }
738 738
739 ast_ptr<false, Exp_t> newExp(Value_t* left, BinaryOperator_t* op, Value_t* right, ast_node* x) { 739 ast_ptr<false, Exp_t> newExp(Value_t* left, BinaryOperator_t* op, Value_t* right, ast_node* x) {
740 auto lunary = x->new_ptr<unary_exp_t>(); 740 auto lunary = x->new_ptr<UnaryExp_t>();
741 lunary->expos.push_back(left); 741 lunary->expos.push_back(left);
742 auto opValue = x->new_ptr<exp_op_value_t>(); 742 auto opValue = x->new_ptr<ExpOpValue_t>();
743 { 743 {
744 auto runary = x->new_ptr<unary_exp_t>(); 744 auto runary = x->new_ptr<UnaryExp_t>();
745 runary->expos.push_back(right); 745 runary->expos.push_back(right);
746 opValue->op.set(op); 746 opValue->op.set(op);
747 opValue->pipeExprs.push_back(runary); 747 opValue->pipeExprs.push_back(runary);
@@ -752,7 +752,7 @@ private:
752 return exp; 752 return exp;
753 } 753 }
754 754
755 ast_ptr<false, Exp_t> newExp(unary_exp_t* unary, ast_node* x) { 755 ast_ptr<false, Exp_t> newExp(UnaryExp_t* unary, ast_node* x) {
756 auto exp = x->new_ptr<Exp_t>(); 756 auto exp = x->new_ptr<Exp_t>();
757 exp->pipeExprs.push_back(unary); 757 exp->pipeExprs.push_back(unary);
758 return exp; 758 return exp;
@@ -842,7 +842,7 @@ private:
842 return nullptr; 842 return nullptr;
843 } 843 }
844 case id<Local_t>(): { 844 case id<Local_t>(): {
845 if (auto localValues = static_cast<Local_t*>(stmt->content.get())->item.as<local_values_t>()) { 845 if (auto localValues = static_cast<Local_t*>(stmt->content.get())->item.as<LocalValues_t>()) {
846 if (auto expList = localValues->valueList.as<ExpListLow_t>()) { 846 if (auto expList = localValues->valueList.as<ExpListLow_t>()) {
847 return static_cast<Exp_t*>(expList->exprs.back()); 847 return static_cast<Exp_t*>(expList->exprs.back());
848 } 848 }
@@ -850,7 +850,7 @@ private:
850 return nullptr; 850 return nullptr;
851 } 851 }
852 case id<Global_t>(): { 852 case id<Global_t>(): {
853 if (auto globalValues = static_cast<Global_t*>(stmt->content.get())->item.as<global_values_t>()) { 853 if (auto globalValues = static_cast<Global_t*>(stmt->content.get())->item.as<GlobalValues_t>()) {
854 if (auto expList = globalValues->valueList.as<ExpListLow_t>()) { 854 if (auto expList = globalValues->valueList.as<ExpListLow_t>()) {
855 return static_cast<Exp_t*>(expList->exprs.back()); 855 return static_cast<Exp_t*>(expList->exprs.back());
856 } 856 }
@@ -897,7 +897,7 @@ private:
897 if (ast_is<ColonChainItem_t>(chainValue->items.back())) { 897 if (ast_is<ColonChainItem_t>(chainValue->items.back())) {
898 return ChainType::EndWithColon; 898 return ChainType::EndWithColon;
899 } 899 }
900 if (ast_is<existential_op_t>(chainValue->items.back())) { 900 if (ast_is<ExistentialOp_t>(chainValue->items.back())) {
901 return ChainType::EndWithEOP; 901 return ChainType::EndWithEOP;
902 } 902 }
903 if (auto dot = ast_cast<DotChainItem_t>(chainValue->items.back())) { 903 if (auto dot = ast_cast<DotChainItem_t>(chainValue->items.back())) {
@@ -913,7 +913,7 @@ private:
913 } else if (auto meta = colonChain->name.as<Metamethod_t>(); meta && !meta->item.is<Name_t>()) { 913 } else if (auto meta = colonChain->name.as<Metamethod_t>(); meta && !meta->item.is<Name_t>()) {
914 return ChainType::MetaFieldInvocation; 914 return ChainType::MetaFieldInvocation;
915 } 915 }
916 } else if (ast_is<existential_op_t>(item)) { 916 } else if (ast_is<ExistentialOp_t>(item)) {
917 return ChainType::HasEOP; 917 return ChainType::HasEOP;
918 } 918 }
919 } 919 }
@@ -928,8 +928,8 @@ private:
928 BREAK_IF(!callable); 928 BREAK_IF(!callable);
929 ast_node* var = callable->item.as<Variable_t>(); 929 ast_node* var = callable->item.as<Variable_t>();
930 if (!var) { 930 if (!var) {
931 if (auto self = callable->item.as<SelfName_t>()) { 931 if (auto self = callable->item.as<SelfItem_t>()) {
932 var = self->name.as<self_t>(); 932 var = self->name.as<Self_t>();
933 } 933 }
934 } 934 }
935 BREAK_IF(!var); 935 BREAK_IF(!var);
@@ -949,7 +949,7 @@ private:
949 BREAK_IF(!chainValue); 949 BREAK_IF(!chainValue);
950 BREAK_IF(chainValue->items.size() != 1); 950 BREAK_IF(chainValue->items.size() != 1);
951 auto callable = ast_cast<Callable_t>(chainValue->items.front()); 951 auto callable = ast_cast<Callable_t>(chainValue->items.front());
952 BREAK_IF(!callable || !(callable->item.is<Variable_t>() || callable->getByPath<SelfName_t, self_t>())); 952 BREAK_IF(!callable || !(callable->item.is<Variable_t>() || callable->getByPath<SelfItem_t, Self_t>()));
953 str_list tmp; 953 str_list tmp;
954 if (accessing) { 954 if (accessing) {
955 transformCallable(callable, tmp); 955 transformCallable(callable, tmp);
@@ -986,7 +986,7 @@ private:
986 case id<Variable_t>(): 986 case id<Variable_t>():
987 checkConst(_parser.toString(callable->item.get()), callable->item.get()); 987 checkConst(_parser.toString(callable->item.get()), callable->item.get());
988 return true; 988 return true;
989 case id<SelfName_t>(): 989 case id<SelfItem_t>():
990 return true; 990 return true;
991 } 991 }
992 } else 992 } else
@@ -997,7 +997,7 @@ private:
997 } 997 }
998 } else { 998 } else {
999 if (std::find_if(chainItems.begin(), chainItems.end(), [](ast_node* node) { 999 if (std::find_if(chainItems.begin(), chainItems.end(), [](ast_node* node) {
1000 return ast_is<existential_op_t>(node); 1000 return ast_is<ExistentialOp_t>(node);
1001 }) 1001 })
1002 != chainItems.end()) { 1002 != chainItems.end()) {
1003 return false; 1003 return false;
@@ -1006,7 +1006,7 @@ private:
1006 switch (lastItem->getId()) { 1006 switch (lastItem->getId()) {
1007 case id<DotChainItem_t>(): 1007 case id<DotChainItem_t>():
1008 case id<Exp_t>(): 1008 case id<Exp_t>():
1009 case id<table_appending_op_t>(): 1009 case id<TableAppendingOp_t>():
1010 return true; 1010 return true;
1011 } 1011 }
1012 } 1012 }
@@ -1017,7 +1017,7 @@ private:
1017 if (auto value = singleValueFrom(exp)) { 1017 if (auto value = singleValueFrom(exp)) {
1018 auto item = value->item.get(); 1018 auto item = value->item.get();
1019 switch (item->getId()) { 1019 switch (item->getId()) {
1020 case id<simple_table_t>(): 1020 case id<SimpleTable_t>():
1021 return true; 1021 return true;
1022 case id<SimpleValue_t>(): { 1022 case id<SimpleValue_t>(): {
1023 auto simpleValue = static_cast<SimpleValue_t*>(item); 1023 auto simpleValue = static_cast<SimpleValue_t*>(item);
@@ -1167,8 +1167,8 @@ private:
1167 } else if (auto attrib = statement->content.as<LocalAttrib_t>()) { 1167 } else if (auto attrib = statement->content.as<LocalAttrib_t>()) {
1168 auto appendix = statement->appendix.get(); 1168 auto appendix = statement->appendix.get();
1169 switch (appendix->item->getId()) { 1169 switch (appendix->item->getId()) {
1170 case id<if_line_t>(): { 1170 case id<IfLine_t>(): {
1171 auto if_line = static_cast<if_line_t*>(appendix->item.get()); 1171 auto if_line = static_cast<IfLine_t*>(appendix->item.get());
1172 auto ifNode = x->new_ptr<If_t>(); 1172 auto ifNode = x->new_ptr<If_t>();
1173 ifNode->type.set(if_line->type); 1173 ifNode->type.set(if_line->type);
1174 ifNode->nodes.push_back(if_line->condition); 1174 ifNode->nodes.push_back(if_line->condition);
@@ -1214,7 +1214,7 @@ private:
1214 transformStatement(statement, out); 1214 transformStatement(statement, out);
1215 return; 1215 return;
1216 } 1216 }
1217 case id<while_line_t>(): { 1217 case id<WhileLine_t>(): {
1218 throw std::logic_error(_info.errorMessage("while-loop line decorator is not supported here"sv, appendix->item.get())); 1218 throw std::logic_error(_info.errorMessage("while-loop line decorator is not supported here"sv, appendix->item.get()));
1219 break; 1219 break;
1220 } 1220 }
@@ -1227,8 +1227,8 @@ private:
1227 } 1227 }
1228 auto appendix = statement->appendix.get(); 1228 auto appendix = statement->appendix.get();
1229 switch (appendix->item->getId()) { 1229 switch (appendix->item->getId()) {
1230 case id<if_line_t>(): { 1230 case id<IfLine_t>(): {
1231 auto if_line = static_cast<if_line_t*>(appendix->item.get()); 1231 auto if_line = static_cast<IfLine_t*>(appendix->item.get());
1232 auto ifNode = x->new_ptr<If_t>(); 1232 auto ifNode = x->new_ptr<If_t>();
1233 ifNode->type.set(if_line->type); 1233 ifNode->type.set(if_line->type);
1234 ifNode->nodes.push_back(if_line->condition); 1234 ifNode->nodes.push_back(if_line->condition);
@@ -1248,8 +1248,8 @@ private:
1248 statement->content.set(expListAssign); 1248 statement->content.set(expListAssign);
1249 break; 1249 break;
1250 } 1250 }
1251 case id<while_line_t>(): { 1251 case id<WhileLine_t>(): {
1252 auto while_line = static_cast<while_line_t*>(appendix->item.get()); 1252 auto while_line = static_cast<WhileLine_t*>(appendix->item.get());
1253 auto whileNode = x->new_ptr<While_t>(); 1253 auto whileNode = x->new_ptr<While_t>();
1254 whileNode->type.set(while_line->type); 1254 whileNode->type.set(while_line->type);
1255 whileNode->condition.set(while_line->condition); 1255 whileNode->condition.set(while_line->condition);
@@ -1429,8 +1429,8 @@ private:
1429 std::string name; 1429 std::string name;
1430 if (auto var = callable->item.as<Variable_t>()) { 1430 if (auto var = callable->item.as<Variable_t>()) {
1431 name = _parser.toString(var); 1431 name = _parser.toString(var);
1432 } else if (auto self = callable->item.as<SelfName_t>()) { 1432 } else if (auto self = callable->item.as<SelfItem_t>()) {
1433 if (self->name.is<self_t>()) name = "self"sv; 1433 if (self->name.is<Self_t>()) name = "self"sv;
1434 } 1434 }
1435 BREAK_IF(name.empty()); 1435 BREAK_IF(name.empty());
1436 switch (op) { 1436 switch (op) {
@@ -1596,7 +1596,7 @@ private:
1596 BLOCK_START 1596 BLOCK_START
1597 auto value = singleValueFrom(*it); 1597 auto value = singleValueFrom(*it);
1598 BREAK_IF(!value); 1598 BREAK_IF(!value);
1599 if (value->item.is<simple_table_t>() || value->getByPath<SimpleValue_t, TableLit_t>()) { 1599 if (value->item.is<SimpleTable_t>() || value->getByPath<SimpleValue_t, TableLit_t>()) {
1600 holdItem = true; 1600 holdItem = true;
1601 break; 1601 break;
1602 } 1602 }
@@ -1606,7 +1606,7 @@ private:
1606 if (auto dot = ast_cast<DotChainItem_t>(chainValue->items.back())) { 1606 if (auto dot = ast_cast<DotChainItem_t>(chainValue->items.back())) {
1607 BREAK_IF(!dot->name.is<Metatable_t>()); 1607 BREAK_IF(!dot->name.is<Metatable_t>());
1608 holdItem = true; 1608 holdItem = true;
1609 } else if (ast_is<table_appending_op_t>(chainValue->items.back())) { 1609 } else if (ast_is<TableAppendingOp_t>(chainValue->items.back())) {
1610 holdItem = true; 1610 holdItem = true;
1611 } 1611 }
1612 BLOCK_END 1612 BLOCK_END
@@ -1677,7 +1677,7 @@ private:
1677 transformAssignItem(*vit, args); 1677 transformAssignItem(*vit, args);
1678 _buf << indent() << globalVar("setmetatable"sv, x) << '(' << join(args, ", "sv) << ')' << nll(x); 1678 _buf << indent() << globalVar("setmetatable"sv, x) << '(' << join(args, ", "sv) << ')' << nll(x);
1679 temp.push_back(clearBuf()); 1679 temp.push_back(clearBuf());
1680 } else if (ast_is<table_appending_op_t>(chainValue->items.back())) { 1680 } else if (ast_is<TableAppendingOp_t>(chainValue->items.back())) {
1681 auto tmpChain = chainValue->new_ptr<ChainValue_t>(); 1681 auto tmpChain = chainValue->new_ptr<ChainValue_t>();
1682 tmpChain->items.dup(chainValue->items); 1682 tmpChain->items.dup(chainValue->items);
1683 tmpChain->items.pop_back(); 1683 tmpChain->items.pop_back();
@@ -1940,7 +1940,7 @@ private:
1940 bool isNil = false; 1940 bool isNil = false;
1941 if (auto v1 = singleValueFrom(pair.defVal)) { 1941 if (auto v1 = singleValueFrom(pair.defVal)) {
1942 if (auto v2 = v1->item.as<SimpleValue_t>()) { 1942 if (auto v2 = v1->item.as<SimpleValue_t>()) {
1943 if (auto v3 = v2->value.as<const_value_t>()) { 1943 if (auto v3 = v2->value.as<ConstValue_t>()) {
1944 isNil = _parser.toString(v3) == "nil"sv; 1944 isNil = _parser.toString(v3) == "nil"sv;
1945 } 1945 }
1946 } 1946 }
@@ -2095,7 +2095,7 @@ private:
2095 bool isNil = false; 2095 bool isNil = false;
2096 if (auto v1 = singleValueFrom(item.defVal)) { 2096 if (auto v1 = singleValueFrom(item.defVal)) {
2097 if (auto v2 = v1->item.as<SimpleValue_t>()) { 2097 if (auto v2 = v1->item.as<SimpleValue_t>()) {
2098 if (auto v3 = v2->value.as<const_value_t>()) { 2098 if (auto v3 = v2->value.as<ConstValue_t>()) {
2099 isNil = _parser.toString(v3) == "nil"sv; 2099 isNil = _parser.toString(v3) == "nil"sv;
2100 } 2100 }
2101 } 2101 }
@@ -2141,7 +2141,7 @@ private:
2141 2141
2142 std::list<DestructItem> destructFromExp(ast_node* node, bool optional) { 2142 std::list<DestructItem> destructFromExp(ast_node* node, bool optional) {
2143 const node_container* tableItems = nullptr; 2143 const node_container* tableItems = nullptr;
2144 ast_ptr<false, existential_op_t> sep = optional ? node->new_ptr<existential_op_t>() : nullptr; 2144 ast_ptr<false, ExistentialOp_t> sep = optional ? node->new_ptr<ExistentialOp_t>() : nullptr;
2145 switch (node->getId()) { 2145 switch (node->getId()) {
2146 case id<Exp_t>(): { 2146 case id<Exp_t>(): {
2147 auto item = singleValueFrom(node)->item.get(); 2147 auto item = singleValueFrom(node)->item.get();
@@ -2150,7 +2150,7 @@ private:
2150 if (tbA) { 2150 if (tbA) {
2151 tableItems = &tbA->values.objects(); 2151 tableItems = &tbA->values.objects();
2152 } else { 2152 } else {
2153 auto tbB = ast_cast<simple_table_t>(item); 2153 auto tbB = ast_cast<SimpleTable_t>(item);
2154 if (tbB) tableItems = &tbB->pairs.objects(); 2154 if (tbB) tableItems = &tbB->pairs.objects();
2155 } 2155 }
2156 break; 2156 break;
@@ -2170,8 +2170,8 @@ private:
2170 tableItems = &table->values.objects(); 2170 tableItems = &table->values.objects();
2171 break; 2171 break;
2172 } 2172 }
2173 case id<simple_table_t>(): { 2173 case id<SimpleTable_t>(): {
2174 auto table = ast_cast<simple_table_t>(node); 2174 auto table = ast_cast<SimpleTable_t>(node);
2175 tableItems = &table->pairs.objects(); 2175 tableItems = &table->pairs.objects();
2176 break; 2176 break;
2177 } 2177 }
@@ -2184,9 +2184,9 @@ private:
2184 for (auto pair : *tableItems) { 2184 for (auto pair : *tableItems) {
2185 switch (pair->getId()) { 2185 switch (pair->getId()) {
2186 case id<Exp_t>(): 2186 case id<Exp_t>():
2187 case id<normal_def_t>(): { 2187 case id<NormalDef_t>(): {
2188 Exp_t* defVal = nullptr; 2188 Exp_t* defVal = nullptr;
2189 if (auto nd = ast_cast<normal_def_t>(pair)) { 2189 if (auto nd = ast_cast<NormalDef_t>(pair)) {
2190 pair = nd->item.get(); 2190 pair = nd->item.get();
2191 defVal = nd->defVal.get(); 2191 defVal = nd->defVal.get();
2192 } 2192 }
@@ -2196,7 +2196,7 @@ private:
2196 } 2196 }
2197 auto value = singleValueFrom(pair); 2197 auto value = singleValueFrom(pair);
2198 auto item = value->item.get(); 2198 auto item = value->item.get();
2199 if (ast_is<simple_table_t>(item) || item->getByPath<TableLit_t>()) { 2199 if (ast_is<SimpleTable_t>(item) || item->getByPath<TableLit_t>()) {
2200 auto subPairs = destructFromExp(pair, optional); 2200 auto subPairs = destructFromExp(pair, optional);
2201 if (!subPairs.empty()) { 2201 if (!subPairs.empty()) {
2202 if (defVal) { 2202 if (defVal) {
@@ -2223,14 +2223,14 @@ private:
2223 } 2223 }
2224 break; 2224 break;
2225 } 2225 }
2226 case id<variable_pair_t>(): 2226 case id<VariablePair_t>():
2227 case id<variable_pair_def_t>(): { 2227 case id<VariablePairDef_t>(): {
2228 Exp_t* defVal = nullptr; 2228 Exp_t* defVal = nullptr;
2229 if (auto vpd = ast_cast<variable_pair_def_t>(pair)) { 2229 if (auto vpd = ast_cast<VariablePairDef_t>(pair)) {
2230 pair = vpd->pair.get(); 2230 pair = vpd->pair.get();
2231 defVal = vpd->defVal.get(); 2231 defVal = vpd->defVal.get();
2232 } 2232 }
2233 auto vp = static_cast<variable_pair_t*>(pair); 2233 auto vp = static_cast<VariablePair_t*>(pair);
2234 auto name = _parser.toString(vp->name); 2234 auto name = _parser.toString(vp->name);
2235 auto chain = toAst<ChainValue_t>('.' + name, vp->name); 2235 auto chain = toAst<ChainValue_t>('.' + name, vp->name);
2236 pairs.push_back({toAst<Exp_t>(name, vp).get(), 2236 pairs.push_back({toAst<Exp_t>(name, vp).get(),
@@ -2239,14 +2239,14 @@ private:
2239 defVal}); 2239 defVal});
2240 break; 2240 break;
2241 } 2241 }
2242 case id<normal_pair_t>(): 2242 case id<NormalPair_t>():
2243 case id<normal_pair_def_t>(): { 2243 case id<NormalPairDef_t>(): {
2244 Exp_t* defVal = nullptr; 2244 Exp_t* defVal = nullptr;
2245 if (auto npd = ast_cast<normal_pair_def_t>(pair)) { 2245 if (auto npd = ast_cast<NormalPairDef_t>(pair)) {
2246 pair = npd->pair.get(); 2246 pair = npd->pair.get();
2247 defVal = npd->defVal.get(); 2247 defVal = npd->defVal.get();
2248 } 2248 }
2249 auto np = static_cast<normal_pair_t*>(pair); 2249 auto np = static_cast<NormalPair_t*>(pair);
2250 ast_ptr<true, ast_node> keyIndex; 2250 ast_ptr<true, ast_node> keyIndex;
2251 if (np->key) { 2251 if (np->key) {
2252 if (auto key = np->key->getByPath<Name_t>()) { 2252 if (auto key = np->key->getByPath<Name_t>()) {
@@ -2256,7 +2256,7 @@ private:
2256 } else { 2256 } else {
2257 keyIndex = toAst<DotChainItem_t>('.' + keyNameStr, key).get(); 2257 keyIndex = toAst<DotChainItem_t>('.' + keyNameStr, key).get();
2258 } 2258 }
2259 } else if (auto key = np->key->getByPath<SelfName_t>()) { 2259 } else if (auto key = np->key->getByPath<SelfItem_t>()) {
2260 auto callable = np->new_ptr<Callable_t>(); 2260 auto callable = np->new_ptr<Callable_t>();
2261 callable->item.set(key); 2261 callable->item.set(key);
2262 auto chainValue = np->new_ptr<ChainValue_t>(); 2262 auto chainValue = np->new_ptr<ChainValue_t>();
@@ -2273,7 +2273,7 @@ private:
2273 if (auto exp = np->value.as<Exp_t>()) { 2273 if (auto exp = np->value.as<Exp_t>()) {
2274 if (!isAssignable(exp)) throw std::logic_error(_info.errorMessage("can't do destructure value"sv, exp)); 2274 if (!isAssignable(exp)) throw std::logic_error(_info.errorMessage("can't do destructure value"sv, exp));
2275 auto item = singleValueFrom(exp)->item.get(); 2275 auto item = singleValueFrom(exp)->item.get();
2276 if (ast_is<simple_table_t>(item) || item->getByPath<TableLit_t>()) { 2276 if (ast_is<SimpleTable_t>(item) || item->getByPath<TableLit_t>()) {
2277 auto subPairs = destructFromExp(exp, optional); 2277 auto subPairs = destructFromExp(exp, optional);
2278 if (!subPairs.empty()) { 2278 if (!subPairs.empty()) {
2279 if (defVal) { 2279 if (defVal) {
@@ -2327,31 +2327,31 @@ private:
2327 } 2327 }
2328 break; 2328 break;
2329 } 2329 }
2330 case id<meta_variable_pair_t>(): 2330 case id<MetaVariablePair_t>():
2331 case id<meta_variable_pair_def_t>(): { 2331 case id<MetaVariablePairDef_t>(): {
2332 Exp_t* defVal = nullptr; 2332 Exp_t* defVal = nullptr;
2333 if (auto mvpd = ast_cast<meta_variable_pair_def_t>(pair)) { 2333 if (auto mvpd = ast_cast<MetaVariablePairDef_t>(pair)) {
2334 pair = mvpd->pair.get(); 2334 pair = mvpd->pair.get();
2335 defVal = mvpd->defVal.get(); 2335 defVal = mvpd->defVal.get();
2336 } 2336 }
2337 auto mp = static_cast<meta_variable_pair_t*>(pair); 2337 auto mp = static_cast<MetaVariablePair_t*>(pair);
2338 auto name = _parser.toString(mp->name); 2338 auto name = _parser.toString(mp->name);
2339 checkMetamethod(name, mp->name); 2339 checkMetamethod(name, mp->name);
2340 _buf << "__"sv << name << ':' << name; 2340 _buf << "__"sv << name << ':' << name;
2341 auto newPairDef = toAst<normal_pair_def_t>(clearBuf(), pair); 2341 auto newPairDef = toAst<NormalPairDef_t>(clearBuf(), pair);
2342 newPairDef->defVal.set(defVal); 2342 newPairDef->defVal.set(defVal);
2343 subMetaDestruct->values.push_back(newPairDef); 2343 subMetaDestruct->values.push_back(newPairDef);
2344 break; 2344 break;
2345 } 2345 }
2346 case id<meta_normal_pair_t>(): 2346 case id<MetaNormalPair_t>():
2347 case id<meta_normal_pair_def_t>(): { 2347 case id<MetaNormalPairDef_t>(): {
2348 Exp_t* defVal = nullptr; 2348 Exp_t* defVal = nullptr;
2349 if (auto mnpd = ast_cast<meta_normal_pair_def_t>(pair)) { 2349 if (auto mnpd = ast_cast<MetaNormalPairDef_t>(pair)) {
2350 pair = mnpd->pair.get(); 2350 pair = mnpd->pair.get();
2351 defVal = mnpd->defVal.get(); 2351 defVal = mnpd->defVal.get();
2352 } 2352 }
2353 auto mp = static_cast<meta_normal_pair_t*>(pair); 2353 auto mp = static_cast<MetaNormalPair_t*>(pair);
2354 auto newPair = pair->new_ptr<normal_pair_t>(); 2354 auto newPair = pair->new_ptr<NormalPair_t>();
2355 if (mp->key) { 2355 if (mp->key) {
2356 switch (mp->key->getId()) { 2356 switch (mp->key->getId()) {
2357 case id<Name_t>(): { 2357 case id<Name_t>(): {
@@ -2370,7 +2370,7 @@ private:
2370 } 2370 }
2371 } 2371 }
2372 newPair->value.set(mp->value); 2372 newPair->value.set(mp->value);
2373 auto newPairDef = mp->new_ptr<normal_pair_def_t>(); 2373 auto newPairDef = mp->new_ptr<NormalPairDef_t>();
2374 newPairDef->pair.set(newPair); 2374 newPairDef->pair.set(newPair);
2375 newPairDef->defVal.set(defVal); 2375 newPairDef->defVal.set(defVal);
2376 subMetaDestruct->values.push_back(newPairDef); 2376 subMetaDestruct->values.push_back(newPairDef);
@@ -2425,11 +2425,11 @@ private:
2425 auto expr = *i; 2425 auto expr = *i;
2426 auto value = singleValueFrom(expr); 2426 auto value = singleValueFrom(expr);
2427 ast_node* destructNode = value->getByPath<SimpleValue_t, TableLit_t>(); 2427 ast_node* destructNode = value->getByPath<SimpleValue_t, TableLit_t>();
2428 if (destructNode || (destructNode = value->item.as<simple_table_t>())) { 2428 if (destructNode || (destructNode = value->item.as<SimpleTable_t>())) {
2429 if (*j != nil) { 2429 if (*j != nil) {
2430 if (auto ssVal = simpleSingleValueFrom(*j)) { 2430 if (auto ssVal = simpleSingleValueFrom(*j)) {
2431 switch (ssVal->value->getId()) { 2431 switch (ssVal->value->getId()) {
2432 case id<const_value_t>(): 2432 case id<ConstValue_t>():
2433 throw std::logic_error(_info.errorMessage("can not destructure a constant"sv, ssVal->value)); 2433 throw std::logic_error(_info.errorMessage("can not destructure a constant"sv, ssVal->value));
2434 break; 2434 break;
2435 case id<Num_t>(): 2435 case id<Num_t>():
@@ -2449,28 +2449,28 @@ private:
2449 case id<TableLit_t>(): 2449 case id<TableLit_t>():
2450 dlist = &static_cast<TableLit_t*>(destructNode)->values.objects(); 2450 dlist = &static_cast<TableLit_t*>(destructNode)->values.objects();
2451 break; 2451 break;
2452 case id<simple_table_t>(): 2452 case id<SimpleTable_t>():
2453 dlist = &static_cast<simple_table_t*>(destructNode)->pairs.objects(); 2453 dlist = &static_cast<SimpleTable_t*>(destructNode)->pairs.objects();
2454 break; 2454 break;
2455 default: YUEE("AST node mismatch", destructNode); break; 2455 default: YUEE("AST node mismatch", destructNode); break;
2456 } 2456 }
2457 for (auto item : *dlist) { 2457 for (auto item : *dlist) {
2458 switch (item->getId()) { 2458 switch (item->getId()) {
2459 case id<meta_variable_pair_def_t>(): { 2459 case id<MetaVariablePairDef_t>(): {
2460 auto mvp = static_cast<meta_variable_pair_def_t*>(item); 2460 auto mvp = static_cast<MetaVariablePairDef_t*>(item);
2461 auto mp = mvp->pair.get(); 2461 auto mp = mvp->pair.get();
2462 auto name = _parser.toString(mp->name); 2462 auto name = _parser.toString(mp->name);
2463 checkMetamethod(name, mp->name); 2463 checkMetamethod(name, mp->name);
2464 _buf << "__"sv << name << ':' << name; 2464 _buf << "__"sv << name << ':' << name;
2465 auto newPairDef = toAst<normal_pair_def_t>(clearBuf(), item); 2465 auto newPairDef = toAst<NormalPairDef_t>(clearBuf(), item);
2466 newPairDef->defVal.set(mvp->defVal); 2466 newPairDef->defVal.set(mvp->defVal);
2467 subMetaDestruct->values.push_back(newPairDef); 2467 subMetaDestruct->values.push_back(newPairDef);
2468 break; 2468 break;
2469 } 2469 }
2470 case id<meta_normal_pair_def_t>(): { 2470 case id<MetaNormalPairDef_t>(): {
2471 auto mnp = static_cast<meta_normal_pair_def_t*>(item); 2471 auto mnp = static_cast<MetaNormalPairDef_t*>(item);
2472 auto mp = mnp->pair.get(); 2472 auto mp = mnp->pair.get();
2473 auto newPair = item->new_ptr<normal_pair_t>(); 2473 auto newPair = item->new_ptr<NormalPair_t>();
2474 if (mp->key) { 2474 if (mp->key) {
2475 switch (mp->key->getId()) { 2475 switch (mp->key->getId()) {
2476 case id<Name_t>(): { 2476 case id<Name_t>(): {
@@ -2492,24 +2492,24 @@ private:
2492 } 2492 }
2493 } 2493 }
2494 newPair->value.set(mp->value); 2494 newPair->value.set(mp->value);
2495 auto newPairDef = item->new_ptr<normal_pair_def_t>(); 2495 auto newPairDef = item->new_ptr<NormalPairDef_t>();
2496 newPairDef->pair.set(newPair); 2496 newPairDef->pair.set(newPair);
2497 newPairDef->defVal.set(mnp->defVal); 2497 newPairDef->defVal.set(mnp->defVal);
2498 subMetaDestruct->values.push_back(newPairDef); 2498 subMetaDestruct->values.push_back(newPairDef);
2499 break; 2499 break;
2500 } 2500 }
2501 case id<meta_variable_pair_t>(): { 2501 case id<MetaVariablePair_t>(): {
2502 auto mp = static_cast<meta_variable_pair_t*>(item); 2502 auto mp = static_cast<MetaVariablePair_t*>(item);
2503 auto name = _parser.toString(mp->name); 2503 auto name = _parser.toString(mp->name);
2504 checkMetamethod(name, mp->name); 2504 checkMetamethod(name, mp->name);
2505 _buf << "__"sv << name << ':' << name; 2505 _buf << "__"sv << name << ':' << name;
2506 auto newPairDef = toAst<normal_pair_def_t>(clearBuf(), item); 2506 auto newPairDef = toAst<NormalPairDef_t>(clearBuf(), item);
2507 subMetaDestruct->values.push_back(newPairDef); 2507 subMetaDestruct->values.push_back(newPairDef);
2508 break; 2508 break;
2509 } 2509 }
2510 case id<meta_normal_pair_t>(): { 2510 case id<MetaNormalPair_t>(): {
2511 auto mp = static_cast<meta_normal_pair_t*>(item); 2511 auto mp = static_cast<MetaNormalPair_t*>(item);
2512 auto newPair = item->new_ptr<normal_pair_t>(); 2512 auto newPair = item->new_ptr<NormalPair_t>();
2513 if (mp->key) { 2513 if (mp->key) {
2514 switch (mp->key->getId()) { 2514 switch (mp->key->getId()) {
2515 case id<Name_t>(): { 2515 case id<Name_t>(): {
@@ -2533,21 +2533,21 @@ private:
2533 } 2533 }
2534 } 2534 }
2535 newPair->value.set(mp->value); 2535 newPair->value.set(mp->value);
2536 auto newPairDef = item->new_ptr<normal_pair_def_t>(); 2536 auto newPairDef = item->new_ptr<NormalPairDef_t>();
2537 newPairDef->pair.set(newPair); 2537 newPairDef->pair.set(newPair);
2538 subMetaDestruct->values.push_back(newPairDef); 2538 subMetaDestruct->values.push_back(newPairDef);
2539 break; 2539 break;
2540 } 2540 }
2541 case id<variable_pair_t>(): { 2541 case id<VariablePair_t>(): {
2542 auto pair = static_cast<variable_pair_t*>(item); 2542 auto pair = static_cast<VariablePair_t*>(item);
2543 auto newPairDef = item->new_ptr<variable_pair_def_t>(); 2543 auto newPairDef = item->new_ptr<VariablePairDef_t>();
2544 newPairDef->pair.set(pair); 2544 newPairDef->pair.set(pair);
2545 subDestruct->values.push_back(newPairDef); 2545 subDestruct->values.push_back(newPairDef);
2546 break; 2546 break;
2547 } 2547 }
2548 case id<normal_pair_t>(): { 2548 case id<NormalPair_t>(): {
2549 auto pair = static_cast<normal_pair_t*>(item); 2549 auto pair = static_cast<NormalPair_t*>(item);
2550 auto newPairDef = item->new_ptr<normal_pair_def_t>(); 2550 auto newPairDef = item->new_ptr<NormalPairDef_t>();
2551 newPairDef->pair.set(pair); 2551 newPairDef->pair.set(pair);
2552 subDestruct->values.push_back(newPairDef); 2552 subDestruct->values.push_back(newPairDef);
2553 break; 2553 break;
@@ -2636,7 +2636,7 @@ private:
2636 for (auto node : item.structure->items.objects()) { 2636 for (auto node : item.structure->items.objects()) {
2637 if (auto exp = ast_cast<Exp_t>(node)) { 2637 if (auto exp = ast_cast<Exp_t>(node)) {
2638 if (auto value = simpleSingleValueFrom(node)) { 2638 if (auto value = simpleSingleValueFrom(node)) {
2639 if (ast_is<Num_t, const_value_t>(value->value)) { 2639 if (ast_is<Num_t, ConstValue_t>(value->value)) {
2640 continue; 2640 continue;
2641 } 2641 }
2642 } 2642 }
@@ -2700,8 +2700,8 @@ private:
2700 if (chain->items.size() == 2) { 2700 if (chain->items.size() == 2) {
2701 if (auto callable = ast_cast<Callable_t>(chain->items.front())) { 2701 if (auto callable = ast_cast<Callable_t>(chain->items.front())) {
2702 ast_node* var = callable->item.as<Variable_t>(); 2702 ast_node* var = callable->item.as<Variable_t>();
2703 if (auto self = callable->item.as<SelfName_t>()) { 2703 if (auto self = callable->item.as<SelfItem_t>()) {
2704 var = self->name.as<self_t>(); 2704 var = self->name.as<Self_t>();
2705 } 2705 }
2706 BREAK_IF(var && isLocal(_parser.toString(var))); 2706 BREAK_IF(var && isLocal(_parser.toString(var)));
2707 } 2707 }
@@ -2834,7 +2834,7 @@ private:
2834 for (auto it = nodes.rbegin(); it != nodes.rend(); ++it) { 2834 for (auto it = nodes.rbegin(); it != nodes.rend(); ++it) {
2835 ns.push_back(*it); 2835 ns.push_back(*it);
2836 if (auto cond = ast_cast<IfCond_t>(*it)) { 2836 if (auto cond = ast_cast<IfCond_t>(*it)) {
2837 if (*it != nodes.front() && cond->condition.is<assignment_t>()) { 2837 if (*it != nodes.front() && cond->condition.is<Assignment_t>()) {
2838 auto x = *it; 2838 auto x = *it;
2839 auto newIf = x->new_ptr<If_t>(); 2839 auto newIf = x->new_ptr<If_t>();
2840 newIf->type.set(toAst<IfType_t>("if"sv, x)); 2840 newIf->type.set(toAst<IfType_t>("if"sv, x));
@@ -2888,7 +2888,7 @@ private:
2888 default: YUEE("AST node mismatch", node); break; 2888 default: YUEE("AST node mismatch", node); break;
2889 } 2889 }
2890 } 2890 }
2891 auto asmt = ifCondPairs.front().first->condition.as<assignment_t>(); 2891 auto asmt = ifCondPairs.front().first->condition.as<Assignment_t>();
2892 bool storingValue = false; 2892 bool storingValue = false;
2893 ast_ptr<false, ExpListAssign_t> extraAssignment; 2893 ast_ptr<false, ExpListAssign_t> extraAssignment;
2894 if (asmt) { 2894 if (asmt) {
@@ -3019,14 +3019,14 @@ private:
3019 3019
3020 void transform_pipe_exp(const node_container& values, str_list& out, ExpUsage usage, ExpList_t* assignList = nullptr) { 3020 void transform_pipe_exp(const node_container& values, str_list& out, ExpUsage usage, ExpList_t* assignList = nullptr) {
3021 if (values.size() == 1 && usage == ExpUsage::Closure) { 3021 if (values.size() == 1 && usage == ExpUsage::Closure) {
3022 transform_unary_exp(static_cast<unary_exp_t*>(values.front()), out); 3022 transform_unary_exp(static_cast<UnaryExp_t*>(values.front()), out);
3023 } else { 3023 } else {
3024 auto x = values.front(); 3024 auto x = values.front();
3025 auto arg = newExp(static_cast<unary_exp_t*>(x), x); 3025 auto arg = newExp(static_cast<UnaryExp_t*>(x), x);
3026 auto begin = values.begin(); 3026 auto begin = values.begin();
3027 begin++; 3027 begin++;
3028 for (auto it = begin; it != values.end(); ++it) { 3028 for (auto it = begin; it != values.end(); ++it) {
3029 auto unary = static_cast<unary_exp_t*>(*it); 3029 auto unary = static_cast<UnaryExp_t*>(*it);
3030 auto value = static_cast<Value_t*>(singleUnaryExpFrom(unary) ? unary->expos.back() : nullptr); 3030 auto value = static_cast<Value_t*>(singleUnaryExpFrom(unary) ? unary->expos.back() : nullptr);
3031 if (values.back() == *it && !unary->ops.empty() && usage == ExpUsage::Common) { 3031 if (values.back() == *it && !unary->ops.empty() && usage == ExpUsage::Common) {
3032 throw std::logic_error(_info.errorMessage("expression list is not supported here"sv, x)); 3032 throw std::logic_error(_info.errorMessage("expression list is not supported here"sv, x));
@@ -3119,7 +3119,7 @@ private:
3119 str_list temp; 3119 str_list temp;
3120 transform_pipe_exp(exp->pipeExprs.objects(), temp, ExpUsage::Closure); 3120 transform_pipe_exp(exp->pipeExprs.objects(), temp, ExpUsage::Closure);
3121 for (auto _opValue : exp->opValues.objects()) { 3121 for (auto _opValue : exp->opValues.objects()) {
3122 auto opValue = static_cast<exp_op_value_t*>(_opValue); 3122 auto opValue = static_cast<ExpOpValue_t*>(_opValue);
3123 transformBinaryOperator(opValue->op, temp); 3123 transformBinaryOperator(opValue->op, temp);
3124 transform_pipe_exp(opValue->pipeExprs.objects(), temp, ExpUsage::Closure); 3124 transform_pipe_exp(opValue->pipeExprs.objects(), temp, ExpUsage::Closure);
3125 } 3125 }
@@ -3140,7 +3140,7 @@ private:
3140 transform_pipe_exp(exp->pipeExprs.objects(), temp, ExpUsage::Closure); 3140 transform_pipe_exp(exp->pipeExprs.objects(), temp, ExpUsage::Closure);
3141 auto last = exp->opValues.objects().back(); 3141 auto last = exp->opValues.objects().back();
3142 for (auto _opValue : exp->opValues.objects()) { 3142 for (auto _opValue : exp->opValues.objects()) {
3143 auto opValue = static_cast<exp_op_value_t*>(_opValue); 3143 auto opValue = static_cast<ExpOpValue_t*>(_opValue);
3144 transformBinaryOperator(opValue->op, temp); 3144 transformBinaryOperator(opValue->op, temp);
3145 if (opValue == last) { 3145 if (opValue == last) {
3146 left->pipeExprs.dup(opValue->pipeExprs); 3146 left->pipeExprs.dup(opValue->pipeExprs);
@@ -3251,7 +3251,7 @@ private:
3251 auto item = value->item.get(); 3251 auto item = value->item.get();
3252 switch (item->getId()) { 3252 switch (item->getId()) {
3253 case id<SimpleValue_t>(): transformSimpleValue(static_cast<SimpleValue_t*>(item), out); break; 3253 case id<SimpleValue_t>(): transformSimpleValue(static_cast<SimpleValue_t*>(item), out); break;
3254 case id<simple_table_t>(): transform_simple_table(static_cast<simple_table_t*>(item), out); break; 3254 case id<SimpleTable_t>(): transform_simple_table(static_cast<SimpleTable_t*>(item), out); break;
3255 case id<ChainValue_t>(): transformChainValue(static_cast<ChainValue_t*>(item), out, ExpUsage::Closure); break; 3255 case id<ChainValue_t>(): transformChainValue(static_cast<ChainValue_t*>(item), out, ExpUsage::Closure); break;
3256 case id<String_t>(): transformString(static_cast<String_t*>(item), out); break; 3256 case id<String_t>(): transformString(static_cast<String_t*>(item), out); break;
3257 default: YUEE("AST node mismatch", value); break; 3257 default: YUEE("AST node mismatch", value); break;
@@ -3270,8 +3270,8 @@ private:
3270 } 3270 }
3271 break; 3271 break;
3272 } 3272 }
3273 case id<SelfName_t>(): { 3273 case id<SelfItem_t>(): {
3274 transformSelfName(static_cast<SelfName_t*>(item), out, invoke); 3274 transformSelfName(static_cast<SelfItem_t*>(item), out, invoke);
3275 globalVar("self"sv, item); 3275 globalVar("self"sv, item);
3276 break; 3276 break;
3277 } 3277 }
@@ -3296,7 +3296,7 @@ private:
3296 void transformSimpleValue(SimpleValue_t* simpleValue, str_list& out) { 3296 void transformSimpleValue(SimpleValue_t* simpleValue, str_list& out) {
3297 auto value = simpleValue->value.get(); 3297 auto value = simpleValue->value.get();
3298 switch (value->getId()) { 3298 switch (value->getId()) {
3299 case id<const_value_t>(): transform_const_value(static_cast<const_value_t*>(value), out); break; 3299 case id<ConstValue_t>(): transform_const_value(static_cast<ConstValue_t*>(value), out); break;
3300 case id<If_t>(): transformIf(static_cast<If_t*>(value), out, ExpUsage::Closure); break; 3300 case id<If_t>(): transformIf(static_cast<If_t*>(value), out, ExpUsage::Closure); break;
3301 case id<Switch_t>(): transformSwitch(static_cast<Switch_t*>(value), out, ExpUsage::Closure); break; 3301 case id<Switch_t>(): transformSwitch(static_cast<Switch_t*>(value), out, ExpUsage::Closure); break;
3302 case id<With_t>(): transformWithClosure(static_cast<With_t*>(value), out); break; 3302 case id<With_t>(): transformWithClosure(static_cast<With_t*>(value), out); break;
@@ -3306,7 +3306,7 @@ private:
3306 case id<While_t>(): transformWhileClosure(static_cast<While_t*>(value), out); break; 3306 case id<While_t>(): transformWhileClosure(static_cast<While_t*>(value), out); break;
3307 case id<Do_t>(): transformDo(static_cast<Do_t*>(value), out, ExpUsage::Closure); break; 3307 case id<Do_t>(): transformDo(static_cast<Do_t*>(value), out, ExpUsage::Closure); break;
3308 case id<Try_t>(): transformTry(static_cast<Try_t*>(value), out, ExpUsage::Closure); break; 3308 case id<Try_t>(): transformTry(static_cast<Try_t*>(value), out, ExpUsage::Closure); break;
3309 case id<unary_value_t>(): transform_unary_value(static_cast<unary_value_t*>(value), out); break; 3309 case id<UnaryValue_t>(): transform_unary_value(static_cast<UnaryValue_t*>(value), out); break;
3310 case id<TblComprehension_t>(): transformTblComprehension(static_cast<TblComprehension_t*>(value), out, ExpUsage::Closure); break; 3310 case id<TblComprehension_t>(): transformTblComprehension(static_cast<TblComprehension_t*>(value), out, ExpUsage::Closure); break;
3311 case id<TableLit_t>(): transformTableLit(static_cast<TableLit_t*>(value), out); break; 3311 case id<TableLit_t>(): transformTableLit(static_cast<TableLit_t*>(value), out); break;
3312 case id<Comprehension_t>(): transformComprehension(static_cast<Comprehension_t*>(value), out, ExpUsage::Closure); break; 3312 case id<Comprehension_t>(): transformComprehension(static_cast<Comprehension_t*>(value), out, ExpUsage::Closure); break;
@@ -3449,7 +3449,7 @@ private:
3449 auto funLit = x->new_ptr<FunLit_t>(); 3449 auto funLit = x->new_ptr<FunLit_t>();
3450 funLit->argsDef.set(backcall->argsDef); 3450 funLit->argsDef.set(backcall->argsDef);
3451 auto arrow = _parser.toString(backcall->arrow); 3451 auto arrow = _parser.toString(backcall->arrow);
3452 funLit->arrow.set(toAst<fn_arrow_t>(arrow == "<-"sv ? "->"sv : "=>"sv, x)); 3452 funLit->arrow.set(toAst<FnArrow_t>(arrow == "<-"sv ? "->"sv : "=>"sv, x));
3453 funLit->body.set(body); 3453 funLit->body.set(body);
3454 auto simpleValue = x->new_ptr<SimpleValue_t>(); 3454 auto simpleValue = x->new_ptr<SimpleValue_t>();
3455 simpleValue->value.set(funLit); 3455 simpleValue->value.set(funLit);
@@ -3502,8 +3502,8 @@ private:
3502 if (!local->collected) { 3502 if (!local->collected) {
3503 local->collected = true; 3503 local->collected = true;
3504 switch (local->item->getId()) { 3504 switch (local->item->getId()) {
3505 case id<local_flag_t>(): { 3505 case id<LocalFlag_t>(): {
3506 auto flag = static_cast<local_flag_t*>(local->item.get()); 3506 auto flag = static_cast<LocalFlag_t*>(local->item.get());
3507 LocalMode newMode = _parser.toString(flag) == "*"sv ? LocalMode::Any : LocalMode::Capital; 3507 LocalMode newMode = _parser.toString(flag) == "*"sv ? LocalMode::Any : LocalMode::Capital;
3508 if (int(newMode) > int(mode)) { 3508 if (int(newMode) > int(mode)) {
3509 mode = newMode; 3509 mode = newMode;
@@ -3516,8 +3516,8 @@ private:
3516 } 3516 }
3517 break; 3517 break;
3518 } 3518 }
3519 case id<local_values_t>(): { 3519 case id<LocalValues_t>(): {
3520 auto values = local->item.to<local_values_t>(); 3520 auto values = local->item.to<LocalValues_t>();
3521 for (auto name : values->nameList->names.objects()) { 3521 for (auto name : values->nameList->names.objects()) {
3522 local->forceDecls.push_back(_parser.toString(name)); 3522 local->forceDecls.push_back(_parser.toString(name));
3523 } 3523 }
@@ -3610,7 +3610,7 @@ private:
3610 auto x = last; 3610 auto x = last;
3611 auto expList = expListFrom(last); 3611 auto expList = expListFrom(last);
3612 BREAK_IF(!expList); 3612 BREAK_IF(!expList);
3613 BREAK_IF(last->appendix && !last->appendix->item.is<if_line_t>()); 3613 BREAK_IF(last->appendix && !last->appendix->item.is<IfLine_t>());
3614 auto expListLow = x->new_ptr<ExpListLow_t>(); 3614 auto expListLow = x->new_ptr<ExpListLow_t>();
3615 expListLow->exprs.dup(expList->exprs); 3615 expListLow->exprs.dup(expList->exprs);
3616 auto returnNode = x->new_ptr<Return_t>(); 3616 auto returnNode = x->new_ptr<Return_t>();
@@ -3625,7 +3625,7 @@ private:
3625 BREAK_IF(expListLow->exprs.size() != 1); 3625 BREAK_IF(expListLow->exprs.size() != 1);
3626 auto exp = static_cast<Exp_t*>(expListLow->exprs.back()); 3626 auto exp = static_cast<Exp_t*>(expListLow->exprs.back());
3627 BREAK_IF(!exp->opValues.empty()); 3627 BREAK_IF(!exp->opValues.empty());
3628 auto chainValue = exp->getByPath<unary_exp_t, Value_t, ChainValue_t>(); 3628 auto chainValue = exp->getByPath<UnaryExp_t, Value_t, ChainValue_t>();
3629 BREAK_IF(!chainValue); 3629 BREAK_IF(!chainValue);
3630 isMacro = isMacroChain(chainValue); 3630 isMacro = isMacroChain(chainValue);
3631 BLOCK_END 3631 BLOCK_END
@@ -3835,7 +3835,7 @@ private:
3835 if (argsDef) { 3835 if (argsDef) {
3836 for (auto def_ : argsDef->definitions.objects()) { 3836 for (auto def_ : argsDef->definitions.objects()) {
3837 auto def = static_cast<FnArgDef_t*>(def_); 3837 auto def = static_cast<FnArgDef_t*>(def_);
3838 if (def->name.is<SelfName_t>()) { 3838 if (def->name.is<SelfItem_t>()) {
3839 throw std::logic_error(_info.errorMessage("self name is not supported for macro function argument"sv, def->name)); 3839 throw std::logic_error(_info.errorMessage("self name is not supported for macro function argument"sv, def->name));
3840 } else { 3840 } else {
3841 std::string defVal; 3841 std::string defVal;
@@ -4000,7 +4000,7 @@ private:
4000 } 4000 }
4001 } 4001 }
4002 4002
4003 void transform_outer_var_shadow(outer_var_shadow_t* shadow) { 4003 void transform_outer_var_shadow(OuterVarShadow_t* shadow) {
4004 markVarShadowed(); 4004 markVarShadowed();
4005 if (shadow->varList) { 4005 if (shadow->varList) {
4006 for (auto name : shadow->varList->names.objects()) { 4006 for (auto name : shadow->varList->names.objects()) {
@@ -4025,7 +4025,7 @@ private:
4025 auto& arg = argItems.emplace_back(); 4025 auto& arg = argItems.emplace_back();
4026 switch (def->name->getId()) { 4026 switch (def->name->getId()) {
4027 case id<Variable_t>(): arg.name = _parser.toString(def->name); break; 4027 case id<Variable_t>(): arg.name = _parser.toString(def->name); break;
4028 case id<SelfName_t>(): { 4028 case id<SelfItem_t>(): {
4029 assignSelf = true; 4029 assignSelf = true;
4030 if (def->op) { 4030 if (def->op) {
4031 if (def->defaultValue) { 4031 if (def->defaultValue) {
@@ -4033,21 +4033,21 @@ private:
4033 } 4033 }
4034 arg.checkExistence = true; 4034 arg.checkExistence = true;
4035 } 4035 }
4036 auto selfName = static_cast<SelfName_t*>(def->name.get()); 4036 auto selfName = static_cast<SelfItem_t*>(def->name.get());
4037 switch (selfName->name->getId()) { 4037 switch (selfName->name->getId()) {
4038 case id<self_class_name_t>(): { 4038 case id<SelfClassName_t>(): {
4039 auto clsName = static_cast<self_class_name_t*>(selfName->name.get()); 4039 auto clsName = static_cast<SelfClassName_t*>(selfName->name.get());
4040 arg.name = _parser.toString(clsName->name); 4040 arg.name = _parser.toString(clsName->name);
4041 arg.assignSelf = _parser.toString(clsName); 4041 arg.assignSelf = _parser.toString(clsName);
4042 break; 4042 break;
4043 } 4043 }
4044 case id<self_name_t>(): { 4044 case id<SelfName_t>(): {
4045 auto sfName = static_cast<self_name_t*>(selfName->name.get()); 4045 auto sfName = static_cast<SelfName_t*>(selfName->name.get());
4046 arg.name = _parser.toString(sfName->name); 4046 arg.name = _parser.toString(sfName->name);
4047 arg.assignSelf = _parser.toString(sfName); 4047 arg.assignSelf = _parser.toString(sfName);
4048 break; 4048 break;
4049 } 4049 }
4050 case id<self_t>(): 4050 case id<Self_t>():
4051 arg.name = "self"sv; 4051 arg.name = "self"sv;
4052 if (def->op) throw std::logic_error(_info.errorMessage("can only check existence for assigning self field"sv, selfName->name)); 4052 if (def->op) throw std::logic_error(_info.errorMessage("can only check existence for assigning self field"sv, selfName->name));
4053 break; 4053 break;
@@ -4105,12 +4105,12 @@ private:
4105 out.push_back(join(temp)); 4105 out.push_back(join(temp));
4106 } 4106 }
4107 4107
4108 void transformSelfName(SelfName_t* selfName, str_list& out, const ast_sel<false, Invoke_t, InvokeArgs_t>& invoke = {}) { 4108 void transformSelfName(SelfItem_t* selfName, str_list& out, const ast_sel<false, Invoke_t, InvokeArgs_t>& invoke = {}) {
4109 auto x = selfName; 4109 auto x = selfName;
4110 auto name = selfName->name.get(); 4110 auto name = selfName->name.get();
4111 switch (name->getId()) { 4111 switch (name->getId()) {
4112 case id<self_class_name_t>(): { 4112 case id<SelfClassName_t>(): {
4113 auto clsName = static_cast<self_class_name_t*>(name); 4113 auto clsName = static_cast<SelfClassName_t*>(name);
4114 auto nameStr = _parser.toString(clsName->name); 4114 auto nameStr = _parser.toString(clsName->name);
4115 if (LuaKeywords.find(nameStr) != LuaKeywords.end()) { 4115 if (LuaKeywords.find(nameStr) != LuaKeywords.end()) {
4116 out.push_back("self.__class[\""s + nameStr + "\"]"s); 4116 out.push_back("self.__class[\""s + nameStr + "\"]"s);
@@ -4127,11 +4127,11 @@ private:
4127 } 4127 }
4128 break; 4128 break;
4129 } 4129 }
4130 case id<self_class_t>(): 4130 case id<SelfClass_t>():
4131 out.push_back("self.__class"s); 4131 out.push_back("self.__class"s);
4132 break; 4132 break;
4133 case id<self_name_t>(): { 4133 case id<SelfName_t>(): {
4134 auto sfName = static_cast<self_class_name_t*>(name); 4134 auto sfName = static_cast<SelfClassName_t*>(name);
4135 auto nameStr = _parser.toString(sfName->name); 4135 auto nameStr = _parser.toString(sfName->name);
4136 if (LuaKeywords.find(nameStr) != LuaKeywords.end()) { 4136 if (LuaKeywords.find(nameStr) != LuaKeywords.end()) {
4137 out.push_back("self[\""s + nameStr + "\"]"s); 4137 out.push_back("self[\""s + nameStr + "\"]"s);
@@ -4148,7 +4148,7 @@ private:
4148 } 4148 }
4149 break; 4149 break;
4150 } 4150 }
4151 case id<self_t>(): 4151 case id<Self_t>():
4152 out.push_back("self"s); 4152 out.push_back("self"s);
4153 break; 4153 break;
4154 default: YUEE("AST node mismatch", name); break; 4154 default: YUEE("AST node mismatch", name); break;
@@ -4157,7 +4157,7 @@ private:
4157 4157
4158 bool transformChainEndWithEOP(const node_container& chainList, str_list& out, ExpUsage usage, ExpList_t* assignList) { 4158 bool transformChainEndWithEOP(const node_container& chainList, str_list& out, ExpUsage usage, ExpList_t* assignList) {
4159 auto x = chainList.front(); 4159 auto x = chainList.front();
4160 if (ast_is<existential_op_t>(chainList.back())) { 4160 if (ast_is<ExistentialOp_t>(chainList.back())) {
4161 auto parens = x->new_ptr<Parens_t>(); 4161 auto parens = x->new_ptr<Parens_t>();
4162 { 4162 {
4163 auto chainValue = x->new_ptr<ChainValue_t>(); 4163 auto chainValue = x->new_ptr<ChainValue_t>();
@@ -4200,7 +4200,7 @@ private:
4200 } 4200 }
4201 4201
4202 bool transformChainWithEOP(const node_container& chainList, str_list& out, ExpUsage usage, ExpList_t* assignList, bool optionalDestruct) { 4202 bool transformChainWithEOP(const node_container& chainList, str_list& out, ExpUsage usage, ExpList_t* assignList, bool optionalDestruct) {
4203 auto opIt = std::find_if(chainList.begin(), chainList.end(), [](ast_node* node) { return ast_is<existential_op_t>(node); }); 4203 auto opIt = std::find_if(chainList.begin(), chainList.end(), [](ast_node* node) { return ast_is<ExistentialOp_t>(node); });
4204 if (opIt != chainList.end()) { 4204 if (opIt != chainList.end()) {
4205 auto x = chainList.front(); 4205 auto x = chainList.front();
4206 str_list temp; 4206 str_list temp;
@@ -4218,9 +4218,9 @@ private:
4218 BLOCK_START 4218 BLOCK_START
4219 auto back = ast_cast<Callable_t>(partOne->items.back()); 4219 auto back = ast_cast<Callable_t>(partOne->items.back());
4220 BREAK_IF(!back); 4220 BREAK_IF(!back);
4221 auto selfName = ast_cast<SelfName_t>(back->item); 4221 auto selfName = ast_cast<SelfItem_t>(back->item);
4222 BREAK_IF(!selfName); 4222 BREAK_IF(!selfName);
4223 if (auto sname = ast_cast<self_name_t>(selfName->name)) { 4223 if (auto sname = ast_cast<SelfName_t>(selfName->name)) {
4224 auto colonItem = x->new_ptr<ColonChainItem_t>(); 4224 auto colonItem = x->new_ptr<ColonChainItem_t>();
4225 colonItem->name.set(sname->name); 4225 colonItem->name.set(sname->name);
4226 partOne->items.pop_back(); 4226 partOne->items.pop_back();
@@ -4228,7 +4228,7 @@ private:
4228 partOne->items.push_back(colonItem); 4228 partOne->items.push_back(colonItem);
4229 break; 4229 break;
4230 } 4230 }
4231 if (auto cname = ast_cast<self_class_name_t>(selfName->name)) { 4231 if (auto cname = ast_cast<SelfClassName_t>(selfName->name)) {
4232 auto colonItem = x->new_ptr<ColonChainItem_t>(); 4232 auto colonItem = x->new_ptr<ColonChainItem_t>();
4233 colonItem->name.set(cname->name); 4233 colonItem->name.set(cname->name);
4234 partOne->items.pop_back(); 4234 partOne->items.pop_back();
@@ -4662,11 +4662,11 @@ private:
4662 auto followItem = next != chainList.end() ? *next : nullptr; 4662 auto followItem = next != chainList.end() ? *next : nullptr;
4663 if (current != chainList.begin()) { 4663 if (current != chainList.begin()) {
4664 --current; 4664 --current;
4665 if (!ast_is<existential_op_t>(*current)) { 4665 if (!ast_is<ExistentialOp_t>(*current)) {
4666 ++current; 4666 ++current;
4667 } 4667 }
4668 } 4668 }
4669 if (ast_is<existential_op_t>(followItem)) { 4669 if (ast_is<ExistentialOp_t>(followItem)) {
4670 ++next; 4670 ++next;
4671 followItem = next != chainList.end() ? *next : nullptr; 4671 followItem = next != chainList.end() ? *next : nullptr;
4672 --next; 4672 --next;
@@ -4707,8 +4707,8 @@ private:
4707 auto name = _parser.toString(colonItem->name); 4707 auto name = _parser.toString(colonItem->name);
4708 auto chainValue = x->new_ptr<ChainValue_t>(); 4708 auto chainValue = x->new_ptr<ChainValue_t>();
4709 chainValue->items.push_back(toAst<Callable_t>(callVar, x)); 4709 chainValue->items.push_back(toAst<Callable_t>(callVar, x));
4710 if (ast_is<existential_op_t>(*current)) { 4710 if (ast_is<ExistentialOp_t>(*current)) {
4711 chainValue->items.push_back(x->new_ptr<existential_op_t>()); 4711 chainValue->items.push_back(x->new_ptr<ExistentialOp_t>());
4712 } 4712 }
4713 chainValue->items.push_back(toAst<Exp_t>('\"' + name + '\"', x)); 4713 chainValue->items.push_back(toAst<Exp_t>('\"' + name + '\"', x));
4714 if (auto invoke = ast_cast<Invoke_t>(followItem)) { 4714 if (auto invoke = ast_cast<Invoke_t>(followItem)) {
@@ -4789,8 +4789,8 @@ private:
4789 temp.back() = (temp.back().front() == '[' ? "[ "s : "["s) + temp.back() + ']'; 4789 temp.back() = (temp.back().front() == '[' ? "[ "s : "["s) + temp.back() + ']';
4790 break; 4790 break;
4791 case id<InvokeArgs_t>(): transformInvokeArgs(static_cast<InvokeArgs_t*>(item), temp); break; 4791 case id<InvokeArgs_t>(): transformInvokeArgs(static_cast<InvokeArgs_t*>(item), temp); break;
4792 case id<table_appending_op_t>(): 4792 case id<TableAppendingOp_t>():
4793 transform_table_appending_op(static_cast<table_appending_op_t*>(item), temp); 4793 transform_table_appending_op(static_cast<TableAppendingOp_t*>(item), temp);
4794 break; 4794 break;
4795 default: YUEE("AST node mismatch", item); break; 4795 default: YUEE("AST node mismatch", item); break;
4796 } 4796 }
@@ -4925,7 +4925,7 @@ private:
4925 auto exp = static_cast<Exp_t*>(arg); 4925 auto exp = static_cast<Exp_t*>(arg);
4926 BLOCK_START 4926 BLOCK_START
4927 BREAK_IF(!exp->opValues.empty()); 4927 BREAK_IF(!exp->opValues.empty());
4928 auto chainValue = exp->getByPath<unary_exp_t, Value_t, ChainValue_t>(); 4928 auto chainValue = exp->getByPath<UnaryExp_t, Value_t, ChainValue_t>();
4929 BREAK_IF(!chainValue); 4929 BREAK_IF(!chainValue);
4930 BREAK_IF(!isMacroChain(chainValue)); 4930 BREAK_IF(!isMacroChain(chainValue));
4931 str = std::get<1>(expandMacroStr(chainValue)); 4931 str = std::get<1>(expandMacroStr(chainValue));
@@ -5107,11 +5107,11 @@ private:
5107 for (auto stmt_ : block->statements.objects()) { 5107 for (auto stmt_ : block->statements.objects()) {
5108 auto stmt = static_cast<Statement_t*>(stmt_); 5108 auto stmt = static_cast<Statement_t*>(stmt_);
5109 if (auto global = stmt->content.as<Global_t>()) { 5109 if (auto global = stmt->content.as<Global_t>()) {
5110 if (global->item.is<global_op_t>()) { 5110 if (global->item.is<GlobalOp_t>()) {
5111 throw std::logic_error(_info.errorMessage("can not insert global statement with wildcard operator from macro"sv, x)); 5111 throw std::logic_error(_info.errorMessage("can not insert global statement with wildcard operator from macro"sv, x));
5112 } 5112 }
5113 } else if (auto local = stmt->content.as<Local_t>()) { 5113 } else if (auto local = stmt->content.as<Local_t>()) {
5114 if (local->item.is<local_flag_t>()) { 5114 if (local->item.is<LocalFlag_t>()) {
5115 throw std::logic_error(_info.errorMessage("can not insert local statement with wildcard operator from macro"sv, x)); 5115 throw std::logic_error(_info.errorMessage("can not insert local statement with wildcard operator from macro"sv, x));
5116 } 5116 }
5117 } 5117 }
@@ -5214,7 +5214,7 @@ private:
5214 throw std::logic_error(_info.errorMessage("slice syntax not supported here"sv, slice)); 5214 throw std::logic_error(_info.errorMessage("slice syntax not supported here"sv, slice));
5215 } 5215 }
5216 5216
5217 void transform_table_appending_op(table_appending_op_t* op, str_list&) { 5217 void transform_table_appending_op(TableAppendingOp_t* op, str_list&) {
5218 throw std::logic_error(_info.errorMessage("table appending syntax not supported here"sv, op)); 5218 throw std::logic_error(_info.errorMessage("table appending syntax not supported here"sv, op));
5219 } 5219 }
5220 5220
@@ -5233,7 +5233,7 @@ private:
5233 out.push_back('(' + join(temp, ", "sv) + ')'); 5233 out.push_back('(' + join(temp, ", "sv) + ')');
5234 } 5234 }
5235 5235
5236 void transform_unary_value(unary_value_t* unary_value, str_list& out) { 5236 void transform_unary_value(UnaryValue_t* unary_value, str_list& out) {
5237 str_list temp; 5237 str_list temp;
5238 for (auto _op : unary_value->ops.objects()) { 5238 for (auto _op : unary_value->ops.objects()) {
5239 std::string op = _parser.toString(_op); 5239 std::string op = _parser.toString(_op);
@@ -5246,7 +5246,7 @@ private:
5246 out.push_back(join(temp)); 5246 out.push_back(join(temp));
5247 } 5247 }
5248 5248
5249 void transform_unary_exp(unary_exp_t* unary_exp, str_list& out) { 5249 void transform_unary_exp(UnaryExp_t* unary_exp, str_list& out) {
5250 if (unary_exp->ops.empty() && unary_exp->expos.size() == 1) { 5250 if (unary_exp->ops.empty() && unary_exp->expos.size() == 1) {
5251 transformValue(static_cast<Value_t*>(unary_exp->expos.back()), out); 5251 transformValue(static_cast<Value_t*>(unary_exp->expos.back()), out);
5252 return; 5252 return;
@@ -5341,29 +5341,29 @@ private:
5341 transformForEach(forEach, temp); 5341 transformForEach(forEach, temp);
5342 break; 5342 break;
5343 } 5343 }
5344 case id<variable_pair_t>(): 5344 case id<VariablePair_t>():
5345 case id<variable_pair_def_t>(): { 5345 case id<VariablePairDef_t>(): {
5346 if (auto pair = ast_cast<variable_pair_def_t>(item)) { 5346 if (auto pair = ast_cast<VariablePairDef_t>(item)) {
5347 if (pair->defVal) { 5347 if (pair->defVal) {
5348 throw std::logic_error(_info.errorMessage("invalid default value here"sv, pair->defVal)); 5348 throw std::logic_error(_info.errorMessage("invalid default value here"sv, pair->defVal));
5349 } 5349 }
5350 item = pair->pair.get(); 5350 item = pair->pair.get();
5351 } 5351 }
5352 auto variablePair = static_cast<variable_pair_t*>(item); 5352 auto variablePair = static_cast<VariablePair_t*>(item);
5353 auto nameStr = _parser.toString(variablePair->name); 5353 auto nameStr = _parser.toString(variablePair->name);
5354 auto assignment = toAst<ExpListAssign_t>(tableVar + '.' + nameStr + '=' + nameStr, item); 5354 auto assignment = toAst<ExpListAssign_t>(tableVar + '.' + nameStr + '=' + nameStr, item);
5355 transformAssignment(assignment, temp); 5355 transformAssignment(assignment, temp);
5356 break; 5356 break;
5357 } 5357 }
5358 case id<normal_pair_t>(): 5358 case id<NormalPair_t>():
5359 case id<normal_pair_def_t>(): { 5359 case id<NormalPairDef_t>(): {
5360 if (auto pair = ast_cast<normal_pair_def_t>(item)) { 5360 if (auto pair = ast_cast<NormalPairDef_t>(item)) {
5361 if (pair->defVal) { 5361 if (pair->defVal) {
5362 throw std::logic_error(_info.errorMessage("invalid default value here"sv, pair->defVal)); 5362 throw std::logic_error(_info.errorMessage("invalid default value here"sv, pair->defVal));
5363 } 5363 }
5364 item = pair->pair.get(); 5364 item = pair->pair.get();
5365 } 5365 }
5366 auto normalPair = static_cast<normal_pair_t*>(item); 5366 auto normalPair = static_cast<NormalPair_t*>(item);
5367 auto assignment = toAst<ExpListAssign_t>(tableVar + "=nil"s, item); 5367 auto assignment = toAst<ExpListAssign_t>(tableVar + "=nil"s, item);
5368 auto chainValue = singleValueFrom(ast_to<Exp_t>(assignment->expList->exprs.front()))->item.to<ChainValue_t>(); 5368 auto chainValue = singleValueFrom(ast_to<Exp_t>(assignment->expList->exprs.front()))->item.to<ChainValue_t>();
5369 auto key = normalPair->key.get(); 5369 auto key = normalPair->key.get();
@@ -5376,7 +5376,7 @@ private:
5376 dotItem->name.set(name); 5376 dotItem->name.set(name);
5377 chainItem = dotItem.get(); 5377 chainItem = dotItem.get();
5378 } else { 5378 } else {
5379 auto selfName = keyName->name.to<SelfName_t>(); 5379 auto selfName = keyName->name.to<SelfItem_t>();
5380 auto callable = x->new_ptr<Callable_t>(); 5380 auto callable = x->new_ptr<Callable_t>();
5381 callable->item.set(selfName); 5381 callable->item.set(selfName);
5382 auto chainValue = x->new_ptr<ChainValue_t>(); 5382 auto chainValue = x->new_ptr<ChainValue_t>();
@@ -5407,9 +5407,9 @@ private:
5407 break; 5407 break;
5408 } 5408 }
5409 case id<Exp_t>(): 5409 case id<Exp_t>():
5410 case id<normal_def_t>(): { 5410 case id<NormalDef_t>(): {
5411 auto current = item; 5411 auto current = item;
5412 if (auto pair = ast_cast<normal_def_t>(item)) { 5412 if (auto pair = ast_cast<NormalDef_t>(item)) {
5413 if (pair->defVal) { 5413 if (pair->defVal) {
5414 throw std::logic_error(_info.errorMessage("invalid default value here"sv, pair->defVal)); 5414 throw std::logic_error(_info.errorMessage("invalid default value here"sv, pair->defVal));
5415 } 5415 }
@@ -5457,29 +5457,29 @@ private:
5457 transformAssignment(assignment, temp); 5457 transformAssignment(assignment, temp);
5458 break; 5458 break;
5459 } 5459 }
5460 case id<meta_variable_pair_t>(): 5460 case id<MetaVariablePair_t>():
5461 case id<meta_variable_pair_def_t>(): { 5461 case id<MetaVariablePairDef_t>(): {
5462 if (auto pair = ast_cast<meta_variable_pair_def_t>(item)) { 5462 if (auto pair = ast_cast<MetaVariablePairDef_t>(item)) {
5463 if (pair->defVal) { 5463 if (pair->defVal) {
5464 throw std::logic_error(_info.errorMessage("invalid default value here"sv, pair->defVal)); 5464 throw std::logic_error(_info.errorMessage("invalid default value here"sv, pair->defVal));
5465 } 5465 }
5466 item = pair->pair.get(); 5466 item = pair->pair.get();
5467 } 5467 }
5468 auto metaVarPair = static_cast<meta_variable_pair_t*>(item); 5468 auto metaVarPair = static_cast<MetaVariablePair_t*>(item);
5469 auto nameStr = _parser.toString(metaVarPair->name); 5469 auto nameStr = _parser.toString(metaVarPair->name);
5470 auto assignment = toAst<ExpListAssign_t>(tableVar + ".<"s + nameStr + ">="s + nameStr, item); 5470 auto assignment = toAst<ExpListAssign_t>(tableVar + ".<"s + nameStr + ">="s + nameStr, item);
5471 transformAssignment(assignment, temp); 5471 transformAssignment(assignment, temp);
5472 break; 5472 break;
5473 } 5473 }
5474 case id<meta_normal_pair_t>(): 5474 case id<MetaNormalPair_t>():
5475 case id<meta_normal_pair_def_t>(): { 5475 case id<MetaNormalPairDef_t>(): {
5476 if (auto pair = ast_cast<meta_normal_pair_def_t>(item)) { 5476 if (auto pair = ast_cast<MetaNormalPairDef_t>(item)) {
5477 if (pair->defVal) { 5477 if (pair->defVal) {
5478 throw std::logic_error(_info.errorMessage("invalid default value here"sv, pair->defVal)); 5478 throw std::logic_error(_info.errorMessage("invalid default value here"sv, pair->defVal));
5479 } 5479 }
5480 item = pair->pair.get(); 5480 item = pair->pair.get();
5481 } 5481 }
5482 auto metaNormalPair = static_cast<meta_normal_pair_t*>(item); 5482 auto metaNormalPair = static_cast<MetaNormalPair_t*>(item);
5483 auto assignment = toAst<ExpListAssign_t>(tableVar + "=nil"s, item); 5483 auto assignment = toAst<ExpListAssign_t>(tableVar + "=nil"s, item);
5484 auto chainValue = singleValueFrom(ast_to<Exp_t>(assignment->expList->exprs.front()))->item.to<ChainValue_t>(); 5484 auto chainValue = singleValueFrom(ast_to<Exp_t>(assignment->expList->exprs.front()))->item.to<ChainValue_t>();
5485 auto key = metaNormalPair->key.get(); 5485 auto key = metaNormalPair->key.get();
@@ -5554,45 +5554,45 @@ private:
5554 auto x = values.front(); 5554 auto x = values.front();
5555 str_list temp; 5555 str_list temp;
5556 incIndentOffset(); 5556 incIndentOffset();
5557 auto metatable = x->new_ptr<simple_table_t>(); 5557 auto metatable = x->new_ptr<SimpleTable_t>();
5558 ast_sel<false, Exp_t, TableBlock_t> metatableItem; 5558 ast_sel<false, Exp_t, TableBlock_t> metatableItem;
5559 for (auto value : values) { 5559 for (auto value : values) {
5560 auto item = value; 5560 auto item = value;
5561 switch (item->getId()) { 5561 switch (item->getId()) {
5562 case id<variable_pair_def_t>(): { 5562 case id<VariablePairDef_t>(): {
5563 auto pair = static_cast<variable_pair_def_t*>(item); 5563 auto pair = static_cast<VariablePairDef_t*>(item);
5564 if (pair->defVal) { 5564 if (pair->defVal) {
5565 throw std::logic_error(_info.errorMessage("invalid default value"sv, pair->defVal)); 5565 throw std::logic_error(_info.errorMessage("invalid default value"sv, pair->defVal));
5566 } 5566 }
5567 item = pair->pair.get(); 5567 item = pair->pair.get();
5568 break; 5568 break;
5569 } 5569 }
5570 case id<normal_pair_def_t>(): { 5570 case id<NormalPairDef_t>(): {
5571 auto pair = static_cast<normal_pair_def_t*>(item); 5571 auto pair = static_cast<NormalPairDef_t*>(item);
5572 if (pair->defVal) { 5572 if (pair->defVal) {
5573 throw std::logic_error(_info.errorMessage("invalid default value"sv, pair->defVal)); 5573 throw std::logic_error(_info.errorMessage("invalid default value"sv, pair->defVal));
5574 } 5574 }
5575 item = pair->pair.get(); 5575 item = pair->pair.get();
5576 break; 5576 break;
5577 } 5577 }
5578 case id<meta_variable_pair_def_t>(): { 5578 case id<MetaVariablePairDef_t>(): {
5579 auto pair = static_cast<meta_variable_pair_def_t*>(item); 5579 auto pair = static_cast<MetaVariablePairDef_t*>(item);
5580 if (pair->defVal) { 5580 if (pair->defVal) {
5581 throw std::logic_error(_info.errorMessage("invalid default value"sv, pair->defVal)); 5581 throw std::logic_error(_info.errorMessage("invalid default value"sv, pair->defVal));
5582 } 5582 }
5583 item = pair->pair.get(); 5583 item = pair->pair.get();
5584 break; 5584 break;
5585 } 5585 }
5586 case id<meta_normal_pair_def_t>(): { 5586 case id<MetaNormalPairDef_t>(): {
5587 auto pair = static_cast<meta_normal_pair_def_t*>(item); 5587 auto pair = static_cast<MetaNormalPairDef_t*>(item);
5588 if (pair->defVal) { 5588 if (pair->defVal) {
5589 throw std::logic_error(_info.errorMessage("invalid default value"sv, pair->defVal)); 5589 throw std::logic_error(_info.errorMessage("invalid default value"sv, pair->defVal));
5590 } 5590 }
5591 item = pair->pair.get(); 5591 item = pair->pair.get();
5592 break; 5592 break;
5593 } 5593 }
5594 case id<normal_def_t>(): { 5594 case id<NormalDef_t>(): {
5595 auto pair = static_cast<normal_def_t*>(item); 5595 auto pair = static_cast<NormalDef_t*>(item);
5596 if (pair->defVal) { 5596 if (pair->defVal) {
5597 throw std::logic_error(_info.errorMessage("invalid default value"sv, pair->defVal)); 5597 throw std::logic_error(_info.errorMessage("invalid default value"sv, pair->defVal));
5598 } 5598 }
@@ -5603,27 +5603,27 @@ private:
5603 bool isMetamethod = false; 5603 bool isMetamethod = false;
5604 switch (item->getId()) { 5604 switch (item->getId()) {
5605 case id<Exp_t>(): transformExp(static_cast<Exp_t*>(item), temp, ExpUsage::Closure); break; 5605 case id<Exp_t>(): transformExp(static_cast<Exp_t*>(item), temp, ExpUsage::Closure); break;
5606 case id<variable_pair_t>(): transform_variable_pair(static_cast<variable_pair_t*>(item), temp); break; 5606 case id<VariablePair_t>(): transform_variable_pair(static_cast<VariablePair_t*>(item), temp); break;
5607 case id<normal_pair_t>(): transform_normal_pair(static_cast<normal_pair_t*>(item), temp, false); break; 5607 case id<NormalPair_t>(): transform_normal_pair(static_cast<NormalPair_t*>(item), temp, false); break;
5608 case id<TableBlockIndent_t>(): transformTableBlockIndent(static_cast<TableBlockIndent_t*>(item), temp); break; 5608 case id<TableBlockIndent_t>(): transformTableBlockIndent(static_cast<TableBlockIndent_t*>(item), temp); break;
5609 case id<TableBlock_t>(): transformTableBlock(static_cast<TableBlock_t*>(item), temp); break; 5609 case id<TableBlock_t>(): transformTableBlock(static_cast<TableBlock_t*>(item), temp); break;
5610 case id<meta_variable_pair_t>(): { 5610 case id<MetaVariablePair_t>(): {
5611 isMetamethod = true; 5611 isMetamethod = true;
5612 auto mp = static_cast<meta_variable_pair_t*>(item); 5612 auto mp = static_cast<MetaVariablePair_t*>(item);
5613 if (metatableItem) { 5613 if (metatableItem) {
5614 throw std::logic_error(_info.errorMessage("too many metatable declarations"sv, mp->name)); 5614 throw std::logic_error(_info.errorMessage("too many metatable declarations"sv, mp->name));
5615 } 5615 }
5616 auto name = _parser.toString(mp->name); 5616 auto name = _parser.toString(mp->name);
5617 checkMetamethod(name, mp->name); 5617 checkMetamethod(name, mp->name);
5618 _buf << "__"sv << name << ':' << name; 5618 _buf << "__"sv << name << ':' << name;
5619 auto newPair = toAst<normal_pair_t>(clearBuf(), item); 5619 auto newPair = toAst<NormalPair_t>(clearBuf(), item);
5620 metatable->pairs.push_back(newPair); 5620 metatable->pairs.push_back(newPair);
5621 break; 5621 break;
5622 } 5622 }
5623 case id<meta_normal_pair_t>(): { 5623 case id<MetaNormalPair_t>(): {
5624 isMetamethod = true; 5624 isMetamethod = true;
5625 auto mp = static_cast<meta_normal_pair_t*>(item); 5625 auto mp = static_cast<MetaNormalPair_t*>(item);
5626 auto newPair = item->new_ptr<normal_pair_t>(); 5626 auto newPair = item->new_ptr<NormalPair_t>();
5627 if (mp->key) { 5627 if (mp->key) {
5628 if (metatableItem) { 5628 if (metatableItem) {
5629 throw std::logic_error(_info.errorMessage("too many metatable declarations"sv, mp->key)); 5629 throw std::logic_error(_info.errorMessage("too many metatable declarations"sv, mp->key));
@@ -5864,8 +5864,8 @@ private:
5864 } 5864 }
5865 } 5865 }
5866 switch (loopTarget->getId()) { 5866 switch (loopTarget->getId()) {
5867 case id<star_exp_t>(): { 5867 case id<StarExp_t>(): {
5868 auto star_exp = static_cast<star_exp_t*>(loopTarget); 5868 auto star_exp = static_cast<StarExp_t*>(loopTarget);
5869 auto listVar = singleVariableFrom(star_exp->value, true); 5869 auto listVar = singleVariableFrom(star_exp->value, true);
5870 if (!isLocal(listVar)) listVar.clear(); 5870 if (!isLocal(listVar)) listVar.clear();
5871 auto indexVar = getUnusedName("_index_"sv); 5871 auto indexVar = getUnusedName("_index_"sv);
@@ -6011,7 +6011,7 @@ private:
6011 if (auto tableBlock = ast_cast<TableBlock_t>(lastArg)) { 6011 if (auto tableBlock = ast_cast<TableBlock_t>(lastArg)) {
6012 lastTable = &tableBlock->values; 6012 lastTable = &tableBlock->values;
6013 } else if (auto value = singleValueFrom(lastArg)) { 6013 } else if (auto value = singleValueFrom(lastArg)) {
6014 if (auto simpleTable = ast_cast<simple_table_t>(value->item)) { 6014 if (auto simpleTable = ast_cast<SimpleTable_t>(value->item)) {
6015 lastTable = &simpleTable->pairs; 6015 lastTable = &simpleTable->pairs;
6016 } 6016 }
6017 } 6017 }
@@ -6020,7 +6020,7 @@ private:
6020 invokeArgs->args.pop_back(); 6020 invokeArgs->args.pop_back();
6021 while (!invokeArgs->args.empty()) { 6021 while (!invokeArgs->args.empty()) {
6022 if (Value_t* value = singleValueFrom(invokeArgs->args.back())) { 6022 if (Value_t* value = singleValueFrom(invokeArgs->args.back())) {
6023 if (auto tb = value->item.as<simple_table_t>()) { 6023 if (auto tb = value->item.as<SimpleTable_t>()) {
6024 const auto& ps = tb->pairs.objects(); 6024 const auto& ps = tb->pairs.objects();
6025 for (auto it = ps.rbegin(); it != ps.rend(); ++it) { 6025 for (auto it = ps.rbegin(); it != ps.rend(); ++it) {
6026 lastTable->push_front(*it); 6026 lastTable->push_front(*it);
@@ -6045,7 +6045,7 @@ private:
6045 out.push_back('(' + join(temp, ", "sv) + ')'); 6045 out.push_back('(' + join(temp, ", "sv) + ')');
6046 } 6046 }
6047 6047
6048 void transformForHead(Variable_t* var, Exp_t* startVal, Exp_t* stopVal, for_step_value_t* stepVal, str_list& out) { 6048 void transformForHead(Variable_t* var, Exp_t* startVal, Exp_t* stopVal, ForStepValue_t* stepVal, str_list& out) {
6049 str_list temp; 6049 str_list temp;
6050 std::string varName = _parser.toString(var); 6050 std::string varName = _parser.toString(var);
6051 transformExp(startVal, temp, ExpUsage::Closure); 6051 transformExp(startVal, temp, ExpUsage::Closure);
@@ -6421,7 +6421,7 @@ private:
6421 out.push_back(join(temp)); 6421 out.push_back(join(temp));
6422 } 6422 }
6423 6423
6424 void transform_variable_pair(variable_pair_t* pair, str_list& out) { 6424 void transform_variable_pair(VariablePair_t* pair, str_list& out) {
6425 auto name = _parser.toString(pair->name); 6425 auto name = _parser.toString(pair->name);
6426 if (_config.lintGlobalVariable && !isLocal(name)) { 6426 if (_config.lintGlobalVariable && !isLocal(name)) {
6427 if (_globals.find(name) == _globals.end()) { 6427 if (_globals.find(name) == _globals.end()) {
@@ -6431,14 +6431,14 @@ private:
6431 out.push_back(name + " = "s + name); 6431 out.push_back(name + " = "s + name);
6432 } 6432 }
6433 6433
6434 void transform_normal_pair(normal_pair_t* pair, str_list& out, bool assignClass) { 6434 void transform_normal_pair(NormalPair_t* pair, str_list& out, bool assignClass) {
6435 auto key = pair->key.get(); 6435 auto key = pair->key.get();
6436 str_list temp; 6436 str_list temp;
6437 switch (key->getId()) { 6437 switch (key->getId()) {
6438 case id<KeyName_t>(): { 6438 case id<KeyName_t>(): {
6439 auto keyName = static_cast<KeyName_t*>(key); 6439 auto keyName = static_cast<KeyName_t*>(key);
6440 transformKeyName(keyName, temp); 6440 transformKeyName(keyName, temp);
6441 if (keyName->name.is<SelfName_t>() && !assignClass) { 6441 if (keyName->name.is<SelfItem_t>() && !assignClass) {
6442 temp.back() = '[' + temp.back() + ']'; 6442 temp.back() = '[' + temp.back() + ']';
6443 } 6443 }
6444 break; 6444 break;
@@ -6481,8 +6481,8 @@ private:
6481 void transformKeyName(KeyName_t* keyName, str_list& out) { 6481 void transformKeyName(KeyName_t* keyName, str_list& out) {
6482 auto name = keyName->name.get(); 6482 auto name = keyName->name.get();
6483 switch (name->getId()) { 6483 switch (name->getId()) {
6484 case id<SelfName_t>(): 6484 case id<SelfItem_t>():
6485 transformSelfName(static_cast<SelfName_t*>(name), out); 6485 transformSelfName(static_cast<SelfItem_t*>(name), out);
6486 break; 6486 break;
6487 case id<Name_t>(): { 6487 case id<Name_t>(): {
6488 auto nameStr = _parser.toString(name); 6488 auto nameStr = _parser.toString(name);
@@ -6513,10 +6513,10 @@ private:
6513 void transformDoubleString(DoubleString_t* doubleString, str_list& out) { 6513 void transformDoubleString(DoubleString_t* doubleString, str_list& out) {
6514 str_list temp; 6514 str_list temp;
6515 for (auto _seg : doubleString->segments.objects()) { 6515 for (auto _seg : doubleString->segments.objects()) {
6516 auto seg = static_cast<double_string_content_t*>(_seg); 6516 auto seg = static_cast<DoubleStringContent_t*>(_seg);
6517 auto content = seg->content.get(); 6517 auto content = seg->content.get();
6518 switch (content->getId()) { 6518 switch (content->getId()) {
6519 case id<double_string_inner_t>(): { 6519 case id<DoubleStringInner_t>(): {
6520 auto str = _parser.toString(content); 6520 auto str = _parser.toString(content);
6521 Utils::replace(str, "\r\n"sv, "\n"); 6521 Utils::replace(str, "\r\n"sv, "\n");
6522 Utils::replace(str, "\n"sv, "\\n"sv); 6522 Utils::replace(str, "\n"sv, "\\n"sv);
@@ -6593,7 +6593,7 @@ private:
6593 if (auto dotChain = ast_cast<DotChainItem_t>(chain->items.back())) { 6593 if (auto dotChain = ast_cast<DotChainItem_t>(chain->items.back())) {
6594 className = '\"' + _parser.toString(dotChain->name) + '\"'; 6594 className = '\"' + _parser.toString(dotChain->name) + '\"';
6595 } else if (auto index = ast_cast<Exp_t>(chain->items.back())) { 6595 } else if (auto index = ast_cast<Exp_t>(chain->items.back())) {
6596 if (auto name = index->getByPath<unary_exp_t, Value_t, String_t>()) { 6596 if (auto name = index->getByPath<UnaryExp_t, Value_t, String_t>()) {
6597 transformString(name, temp); 6597 transformString(name, temp);
6598 className = std::move(temp.back()); 6598 className = std::move(temp.back());
6599 temp.pop_back(); 6599 temp.pop_back();
@@ -6679,8 +6679,8 @@ private:
6679 std::list<ClassMember> members; 6679 std::list<ClassMember> members;
6680 for (auto content : classDecl->body->contents.objects()) { 6680 for (auto content : classDecl->body->contents.objects()) {
6681 switch (content->getId()) { 6681 switch (content->getId()) {
6682 case id<class_member_list_t>(): { 6682 case id<ClassMemberList_t>(): {
6683 size_t inc = transform_class_member_list(static_cast<class_member_list_t*>(content), members, classVar); 6683 size_t inc = transform_class_member_list(static_cast<ClassMemberList_t*>(content), members, classVar);
6684 auto it = members.end(); 6684 auto it = members.end();
6685 for (size_t i = 0; i < inc; ++i, --it) 6685 for (size_t i = 0; i < inc; ++i, --it)
6686 ; 6686 ;
@@ -6832,24 +6832,24 @@ private:
6832 out.push_back(join(temp)); 6832 out.push_back(join(temp));
6833 } 6833 }
6834 6834
6835 size_t transform_class_member_list(class_member_list_t* class_member_list, std::list<ClassMember>& out, const std::string& classVar) { 6835 size_t transform_class_member_list(ClassMemberList_t* class_member_list, std::list<ClassMember>& out, const std::string& classVar) {
6836 str_list temp; 6836 str_list temp;
6837 size_t count = 0; 6837 size_t count = 0;
6838 for (auto keyValue : class_member_list->values.objects()) { 6838 for (auto keyValue : class_member_list->values.objects()) {
6839 MemType type = MemType::Common; 6839 MemType type = MemType::Common;
6840 ast_ptr<false, ast_node> ref; 6840 ast_ptr<false, ast_node> ref;
6841 switch (keyValue->getId()) { 6841 switch (keyValue->getId()) {
6842 case id<meta_variable_pair_t>(): { 6842 case id<MetaVariablePair_t>(): {
6843 auto mtPair = static_cast<meta_variable_pair_t*>(keyValue); 6843 auto mtPair = static_cast<MetaVariablePair_t*>(keyValue);
6844 auto nameStr = _parser.toString(mtPair->name); 6844 auto nameStr = _parser.toString(mtPair->name);
6845 checkMetamethod(nameStr, mtPair->name); 6845 checkMetamethod(nameStr, mtPair->name);
6846 ref.set(toAst<normal_pair_t>("__"s + nameStr + ':' + nameStr, keyValue)); 6846 ref.set(toAst<NormalPair_t>("__"s + nameStr + ':' + nameStr, keyValue));
6847 keyValue = ref.get(); 6847 keyValue = ref.get();
6848 break; 6848 break;
6849 } 6849 }
6850 case id<meta_normal_pair_t>(): { 6850 case id<MetaNormalPair_t>(): {
6851 auto mtPair = static_cast<meta_normal_pair_t*>(keyValue); 6851 auto mtPair = static_cast<MetaNormalPair_t*>(keyValue);
6852 auto normal_pair = keyValue->new_ptr<normal_pair_t>(); 6852 auto normal_pair = keyValue->new_ptr<NormalPair_t>();
6853 if (auto name = mtPair->key.as<Name_t>()) { 6853 if (auto name = mtPair->key.as<Name_t>()) {
6854 auto nameStr = _parser.toString(name); 6854 auto nameStr = _parser.toString(name);
6855 checkMetamethod(nameStr, name); 6855 checkMetamethod(nameStr, name);
@@ -6866,16 +6866,16 @@ private:
6866 } 6866 }
6867 } 6867 }
6868 BLOCK_START 6868 BLOCK_START
6869 auto normal_pair = ast_cast<normal_pair_t>(keyValue); 6869 auto normal_pair = ast_cast<NormalPair_t>(keyValue);
6870 BREAK_IF(!normal_pair); 6870 BREAK_IF(!normal_pair);
6871 auto keyName = normal_pair->key.as<KeyName_t>(); 6871 auto keyName = normal_pair->key.as<KeyName_t>();
6872 BREAK_IF(!keyName); 6872 BREAK_IF(!keyName);
6873 std::string newSuperCall; 6873 std::string newSuperCall;
6874 auto selfName = keyName->name.as<SelfName_t>(); 6874 auto selfItem = keyName->name.as<SelfItem_t>();
6875 if (selfName) { 6875 if (selfItem) {
6876 type = MemType::Property; 6876 type = MemType::Property;
6877 auto name = ast_cast<self_name_t>(selfName->name); 6877 auto name = ast_cast<SelfName_t>(selfItem->name);
6878 if (!name) throw std::logic_error(_info.errorMessage("invalid class poperty name"sv, selfName->name)); 6878 if (!name) throw std::logic_error(_info.errorMessage("invalid class poperty name"sv, selfItem->name));
6879 newSuperCall = classVar + ".__parent."s + _parser.toString(name->name); 6879 newSuperCall = classVar + ".__parent."s + _parser.toString(name->name);
6880 } else { 6880 } else {
6881 auto x = keyName; 6881 auto x = keyName;
@@ -6945,11 +6945,11 @@ private:
6945 decIndentOffset(); 6945 decIndentOffset();
6946 } 6946 }
6947 switch (keyValue->getId()) { 6947 switch (keyValue->getId()) {
6948 case id<variable_pair_t>(): 6948 case id<VariablePair_t>():
6949 transform_variable_pair(static_cast<variable_pair_t*>(keyValue), temp); 6949 transform_variable_pair(static_cast<VariablePair_t*>(keyValue), temp);
6950 break; 6950 break;
6951 case id<normal_pair_t>(): 6951 case id<NormalPair_t>():
6952 transform_normal_pair(static_cast<normal_pair_t*>(keyValue), temp, true); 6952 transform_normal_pair(static_cast<NormalPair_t*>(keyValue), temp, true);
6953 break; 6953 break;
6954 default: YUEE("AST node mismatch", keyValue); break; 6954 default: YUEE("AST node mismatch", keyValue); break;
6955 } 6955 }
@@ -6969,7 +6969,7 @@ private:
6969 switch (item->getId()) { 6969 switch (item->getId()) {
6970 case id<AssignableChain_t>(): transformAssignableChain(static_cast<AssignableChain_t*>(item), out); break; 6970 case id<AssignableChain_t>(): transformAssignableChain(static_cast<AssignableChain_t*>(item), out); break;
6971 case id<Variable_t>(): transformVariable(static_cast<Variable_t*>(item), out); break; 6971 case id<Variable_t>(): transformVariable(static_cast<Variable_t*>(item), out); break;
6972 case id<SelfName_t>(): transformSelfName(static_cast<SelfName_t*>(item), out); break; 6972 case id<SelfItem_t>(): transformSelfName(static_cast<SelfItem_t*>(item), out); break;
6973 default: YUEE("AST node mismatch", item); break; 6973 default: YUEE("AST node mismatch", item); break;
6974 } 6974 }
6975 } 6975 }
@@ -7137,7 +7137,7 @@ private:
7137 out.push_back(join(temp)); 7137 out.push_back(join(temp));
7138 } 7138 }
7139 7139
7140 void transform_const_value(const_value_t* const_value, str_list& out) { 7140 void transform_const_value(ConstValue_t* const_value, str_list& out) {
7141 out.push_back(_parser.toString(const_value)); 7141 out.push_back(_parser.toString(const_value));
7142 } 7142 }
7143 7143
@@ -7154,16 +7154,16 @@ private:
7154 transformClassDecl(classDecl, out, ExpUsage::Common); 7154 transformClassDecl(classDecl, out, ExpUsage::Common);
7155 break; 7155 break;
7156 } 7156 }
7157 case id<global_op_t>(): 7157 case id<GlobalOp_t>():
7158 if (_parser.toString(item) == "*"sv) { 7158 if (_parser.toString(item) == "*"sv) {
7159 markVarsGlobal(GlobalMode::Any); 7159 markVarsGlobal(GlobalMode::Any);
7160 } else { 7160 } else {
7161 markVarsGlobal(GlobalMode::Capital); 7161 markVarsGlobal(GlobalMode::Capital);
7162 } 7162 }
7163 break; 7163 break;
7164 case id<global_values_t>(): { 7164 case id<GlobalValues_t>(): {
7165 markVarsGlobal(GlobalMode::Any); 7165 markVarsGlobal(GlobalMode::Any);
7166 auto values = global->item.to<global_values_t>(); 7166 auto values = global->item.to<GlobalValues_t>();
7167 if (values->valueList) { 7167 if (values->valueList) {
7168 auto expList = x->new_ptr<ExpList_t>(); 7168 auto expList = x->new_ptr<ExpList_t>();
7169 for (auto name : values->nameList->names.objects()) { 7169 for (auto name : values->nameList->names.objects()) {
@@ -7209,7 +7209,7 @@ private:
7209 } 7209 }
7210 for (auto _exp : expList->exprs.objects()) { 7210 for (auto _exp : expList->exprs.objects()) {
7211 auto exp = static_cast<Exp_t*>(_exp); 7211 auto exp = static_cast<Exp_t*>(_exp);
7212 if (!variableFrom(exp) && !exp->getByPath<unary_exp_t, Value_t, SimpleValue_t, TableLit_t>() && !exp->getByPath<unary_exp_t, Value_t, simple_table_t>()) { 7212 if (!variableFrom(exp) && !exp->getByPath<UnaryExp_t, Value_t, SimpleValue_t, TableLit_t>() && !exp->getByPath<UnaryExp_t, Value_t, SimpleTable_t>()) {
7213 throw std::logic_error(_info.errorMessage("left hand expressions must be variables in export statement"sv, x)); 7213 throw std::logic_error(_info.errorMessage("left hand expressions must be variables in export statement"sv, x));
7214 } 7214 }
7215 } 7215 }
@@ -7253,7 +7253,7 @@ private:
7253 auto assignList = toAst<ExpList_t>(_info.moduleName + "[#"s + _info.moduleName + "+1]"s, x); 7253 auto assignList = toAst<ExpList_t>(_info.moduleName + "[#"s + _info.moduleName + "+1]"s, x);
7254 assignment->expList.set(assignList); 7254 assignment->expList.set(assignList);
7255 for (auto exp : expList->exprs.objects()) { 7255 for (auto exp : expList->exprs.objects()) {
7256 if (auto classDecl = exp->getByPath<unary_exp_t, Value_t, SimpleValue_t, ClassDecl_t>()) { 7256 if (auto classDecl = exp->getByPath<UnaryExp_t, Value_t, SimpleValue_t, ClassDecl_t>()) {
7257 if (classDecl->name && classDecl->name->item->getId() == id<Variable_t>()) { 7257 if (classDecl->name && classDecl->name->item->getId() == id<Variable_t>()) {
7258 transformClassDecl(classDecl, temp, ExpUsage::Common); 7258 transformClassDecl(classDecl, temp, ExpUsage::Common);
7259 auto name = _parser.toString(classDecl->name->item); 7259 auto name = _parser.toString(classDecl->name->item);
@@ -7276,7 +7276,7 @@ private:
7276 } 7276 }
7277 } 7277 }
7278 7278
7279 void transform_simple_table(simple_table_t* table, str_list& out) { 7279 void transform_simple_table(SimpleTable_t* table, str_list& out) {
7280 transformTable(table->pairs.objects(), out); 7280 transformTable(table->pairs.objects(), out);
7281 } 7281 }
7282 7282
@@ -7536,8 +7536,8 @@ private:
7536 expList->exprs.push_back(exp); 7536 expList->exprs.push_back(exp);
7537 break; 7537 break;
7538 } 7538 }
7539 case id<colon_import_name_t>(): { 7539 case id<ColonImportName_t>(): {
7540 auto var = static_cast<colon_import_name_t*>(name)->name.get(); 7540 auto var = static_cast<ColonImportName_t*>(name)->name.get();
7541 { 7541 {
7542 auto nameNode = var->name.get(); 7542 auto nameNode = var->name.get();
7543 auto callable = toAst<Callable_t>(objVar, x); 7543 auto callable = toAst<Callable_t>(objVar, x);
@@ -7597,9 +7597,9 @@ private:
7597 auto name = moduleNameFrom(import->literal); 7597 auto name = moduleNameFrom(import->literal);
7598 import->target.set(toAst<Variable_t>(name, x)); 7598 import->target.set(toAst<Variable_t>(name, x));
7599 } 7599 }
7600 if (ast_is<import_all_macro_t, ImportTabLit_t>(import->target)) { 7600 if (ast_is<ImportAllMacro_t, ImportTabLit_t>(import->target)) {
7601 x = import->target.get(); 7601 x = import->target.get();
7602 bool importAllMacro = import->target.is<import_all_macro_t>(); 7602 bool importAllMacro = import->target.is<ImportAllMacro_t>();
7603 std::list<std::pair<std::string, std::string>> macroPairs; 7603 std::list<std::pair<std::string, std::string>> macroPairs;
7604 auto newTab = x->new_ptr<ImportTabLit_t>(); 7604 auto newTab = x->new_ptr<ImportTabLit_t>();
7605 if (auto tabLit = import->target.as<ImportTabLit_t>()) { 7605 if (auto tabLit = import->target.as<ImportTabLit_t>()) {
@@ -7607,8 +7607,8 @@ private:
7607 switch (item->getId()) { 7607 switch (item->getId()) {
7608#ifdef YUE_NO_MACRO 7608#ifdef YUE_NO_MACRO
7609 case id<MacroName_t>(): 7609 case id<MacroName_t>():
7610 case id<macro_name_pair_t>(): 7610 case id<MacroNamePair_t>():
7611 case id<import_all_macro_t>(): { 7611 case id<ImportAllMacro_t>(): {
7612 throw std::logic_error(_info.errorMessage("macro feature not supported"sv, item)); 7612 throw std::logic_error(_info.errorMessage("macro feature not supported"sv, item));
7613 break; 7613 break;
7614 } 7614 }
@@ -7619,20 +7619,20 @@ private:
7619 macroPairs.emplace_back(name, name); 7619 macroPairs.emplace_back(name, name);
7620 break; 7620 break;
7621 } 7621 }
7622 case id<macro_name_pair_t>(): { 7622 case id<MacroNamePair_t>(): {
7623 auto pair = static_cast<macro_name_pair_t*>(item); 7623 auto pair = static_cast<MacroNamePair_t*>(item);
7624 macroPairs.emplace_back(_parser.toString(pair->key->name), _parser.toString(pair->value->name)); 7624 macroPairs.emplace_back(_parser.toString(pair->key->name), _parser.toString(pair->value->name));
7625 break; 7625 break;
7626 } 7626 }
7627 case id<import_all_macro_t>(): 7627 case id<ImportAllMacro_t>():
7628 if (importAllMacro) throw std::logic_error(_info.errorMessage("import all macro symbol duplicated"sv, item)); 7628 if (importAllMacro) throw std::logic_error(_info.errorMessage("import all macro symbol duplicated"sv, item));
7629 importAllMacro = true; 7629 importAllMacro = true;
7630 break; 7630 break;
7631#endif // YUE_NO_MACRO 7631#endif // YUE_NO_MACRO
7632 case id<variable_pair_t>(): 7632 case id<VariablePair_t>():
7633 case id<normal_pair_t>(): 7633 case id<NormalPair_t>():
7634 case id<meta_variable_pair_t>(): 7634 case id<MetaVariablePair_t>():
7635 case id<meta_normal_pair_t>(): 7635 case id<MetaNormalPair_t>():
7636 case id<Exp_t>(): 7636 case id<Exp_t>():
7637 newTab->items.push_back(item); 7637 newTab->items.push_back(item);
7638 break; 7638 break;
@@ -7734,32 +7734,32 @@ private:
7734 auto tableLit = x->new_ptr<TableLit_t>(); 7734 auto tableLit = x->new_ptr<TableLit_t>();
7735 for (auto pair : tabLit->items.objects()) { 7735 for (auto pair : tabLit->items.objects()) {
7736 switch (pair->getId()) { 7736 switch (pair->getId()) {
7737 case id<variable_pair_t>(): { 7737 case id<VariablePair_t>(): {
7738 auto pairDef = pair->new_ptr<variable_pair_def_t>(); 7738 auto pairDef = pair->new_ptr<VariablePairDef_t>();
7739 pairDef->pair.set(pair); 7739 pairDef->pair.set(pair);
7740 tableLit->values.push_back(pairDef); 7740 tableLit->values.push_back(pairDef);
7741 break; 7741 break;
7742 } 7742 }
7743 case id<normal_pair_t>(): { 7743 case id<NormalPair_t>(): {
7744 auto pairDef = pair->new_ptr<normal_pair_def_t>(); 7744 auto pairDef = pair->new_ptr<NormalPairDef_t>();
7745 pairDef->pair.set(pair); 7745 pairDef->pair.set(pair);
7746 tableLit->values.push_back(pairDef); 7746 tableLit->values.push_back(pairDef);
7747 break; 7747 break;
7748 } 7748 }
7749 case id<Exp_t>(): { 7749 case id<Exp_t>(): {
7750 auto pairDef = pair->new_ptr<normal_def_t>(); 7750 auto pairDef = pair->new_ptr<NormalDef_t>();
7751 pairDef->item.set(pair); 7751 pairDef->item.set(pair);
7752 tableLit->values.push_back(pairDef); 7752 tableLit->values.push_back(pairDef);
7753 break; 7753 break;
7754 } 7754 }
7755 case id<meta_variable_pair_t>(): { 7755 case id<MetaVariablePair_t>(): {
7756 auto pairDef = pair->new_ptr<meta_variable_pair_def_t>(); 7756 auto pairDef = pair->new_ptr<MetaVariablePairDef_t>();
7757 pairDef->pair.set(pair); 7757 pairDef->pair.set(pair);
7758 tableLit->values.push_back(pairDef); 7758 tableLit->values.push_back(pairDef);
7759 break; 7759 break;
7760 } 7760 }
7761 case id<meta_normal_pair_t>(): { 7761 case id<MetaNormalPair_t>(): {
7762 auto pairDef = pair->new_ptr<meta_normal_pair_def_t>(); 7762 auto pairDef = pair->new_ptr<MetaNormalPairDef_t>();
7763 pairDef->pair.set(pair); 7763 pairDef->pair.set(pair);
7764 tableLit->values.push_back(pairDef); 7764 tableLit->values.push_back(pairDef);
7765 break; 7765 break;
@@ -7935,7 +7935,7 @@ private:
7935 for (auto branch_ : branches) { 7935 for (auto branch_ : branches) {
7936 auto branch = static_cast<SwitchCase_t*>(branch_); 7936 auto branch = static_cast<SwitchCase_t*>(branch_);
7937 if (auto value = singleValueFrom(branch->valueList); 7937 if (auto value = singleValueFrom(branch->valueList);
7938 value && (value->item.is<simple_table_t>() || value->getByPath<SimpleValue_t, TableLit_t>())) { 7938 value && (value->item.is<SimpleTable_t>() || value->getByPath<SimpleValue_t, TableLit_t>())) {
7939 if (!firstBranch) { 7939 if (!firstBranch) {
7940 temp.push_back(indent() + "else"s + nll(branch)); 7940 temp.push_back(indent() + "else"s + nll(branch));
7941 pushScope(); 7941 pushScope();
@@ -8070,8 +8070,8 @@ private:
8070 transformLocalDef(local, temp); 8070 transformLocalDef(local, temp);
8071 } 8071 }
8072 switch (local->item->getId()) { 8072 switch (local->item->getId()) {
8073 case id<local_values_t>(): { 8073 case id<LocalValues_t>(): {
8074 auto values = static_cast<local_values_t*>(local->item.get()); 8074 auto values = static_cast<LocalValues_t*>(local->item.get());
8075 if (values->valueList) { 8075 if (values->valueList) {
8076 auto x = local; 8076 auto x = local;
8077 auto expList = x->new_ptr<ExpList_t>(); 8077 auto expList = x->new_ptr<ExpList_t>();
@@ -8097,7 +8097,7 @@ private:
8097 } 8097 }
8098 break; 8098 break;
8099 } 8099 }
8100 case id<local_flag_t>(): break; 8100 case id<LocalFlag_t>(): break;
8101 default: YUEE("AST node mismatch", local->item); break; 8101 default: YUEE("AST node mismatch", local->item); break;
8102 } 8102 }
8103 out.push_back(join(temp)); 8103 out.push_back(join(temp));
@@ -8130,7 +8130,7 @@ private:
8130 auto item = *i; 8130 auto item = *i;
8131 auto value = item->new_ptr<Value_t>(); 8131 auto value = item->new_ptr<Value_t>();
8132 switch (item->getId()) { 8132 switch (item->getId()) {
8133 case id<simple_table_t>(): 8133 case id<SimpleTable_t>():
8134 value->item.set(item); 8134 value->item.set(item);
8135 break; 8135 break;
8136 case id<TableLit_t>(): { 8136 case id<TableLit_t>(): {
@@ -8157,9 +8157,9 @@ private:
8157 } 8157 }
8158 if (getLuaTarget(x) >= 504) { 8158 if (getLuaTarget(x) >= 504) {
8159 std::string attrib; 8159 std::string attrib;
8160 if (localAttrib->attrib.is<const_attrib_t>()) { 8160 if (localAttrib->attrib.is<ConstAttrib_t>()) {
8161 attrib = " <const>"s; 8161 attrib = " <const>"s;
8162 } else if (localAttrib->attrib.is<close_attrib_t>()) { 8162 } else if (localAttrib->attrib.is<CloseAttrib_t>()) {
8163 attrib = " <close>"s; 8163 attrib = " <close>"s;
8164 } else { 8164 } else {
8165 YUEE("AST node mismatch", localAttrib->attrib); 8165 YUEE("AST node mismatch", localAttrib->attrib);
@@ -8169,7 +8169,7 @@ private:
8169 var.append(attrib); 8169 var.append(attrib);
8170 } 8170 }
8171 } else { 8171 } else {
8172 if (localAttrib->attrib.is<close_attrib_t>()) { 8172 if (localAttrib->attrib.is<CloseAttrib_t>()) {
8173 throw std::logic_error(_info.errorMessage("close attribute is not available when not targeting Lua version 5.4 or higher"sv, x)); 8173 throw std::logic_error(_info.errorMessage("close attribute is not available when not targeting Lua version 5.4 or higher"sv, x));
8174 } 8174 }
8175 for (auto& var : vars) { 8175 for (auto& var : vars) {
@@ -8264,7 +8264,7 @@ private:
8264 str_list temp; 8264 str_list temp;
8265 bool constVal = false; 8265 bool constVal = false;
8266 if (auto simpleVal = simpleSingleValueFrom(value)) { 8266 if (auto simpleVal = simpleSingleValueFrom(value)) {
8267 constVal = ast_is<const_value_t, Num_t>(simpleVal->value); 8267 constVal = ast_is<ConstValue_t, Num_t>(simpleVal->value);
8268 } 8268 }
8269 bool localVal = false; 8269 bool localVal = false;
8270 if (auto var = singleVariableFrom(value, false); isLocal(var)) { 8270 if (auto var = singleVariableFrom(value, false); isLocal(var)) {
diff --git a/src/yuescript/yue_parser.cpp b/src/yuescript/yue_parser.cpp
index 48308a6..e78b331 100644
--- a/src/yuescript/yue_parser.cpp
+++ b/src/yuescript/yue_parser.cpp
@@ -33,23 +33,23 @@ std::unordered_set<std::string> Keywords = {
33// clang-format off 33// clang-format off
34YueParser::YueParser() { 34YueParser::YueParser() {
35 plain_space = *set(" \t"); 35 plain_space = *set(" \t");
36 Break = nl(-expr('\r') >> '\n'); 36 line_break = nl(-expr('\r') >> '\n');
37 Any = Break | any(); 37 any_char = line_break | any();
38 Stop = Break | eof(); 38 stop = line_break | eof();
39 Indent = plain_space; 39 indent = plain_space;
40 Comment = "--" >> *(not_(set("\r\n")) >> Any) >> and_(Stop); 40 comment = "--" >> *(not_(set("\r\n")) >> any_char) >> and_(stop);
41 multi_line_open = "--[["; 41 multi_line_open = "--[[";
42 multi_line_close = "]]"; 42 multi_line_close = "]]";
43 multi_line_content = *(not_(multi_line_close) >> Any); 43 multi_line_content = *(not_(multi_line_close) >> any_char);
44 MultiLineComment = multi_line_open >> multi_line_content >> multi_line_close; 44 multi_line_comment = multi_line_open >> multi_line_content >> multi_line_close;
45 EscapeNewLine = '\\' >> *(set(" \t") | MultiLineComment) >> -Comment >> Break; 45 escape_new_line = '\\' >> *(set(" \t") | multi_line_comment) >> -comment >> line_break;
46 space_one = set(" \t") | and_(set("-\\")) >> (MultiLineComment | EscapeNewLine); 46 space_one = set(" \t") | and_(set("-\\")) >> (multi_line_comment | escape_new_line);
47 Space = -(and_(set(" \t-\\")) >> *space_one >> -Comment); 47 space = -(and_(set(" \t-\\")) >> *space_one >> -comment);
48 SpaceBreak = Space >> Break; 48 space_break = space >> line_break;
49 White = Space >> *(Break >> Space); 49 white = space >> *(line_break >> space);
50 EmptyLine = SpaceBreak; 50 empty_line = space_break;
51 AlphaNum = sel({range('a', 'z'), range('A', 'Z'), range('0', '9'), '_'}); 51 alpha_num = sel({range('a', 'z'), range('A', 'Z'), range('0', '9'), '_'});
52 Name = sel({range('a', 'z'), range('A', 'Z'), '_'}) >> *AlphaNum; 52 Name = sel({range('a', 'z'), range('A', 'Z'), '_'}) >> *alpha_num;
53 num_expo = set("eE") >> -set("+-") >> num_char; 53 num_expo = set("eE") >> -set("+-") >> num_char;
54 num_expo_hex = set("pP") >> -set("+-") >> num_char; 54 num_expo_hex = set("pP") >> -set("+-") >> num_char;
55 lj_num = -set("uU") >> set("lL") >> set("lL"); 55 lj_num = -set("uU") >> set("lL") >> set("lL");
@@ -76,7 +76,7 @@ YueParser::YueParser() {
76 seq({'.', +num_char, -num_expo}) 76 seq({'.', +num_char, -num_expo})
77 }); 77 });
78 78
79 Cut = false_(); 79 cut = false_();
80 Seperator = true_(); 80 Seperator = true_();
81 81
82 empty_block_error = pl::user(true_(), [](const item_t& item) { 82 empty_block_error = pl::user(true_(), [](const item_t& item) {
@@ -84,15 +84,52 @@ YueParser::YueParser() {
84 return false; 84 return false;
85 }); 85 });
86 86
87 #define ensure(patt, finally) ((patt) >> (finally) | (finally) >> Cut) 87 #define ensure(patt, finally) ((patt) >> (finally) | (finally) >> cut)
88 #define key(str) (str >> not_(AlphaNum)) 88
89 #define disable_do(patt) (DisableDo >> ((patt) >> EnableDo | EnableDo >> Cut)) 89 #define key(str) (str >> not_(alpha_num))
90 #define disable_chain(patt) (DisableChain >> ((patt) >> EnableChain | EnableChain >> Cut)) 90
91 #define disable_do_chain_arg_table_block(patt) (DisableDoChainArgTableBlock >> ((patt) >> EnableDoChainArgTableBlock | EnableDoChainArgTableBlock >> Cut)) 91 #define disable_do_rule(patt) ( \
92 #define disable_arg_table_block(patt) (DisableArgTableBlock >> ((patt) >> EnableArgTableBlock | EnableArgTableBlock >> Cut)) 92 disable_do >> ( \
93 #define body_with(str) (sel({key(str) >> Space >> (InBlock | Statement), InBlock, empty_block_error})) 93 (patt) >> enable_do | \
94 #define opt_body_with(str) (key(str) >> Space >> (InBlock | Statement) | InBlock) 94 enable_do >> cut \
95 #define body (sel({InBlock, Statement, empty_block_error})) 95 ) \
96 )
97
98 #define disable_chain_rule(patt) ( \
99 disable_chain >> ( \
100 (patt) >> enable_chain | \
101 enable_chain >> cut \
102 ) \
103 )
104
105 #define disable_do_chain_arg_table_block_rule(patt) ( \
106 disable_do_chain_arg_table_block >> ( \
107 (patt) >> enable_do_chain_arg_table_block | \
108 enable_do_chain_arg_table_block >> cut \
109 ) \
110 )
111
112 #define disable_arg_table_block_rule(patt) ( \
113 disable_arg_table_block >> ( \
114 (patt) >> enable_arg_table_block | \
115 enable_arg_table_block >> cut \
116 ) \
117 )
118
119 #define body_with(str) ( \
120 sel({ \
121 key(str) >> space >> (in_block | Statement), \
122 in_block, \
123 empty_block_error \
124 }) \
125 )
126
127 #define opt_body_with(str) ( \
128 key(str) >> space >> (in_block | Statement) | \
129 in_block \
130 )
131
132 #define body (sel({in_block, Statement, empty_block_error}))
96 133
97 Variable = pl::user(Name, [](const item_t& item) { 134 Variable = pl::user(Name, [](const item_t& item) {
98 State* st = reinterpret_cast<State*>(item.user_data); 135 State* st = reinterpret_cast<State*>(item.user_data);
@@ -124,16 +161,16 @@ YueParser::YueParser() {
124 return it != LuaKeywords.end(); 161 return it != LuaKeywords.end();
125 }); 162 });
126 163
127 self = '@'; 164 Self = '@';
128 self_name = '@' >> Name; 165 SelfName = '@' >> Name;
129 self_class = "@@"; 166 SelfClass = "@@";
130 self_class_name = "@@" >> Name; 167 SelfClassName = "@@" >> Name;
131 168
132 SelfName = sel({self_class_name, self_class, self_name, self}); 169 SelfItem = sel({SelfClassName, SelfClass, SelfName, Self});
133 KeyName = SelfName | Name; 170 KeyName = SelfItem | Name;
134 VarArg = "..."; 171 VarArg = "...";
135 172
136 check_indent = pl::user(Indent, [](const item_t& item) { 173 check_indent = pl::user(indent, [](const item_t& item) {
137 int indent = 0; 174 int indent = 0;
138 for (input_it i = item.begin->m_it; i != item.end->m_it; ++i) { 175 for (input_it i = item.begin->m_it; i != item.end->m_it; ++i) {
139 switch (*i) { 176 switch (*i) {
@@ -144,9 +181,9 @@ YueParser::YueParser() {
144 State* st = reinterpret_cast<State*>(item.user_data); 181 State* st = reinterpret_cast<State*>(item.user_data);
145 return st->indents.top() == indent; 182 return st->indents.top() == indent;
146 }); 183 });
147 CheckIndent = and_(check_indent); 184 check_indent_match = and_(check_indent);
148 185
149 advance = pl::user(Indent, [](const item_t& item) { 186 advance = pl::user(indent, [](const item_t& item) {
150 int indent = 0; 187 int indent = 0;
151 for (input_it i = item.begin->m_it; i != item.end->m_it; ++i) { 188 for (input_it i = item.begin->m_it; i != item.end->m_it; ++i) {
152 switch (*i) { 189 switch (*i) {
@@ -162,9 +199,9 @@ YueParser::YueParser() {
162 } 199 }
163 return false; 200 return false;
164 }); 201 });
165 Advance = and_(advance); 202 advance_match = and_(advance);
166 203
167 push_indent = pl::user(Indent, [](const item_t& item) { 204 push_indent = pl::user(indent, [](const item_t& item) {
168 int indent = 0; 205 int indent = 0;
169 for (input_it i = item.begin->m_it; i != item.end->m_it; ++i) { 206 for (input_it i = item.begin->m_it; i != item.end->m_it; ++i) {
170 switch (*i) { 207 switch (*i) {
@@ -176,152 +213,152 @@ YueParser::YueParser() {
176 st->indents.push(indent); 213 st->indents.push(indent);
177 return true; 214 return true;
178 }); 215 });
179 PushIndent = and_(push_indent); 216 push_indent_match = and_(push_indent);
180 217
181 PreventIndent = pl::user(true_(), [](const item_t& item) { 218 prevent_indent = pl::user(true_(), [](const item_t& item) {
182 State* st = reinterpret_cast<State*>(item.user_data); 219 State* st = reinterpret_cast<State*>(item.user_data);
183 st->indents.push(-1); 220 st->indents.push(-1);
184 return true; 221 return true;
185 }); 222 });
186 223
187 PopIndent = pl::user(true_(), [](const item_t& item) { 224 pop_indent = pl::user(true_(), [](const item_t& item) {
188 State* st = reinterpret_cast<State*>(item.user_data); 225 State* st = reinterpret_cast<State*>(item.user_data);
189 st->indents.pop(); 226 st->indents.pop();
190 return true; 227 return true;
191 }); 228 });
192 229
193 InBlock = +SpaceBreak >> Advance >> ensure(Block, PopIndent); 230 in_block = +space_break >> advance_match >> ensure(Block, pop_indent);
194 231
195 local_flag = sel({'*', '^'}); 232 LocalFlag = sel({'*', '^'});
196 local_values = NameList >> -(Space >> '=' >> Space >> (TableBlock | ExpListLow)); 233 LocalValues = NameList >> -(space >> '=' >> space >> (TableBlock | ExpListLow));
197 Local = key("local") >> Space >> (local_flag | local_values); 234 Local = key("local") >> space >> (LocalFlag | LocalValues);
198 235
199 const_attrib = key("const"); 236 ConstAttrib = key("const");
200 close_attrib = key("close"); 237 CloseAttrib = key("close");
201 local_const_item = sel({Variable, simple_table, TableLit}); 238 local_const_item = sel({Variable, SimpleTable, TableLit});
202 LocalAttrib = ( 239 LocalAttrib = (
203 const_attrib >> Seperator >> Space >> local_const_item >> *(Space >> ',' >> Space >> local_const_item) | 240 ConstAttrib >> Seperator >> space >> local_const_item >> *(space >> ',' >> space >> local_const_item) |
204 close_attrib >> Seperator >> Space >> Variable >> *(Space >> ',' >> Space >> Variable) 241 CloseAttrib >> Seperator >> space >> Variable >> *(space >> ',' >> space >> Variable)
205 ) >> Space >> Assign; 242 ) >> space >> Assign;
206 243
207 colon_import_name = '\\' >> Space >> Variable; 244 ColonImportName = '\\' >> space >> Variable;
208 ImportName = colon_import_name | Variable; 245 import_name = ColonImportName | Variable;
209 ImportNameList = Seperator >> *SpaceBreak >> Space >> ImportName >> *((+SpaceBreak | Space >> ',' >> *SpaceBreak) >> Space >> ImportName); 246 import_name_list = Seperator >> *space_break >> space >> import_name >> *((+space_break | space >> ',' >> *space_break) >> space >> import_name);
210 ImportFrom = ImportNameList >> *SpaceBreak >> Space >> key("from") >> Space >> Exp; 247 ImportFrom = import_name_list >> *space_break >> space >> key("from") >> space >> Exp;
211 248
212 import_literal_inner = sel({range('a', 'z'), range('A', 'Z'), set("_-")}) >> *(AlphaNum | '-'); 249 ImportLiteralInner = sel({range('a', 'z'), range('A', 'Z'), set("_-")}) >> *(alpha_num | '-');
213 import_literal_chain = Seperator >> import_literal_inner >> *('.' >> import_literal_inner); 250 import_literal_chain = Seperator >> ImportLiteralInner >> *('.' >> ImportLiteralInner);
214 ImportLiteral = sel({ 251 ImportLiteral = sel({
215 '\'' >> import_literal_chain >> '\'', 252 '\'' >> import_literal_chain >> '\'',
216 '"' >> import_literal_chain >> '"' 253 '"' >> import_literal_chain >> '"'
217 }); 254 });
218 255
219 macro_name_pair = MacroName >> ':' >> Space >> MacroName; 256 MacroNamePair = MacroName >> ':' >> space >> MacroName;
220 import_all_macro = '$'; 257 ImportAllMacro = '$';
221 ImportTabItem = sel({ 258 import_tab_item = sel({
222 variable_pair, 259 VariablePair,
223 normal_pair, 260 NormalPair,
224 ':' >> MacroName, 261 ':' >> MacroName,
225 macro_name_pair, 262 MacroNamePair,
226 import_all_macro, 263 ImportAllMacro,
227 meta_variable_pair, 264 MetaVariablePair,
228 meta_normal_pair, 265 MetaNormalPair,
229 Exp 266 Exp
230 }); 267 });
231 ImportTabList = ImportTabItem >> *(Space >> ',' >> Space >> ImportTabItem); 268 import_tab_list = import_tab_item >> *(space >> ',' >> space >> import_tab_item);
232 ImportTabLine = ( 269 import_tab_line = (
233 PushIndent >> (Space >> ImportTabList >> PopIndent | PopIndent) 270 push_indent_match >> (space >> import_tab_list >> pop_indent | pop_indent)
234 ) | Space; 271 ) | space;
235 import_tab_lines = SpaceBreak >> ImportTabLine >> *(-(Space >> ',') >> SpaceBreak >> ImportTabLine) >> -(Space >> ','); 272 import_tab_lines = space_break >> import_tab_line >> *(-(space >> ',') >> space_break >> import_tab_line) >> -(space >> ',');
236 ImportTabLit = seq({ 273 ImportTabLit = seq({
237 '{', Seperator, 274 '{', Seperator,
238 -(Space >> ImportTabList), 275 -(space >> import_tab_list),
239 -(Space >> ','), 276 -(space >> ','),
240 -import_tab_lines, 277 -import_tab_lines,
241 White, 278 white,
242 '}' 279 '}'
243 }) | seq({ 280 }) | seq({
244 Seperator, KeyValue, *(Space >> ',' >> Space >> KeyValue) 281 Seperator, key_value, *(space >> ',' >> space >> key_value)
245 }); 282 });
246 283
247 ImportAs = ImportLiteral >> -(Space >> key("as") >> Space >> sel({ImportTabLit, Variable, import_all_macro})); 284 ImportAs = ImportLiteral >> -(space >> key("as") >> space >> sel({ImportTabLit, Variable, ImportAllMacro}));
248 285
249 Import = key("import") >> Space >> (ImportAs | ImportFrom); 286 Import = key("import") >> space >> (ImportAs | ImportFrom);
250 287
251 Label = "::" >> LabelName >> "::"; 288 Label = "::" >> LabelName >> "::";
252 289
253 Goto = key("goto") >> Space >> LabelName; 290 Goto = key("goto") >> space >> LabelName;
254 291
255 ShortTabAppending = "[]" >> Space >> Assign; 292 ShortTabAppending = "[]" >> space >> Assign;
256 293
257 BreakLoop = sel({"break", "continue"}) >> not_(AlphaNum); 294 BreakLoop = sel({"break", "continue"}) >> not_(alpha_num);
258 295
259 Return = key("return") >> -(Space >> (TableBlock | ExpListLow)); 296 Return = key("return") >> -(space >> (TableBlock | ExpListLow));
260 297
261 WithExp = ExpList >> -(Space >> Assign); 298 with_exp = ExpList >> -(space >> Assign);
262 299
263 With = key("with") >> -existential_op >> Space >> disable_do_chain_arg_table_block(WithExp) >> Space >> body_with("do"); 300 With = key("with") >> -ExistentialOp >> space >> disable_do_chain_arg_table_block_rule(with_exp) >> space >> body_with("do");
264 SwitchCase = key("when") >> disable_chain(disable_arg_table_block(SwitchList)) >> Space >> body_with("then"); 301 SwitchCase = key("when") >> disable_chain_rule(disable_arg_table_block_rule(SwitchList)) >> space >> body_with("then");
265 SwitchElse = key("else") >> Space >> body; 302 switch_else = key("else") >> space >> body;
266 303
267 SwitchBlock = 304 switch_block =
268 *(Break >> *EmptyLine >> CheckIndent >> Space >> SwitchCase) >> 305 *(line_break >> *empty_line >> check_indent_match >> space >> SwitchCase) >>
269 -(Break >> *EmptyLine >> CheckIndent >> Space >> SwitchElse); 306 -(line_break >> *empty_line >> check_indent_match >> space >> switch_else);
270 307
271 exp_not_tab = not_(simple_table | TableLit) >> Space >> Exp; 308 exp_not_tab = not_(SimpleTable | TableLit) >> space >> Exp;
272 309
273 SwitchList = Seperator >> ( 310 SwitchList = Seperator >> (
274 and_(simple_table | TableLit) >> Space >> Exp | 311 and_(SimpleTable | TableLit) >> space >> Exp |
275 exp_not_tab >> *(Space >> ',' >> exp_not_tab) 312 exp_not_tab >> *(space >> ',' >> exp_not_tab)
276 ); 313 );
277 Switch = key("switch") >> Space >> Exp >> 314 Switch = key("switch") >> space >> Exp >>
278 Space >> Seperator >> ( 315 space >> Seperator >> (
279 SwitchCase >> Space >> ( 316 SwitchCase >> space >> (
280 Break >> *EmptyLine >> CheckIndent >> Space >> SwitchCase >> SwitchBlock | 317 line_break >> *empty_line >> check_indent_match >> space >> SwitchCase >> switch_block |
281 *(Space >> SwitchCase) >> -(Space >> SwitchElse) 318 *(space >> SwitchCase) >> -(space >> switch_else)
282 ) | 319 ) |
283 SpaceBreak >> *EmptyLine >> Advance >> Space >> SwitchCase >> SwitchBlock >> PopIndent 320 space_break >> *empty_line >> advance_match >> space >> SwitchCase >> switch_block >> pop_indent
284 ) >> SwitchBlock; 321 ) >> switch_block;
285 322
286 assignment = ExpList >> Space >> Assign; 323 Assignment = ExpList >> space >> Assign;
287 IfCond = disable_chain(disable_arg_table_block(assignment | Exp)); 324 IfCond = disable_chain_rule(disable_arg_table_block_rule(Assignment | Exp));
288 IfElseIf = -(Break >> *EmptyLine >> CheckIndent) >> Space >> key("elseif") >> Space >> IfCond >> Space >> body_with("then"); 325 if_else_if = -(line_break >> *empty_line >> check_indent_match) >> space >> key("elseif") >> space >> IfCond >> space >> body_with("then");
289 IfElse = -(Break >> *EmptyLine >> CheckIndent) >> Space >> key("else") >> Space >> body; 326 if_else = -(line_break >> *empty_line >> check_indent_match) >> space >> key("else") >> space >> body;
290 IfType = sel({"if", "unless"}) >> not_(AlphaNum); 327 IfType = sel({"if", "unless"}) >> not_(alpha_num);
291 If = seq({IfType, Space, IfCond, Space, opt_body_with("then"), *IfElseIf, -IfElse}); 328 If = seq({IfType, space, IfCond, space, opt_body_with("then"), *if_else_if, -if_else});
292 329
293 WhileType = sel({"while", "until"}) >> not_(AlphaNum); 330 WhileType = sel({"while", "until"}) >> not_(alpha_num);
294 While = WhileType >> Space >> disable_do_chain_arg_table_block(Exp) >> Space >> opt_body_with("do"); 331 While = WhileType >> space >> disable_do_chain_arg_table_block_rule(Exp) >> space >> opt_body_with("do");
295 Repeat = seq({key("repeat"), Space, Body, Break, *EmptyLine, CheckIndent, Space, key("until"), Space, Exp}); 332 Repeat = seq({key("repeat"), space, Body, line_break, *empty_line, check_indent_match, space, key("until"), space, Exp});
296 333
297 for_step_value = ',' >> Space >> Exp; 334 ForStepValue = ',' >> space >> Exp;
298 for_args = Variable >> Space >> '=' >> Space >> Exp >> Space >> ',' >> Space >> Exp >> Space >> -for_step_value; 335 for_args = Variable >> space >> '=' >> space >> Exp >> space >> ',' >> space >> Exp >> space >> -ForStepValue;
299 336
300 For = key("for") >> Space >> disable_do_chain_arg_table_block(for_args) >> Space >> opt_body_with("do"); 337 For = key("for") >> space >> disable_do_chain_arg_table_block_rule(for_args) >> space >> opt_body_with("do");
301 338
302 for_in = star_exp | ExpList; 339 for_in = StarExp | ExpList;
303 340
304 ForEach = key("for") >> Space >> AssignableNameList >> Space >> key("in") >> Space >> 341 ForEach = key("for") >> space >> AssignableNameList >> space >> key("in") >> space >>
305 disable_do_chain_arg_table_block(for_in) >> Space >> opt_body_with("do"); 342 disable_do_chain_arg_table_block_rule(for_in) >> space >> opt_body_with("do");
306 343
307 Do = pl::user(key("do"), [](const item_t& item) { 344 Do = pl::user(key("do"), [](const item_t& item) {
308 State* st = reinterpret_cast<State*>(item.user_data); 345 State* st = reinterpret_cast<State*>(item.user_data);
309 return st->noDoStack.empty() || !st->noDoStack.top(); 346 return st->noDoStack.empty() || !st->noDoStack.top();
310 }) >> Space >> Body; 347 }) >> space >> Body;
311 348
312 DisableDo = pl::user(true_(), [](const item_t& item) { 349 disable_do = pl::user(true_(), [](const item_t& item) {
313 State* st = reinterpret_cast<State*>(item.user_data); 350 State* st = reinterpret_cast<State*>(item.user_data);
314 st->noDoStack.push(true); 351 st->noDoStack.push(true);
315 return true; 352 return true;
316 }); 353 });
317 354
318 EnableDo = pl::user(true_(), [](const item_t& item) { 355 enable_do = pl::user(true_(), [](const item_t& item) {
319 State* st = reinterpret_cast<State*>(item.user_data); 356 State* st = reinterpret_cast<State*>(item.user_data);
320 st->noDoStack.pop(); 357 st->noDoStack.pop();
321 return true; 358 return true;
322 }); 359 });
323 360
324 DisableDoChainArgTableBlock = pl::user(true_(), [](const item_t& item) { 361 disable_do_chain_arg_table_block = pl::user(true_(), [](const item_t& item) {
325 State* st = reinterpret_cast<State*>(item.user_data); 362 State* st = reinterpret_cast<State*>(item.user_data);
326 st->noDoStack.push(true); 363 st->noDoStack.push(true);
327 st->noChainBlockStack.push(true); 364 st->noChainBlockStack.push(true);
@@ -329,7 +366,7 @@ YueParser::YueParser() {
329 return true; 366 return true;
330 }); 367 });
331 368
332 EnableDoChainArgTableBlock = pl::user(true_(), [](const item_t& item) { 369 enable_do_chain_arg_table_block = pl::user(true_(), [](const item_t& item) {
333 State* st = reinterpret_cast<State*>(item.user_data); 370 State* st = reinterpret_cast<State*>(item.user_data);
334 st->noDoStack.pop(); 371 st->noDoStack.pop();
335 st->noChainBlockStack.pop(); 372 st->noChainBlockStack.pop();
@@ -337,110 +374,111 @@ YueParser::YueParser() {
337 return true; 374 return true;
338 }); 375 });
339 376
340 DisableArgTableBlock = pl::user(true_(), [](const item_t& item) { 377 disable_arg_table_block = pl::user(true_(), [](const item_t& item) {
341 State* st = reinterpret_cast<State*>(item.user_data); 378 State* st = reinterpret_cast<State*>(item.user_data);
342 st->noTableBlockStack.push(true); 379 st->noTableBlockStack.push(true);
343 return true; 380 return true;
344 }); 381 });
345 382
346 EnableArgTableBlock = pl::user(true_(), [](const item_t& item) { 383 enable_arg_table_block = pl::user(true_(), [](const item_t& item) {
347 State* st = reinterpret_cast<State*>(item.user_data); 384 State* st = reinterpret_cast<State*>(item.user_data);
348 st->noTableBlockStack.pop(); 385 st->noTableBlockStack.pop();
349 return true; 386 return true;
350 }); 387 });
351 388
352 catch_block = Break >> *EmptyLine >> CheckIndent >> Space >> key("catch") >> Space >> Variable >> Space >> InBlock; 389 CatchBlock = line_break >> *empty_line >> check_indent_match >> space >> key("catch") >> space >> Variable >> space >> in_block;
353 Try = key("try") >> Space >> (InBlock | Exp) >> -catch_block; 390 Try = key("try") >> space >> (in_block | Exp) >> -CatchBlock;
354 391
355 Comprehension = '[' >> not_('[') >> Space >> Exp >> Space >> CompInner >> Space >> ']'; 392 Comprehension = '[' >> not_('[') >> space >> Exp >> space >> CompInner >> space >> ']';
356 comp_value = ',' >> Space >> Exp; 393 CompValue = ',' >> space >> Exp;
357 TblComprehension = '{' >> Space >> Exp >> Space >> -(comp_value >> Space) >> CompInner >> Space >> '}'; 394 TblComprehension = '{' >> space >> Exp >> space >> -(CompValue >> space) >> CompInner >> space >> '}';
358 395
359 CompInner = Seperator >> (CompForEach | CompFor) >> *(Space >> CompClause); 396 CompInner = Seperator >> (CompForEach | CompFor) >> *(space >> comp_clause);
360 star_exp = '*' >> Space >> Exp; 397 StarExp = '*' >> space >> Exp;
361 CompForEach = key("for") >> Space >> AssignableNameList >> Space >> key("in") >> Space >> (star_exp | Exp); 398 CompForEach = key("for") >> space >> AssignableNameList >> space >> key("in") >> space >> (StarExp | Exp);
362 CompFor = key("for") >> Space >> Variable >> Space >> '=' >> Space >> Exp >> Space >> ',' >> Space >> Exp >> -for_step_value; 399 CompFor = key("for") >> space >> Variable >> space >> '=' >> space >> Exp >> space >> ',' >> space >> Exp >> -ForStepValue;
363 CompClause = sel({CompFor, CompForEach, key("when") >> Space >> Exp}); 400 comp_clause = sel({CompFor, CompForEach, key("when") >> space >> Exp});
364 401
365 Assign = '=' >> Space >> Seperator >> sel({ 402 Assign = '=' >> space >> Seperator >> sel({
366 With, If, Switch, TableBlock, 403 With, If, Switch, TableBlock,
367 Exp >> *(Space >> set(",;") >> Space >> Exp) 404 Exp >> *(space >> set(",;") >> space >> Exp)
368 }); 405 });
369 406
370 update_op = sel({ 407 UpdateOp = sel({
371 "..", "//", "or", "and", 408 "..", "//", "or", "and",
372 ">>", "<<", "??", 409 ">>", "<<", "??",
373 set("+-*/%&|") 410 set("+-*/%&|")
374 }); 411 });
375 412
376 Update = update_op >> '=' >> Space >> Exp; 413 Update = UpdateOp >> '=' >> space >> Exp;
377 414
378 Assignable = sel({AssignableChain, Variable, SelfName}); 415 Assignable = sel({AssignableChain, Variable, SelfItem});
379 416
380 unary_value = +(unary_operator >> Space) >> Value; 417 UnaryValue = +(UnaryOperator >> space) >> Value;
381 418
382 ExponentialOperator = '^'; 419 exponential_operator = '^';
383 expo_value = seq({ExponentialOperator, *SpaceBreak, Space, Value}); 420 expo_value = seq({exponential_operator, *space_break, space, Value});
384 expo_exp = Value >> *(Space >> expo_value); 421 expo_exp = Value >> *(space >> expo_value);
385 422
386 unary_operator = sel({ 423 UnaryOperator = sel({
387 '-' >> not_(set(">=") | space_one), 424 '-' >> not_(set(">=") | space_one),
388 '#', 425 '#',
389 '~' >> not_('=' | space_one), 426 '~' >> not_('=' | space_one),
390 "not" >> not_(AlphaNum) 427 "not" >> not_(alpha_num)
391 }); 428 });
392 unary_exp = *(unary_operator >> Space) >> expo_exp; 429 UnaryExp = *(UnaryOperator >> space) >> expo_exp;
393 430
394 PipeOperator = "|>"; 431 pipe_operator = "|>";
395 pipe_value = seq({PipeOperator, *SpaceBreak, Space, unary_exp}); 432 pipe_value = seq({pipe_operator, *space_break, space, UnaryExp});
396 pipe_exp = unary_exp >> *(Space >> pipe_value); 433 pipe_exp = UnaryExp >> *(space >> pipe_value);
397 434
398 BinaryOperator = sel({ 435 BinaryOperator = sel({
399 "or" >> not_(AlphaNum), 436 "or" >> not_(alpha_num),
400 "and" >> not_(AlphaNum), 437 "and" >> not_(alpha_num),
401 "<=", ">=", "~=", "!=", "==", 438 "<=", ">=", "~=", "!=", "==",
402 "..", "<<", ">>", "//", 439 "..", "<<", ">>", "//",
403 set("+-*/%><|&~") 440 set("+-*/%><|&~")
404 }); 441 });
405 exp_op_value = seq({BinaryOperator, *SpaceBreak, Space, pipe_exp}); 442 ExpOpValue = seq({BinaryOperator, *space_break, space, pipe_exp});
406 Exp = seq({Seperator, pipe_exp, *(Space >> exp_op_value), -(Space >> "??" >> Space >> Exp)}); 443 Exp = seq({Seperator, pipe_exp, *(space >> ExpOpValue), -(space >> "??" >> space >> Exp)});
407 444
408 DisableChain = pl::user(true_(), [](const item_t& item) { 445 disable_chain = pl::user(true_(), [](const item_t& item) {
409 State* st = reinterpret_cast<State*>(item.user_data); 446 State* st = reinterpret_cast<State*>(item.user_data);
410 st->noChainBlockStack.push(true); 447 st->noChainBlockStack.push(true);
411 return true; 448 return true;
412 }); 449 });
413 450
414 EnableChain = pl::user(true_(), [](const item_t& item) { 451 enable_chain = pl::user(true_(), [](const item_t& item) {
415 State* st = reinterpret_cast<State*>(item.user_data); 452 State* st = reinterpret_cast<State*>(item.user_data);
416 st->noChainBlockStack.pop(); 453 st->noChainBlockStack.pop();
417 return true; 454 return true;
418 }); 455 });
419 456
420 chain_line = seq({CheckIndent, Space, chain_dot_chain | ColonChain, -InvokeArgs}); 457 chain_line = seq({check_indent_match, space, chain_dot_chain | colon_chain, -InvokeArgs});
421 chain_block = pl::user(true_(), [](const item_t& item) { 458 chain_block = pl::user(true_(), [](const item_t& item) {
422 State* st = reinterpret_cast<State*>(item.user_data); 459 State* st = reinterpret_cast<State*>(item.user_data);
423 return st->noChainBlockStack.empty() || !st->noChainBlockStack.top(); 460 return st->noChainBlockStack.empty() || !st->noChainBlockStack.top();
424 }) >> +SpaceBreak >> Advance >> ensure( 461 }) >> +space_break >> advance_match >> ensure(
425 chain_line >> *(+SpaceBreak >> chain_line), PopIndent); 462 chain_line >> *(+space_break >> chain_line), pop_indent);
426 ChainValue = seq({ 463 ChainValue = seq({
427 Seperator, 464 Seperator,
428 Chain, 465 chain,
429 -existential_op, 466 -ExistentialOp,
430 -(InvokeArgs | chain_block), 467 -(InvokeArgs | chain_block),
431 -table_appending_op 468 -TableAppendingOp
432 }); 469 });
433 470
434 simple_table = seq({Seperator, KeyValue, *(Space >> ',' >> Space >> KeyValue)}); 471 SimpleTable = seq({Seperator, key_value, *(space >> ',' >> space >> key_value)});
435 Value = sel({SimpleValue, simple_table, ChainValue, String}); 472 Value = sel({SimpleValue, SimpleTable, ChainValue, String});
436 473
437 single_string_inner = '\\' >> set("'\\") | not_('\'') >> Any; 474 single_string_inner = '\\' >> set("'\\") | not_('\'') >> any_char;
438 SingleString = '\'' >> *single_string_inner >> '\''; 475 SingleString = '\'' >> *single_string_inner >> '\'';
439 interp = "#{" >> Space >> Exp >> Space >> '}'; 476
440 double_string_plain = '\\' >> set("\"\\") | not_('"') >> Any; 477 interp = "#{" >> space >> Exp >> space >> '}';
441 double_string_inner = +(not_(interp) >> double_string_plain); 478 double_string_plain = '\\' >> set("\"\\") | not_('"') >> any_char;
442 double_string_content = double_string_inner | interp; 479 DoubleStringInner = +(not_(interp) >> double_string_plain);
443 DoubleString = '"' >> Seperator >> *double_string_content >> '"'; 480 DoubleStringContent = DoubleStringInner | interp;
481 DoubleString = '"' >> Seperator >> *DoubleStringContent >> '"';
444 String = sel({DoubleString, SingleString, LuaString}); 482 String = sel({DoubleString, SingleString, LuaString});
445 483
446 lua_string_open = '[' >> *expr('=') >> '['; 484 lua_string_open = '[' >> *expr('=') >> '[';
@@ -459,143 +497,143 @@ YueParser::YueParser() {
459 return st->stringOpen == count; 497 return st->stringOpen == count;
460 }); 498 });
461 499
462 LuaStringContent = *(not_(LuaStringClose) >> Any); 500 LuaStringContent = *(not_(LuaStringClose) >> any_char);
463 501
464 LuaString = LuaStringOpen >> -Break >> LuaStringContent >> LuaStringClose; 502 LuaString = LuaStringOpen >> -line_break >> LuaStringContent >> LuaStringClose;
465 503
466 Parens = seq({'(', *SpaceBreak, Space, Exp, *SpaceBreak, Space, ')'}); 504 Parens = seq({'(', *space_break, space, Exp, *space_break, space, ')'});
467 Callable = sel({Variable, SelfName, MacroName, VarArg, Parens}); 505 Callable = sel({Variable, SelfItem, MacroName, VarArg, Parens});
468 FnArgsExpList = Space >> Exp >> Space >> *seq({Break | ',', White, Exp}); 506 fn_args_exp_list = space >> Exp >> space >> *seq({line_break | ',', white, Exp});
469 507
470 FnArgs = sel({ 508 fn_args = sel({
471 seq({'(', *SpaceBreak, -FnArgsExpList, *SpaceBreak, Space, ')'}), 509 seq({'(', *space_break, -fn_args_exp_list, *space_break, space, ')'}),
472 seq({Space, '!', not_('=')}) 510 seq({space, '!', not_('=')})
473 }); 511 });
474 512
475 meta_index = sel({Name, Index, String}); 513 meta_index = sel({Name, index, String});
476 Metatable = '<' >> Space >> '>'; 514 Metatable = '<' >> space >> '>';
477 Metamethod = '<' >> Space >> meta_index >> Space >> '>'; 515 Metamethod = '<' >> space >> meta_index >> space >> '>';
478 516
479 existential_op = '?' >> not_('?'); 517 ExistentialOp = '?' >> not_('?');
480 table_appending_op = "[]"; 518 TableAppendingOp = "[]";
481 chain_call = seq({ 519 chain_call = seq({
482 Callable, 520 Callable,
483 -existential_op, 521 -ExistentialOp,
484 -ChainItems 522 -chain_items
485 }) | seq({ 523 }) | seq({
486 String, 524 String,
487 ChainItems 525 chain_items
488 }); 526 });
489 chain_index_chain = seq({Index, -existential_op, -ChainItems}); 527 chain_index_chain = seq({index, -ExistentialOp, -chain_items});
490 chain_dot_chain = seq({DotChainItem, -existential_op, -ChainItems}); 528 chain_dot_chain = seq({DotChainItem, -ExistentialOp, -chain_items});
491 529
492 Chain = sel({chain_call, chain_dot_chain, ColonChain, chain_index_chain}); 530 chain = sel({chain_call, chain_dot_chain, colon_chain, chain_index_chain});
493 531
494 chain_call_list = seq({ 532 chain_call_list = seq({
495 Callable, 533 Callable,
496 -existential_op, 534 -ExistentialOp,
497 ChainItems 535 chain_items
498 }) | seq({ 536 }) | seq({
499 String, 537 String,
500 ChainItems 538 chain_items
501 }); 539 });
502 ChainList = sel({chain_call_list, chain_dot_chain, ColonChain, chain_index_chain}); 540 chain_list = sel({chain_call_list, chain_dot_chain, colon_chain, chain_index_chain});
503 541
504 AssignableChain = Seperator >> ChainList; 542 AssignableChain = Seperator >> chain_list;
505 543
506 chain_with_colon = +ChainItem >> -ColonChain; 544 chain_with_colon = +chain_item >> -colon_chain;
507 ChainItems = chain_with_colon | ColonChain; 545 chain_items = chain_with_colon | colon_chain;
508 546
509 Index = seq({'[', not_('['), Space, Exp, Space, ']'}); 547 index = seq({'[', not_('['), space, Exp, space, ']'});
510 ChainItem = sel({ 548 chain_item = sel({
511 Invoke >> -existential_op, 549 Invoke >> -ExistentialOp,
512 DotChainItem >> -existential_op, 550 DotChainItem >> -ExistentialOp,
513 Slice, 551 Slice,
514 Index >> -existential_op 552 index >> -ExistentialOp
515 }); 553 });
516 DotChainItem = '.' >> sel({Name, Metatable, Metamethod}); 554 DotChainItem = '.' >> sel({Name, Metatable, Metamethod});
517 ColonChainItem = sel({'\\', "::"}) >> sel({LuaKeyword, Name, Metamethod}); 555 ColonChainItem = sel({'\\', "::"}) >> sel({LuaKeyword, Name, Metamethod});
518 invoke_chain = Invoke >> -existential_op >> -ChainItems; 556 invoke_chain = Invoke >> -ExistentialOp >> -chain_items;
519 ColonChain = ColonChainItem >> -existential_op >> -invoke_chain; 557 colon_chain = ColonChainItem >> -ExistentialOp >> -invoke_chain;
520 558
521 default_value = true_(); 559 DefaultValue = true_();
522 Slice = seq({ 560 Slice = seq({
523 '[', not_('['), 561 '[', not_('['),
524 Space, Exp | default_value, 562 space, Exp | DefaultValue,
525 Space, ',', 563 space, ',',
526 Space, Exp | default_value, 564 space, Exp | DefaultValue,
527 Space, ',' >> Space >> Exp | default_value, 565 space, ',' >> space >> Exp | DefaultValue,
528 Space, ']' 566 space, ']'
529 }); 567 });
530 568
531 Invoke = Seperator >> sel({ 569 Invoke = Seperator >> sel({
532 FnArgs, 570 fn_args,
533 SingleString, 571 SingleString,
534 DoubleString, 572 DoubleString,
535 and_('[') >> LuaString, 573 and_('[') >> LuaString,
536 and_('{') >> TableLit 574 and_('{') >> TableLit
537 }); 575 });
538 576
539 SpreadExp = "..." >> Space >> Exp; 577 SpreadExp = "..." >> space >> Exp;
540 578
541 TableValue = sel({ 579 table_value = sel({
542 variable_pair_def, 580 VariablePairDef,
543 normal_pair_def, 581 NormalPairDef,
544 meta_variable_pair_def, 582 MetaVariablePairDef,
545 meta_normal_pair_def, 583 MetaNormalPairDef,
546 SpreadExp, 584 SpreadExp,
547 normal_def 585 NormalDef
548 }); 586 });
549 587
550 table_lit_lines = SpaceBreak >> TableLitLine >> *(-(Space >> ',') >> SpaceBreak >> TableLitLine) >> -(Space >> ','); 588 table_lit_lines = space_break >> table_lit_line >> *(-(space >> ',') >> space_break >> table_lit_line) >> -(space >> ',');
551 589
552 TableLit = seq({ 590 TableLit = seq({
553 Space, '{', Seperator, 591 space, '{', Seperator,
554 -(Space >> TableValueList), 592 -(space >> table_value_list),
555 -(Space >> ','), 593 -(space >> ','),
556 -table_lit_lines, 594 -table_lit_lines,
557 White, '}' 595 white, '}'
558 }); 596 });
559 597
560 TableValueList = TableValue >> *(Space >> ',' >> Space >> TableValue); 598 table_value_list = table_value >> *(space >> ',' >> space >> table_value);
561 599
562 TableLitLine = ( 600 table_lit_line = (
563 PushIndent >> (Space >> TableValueList >> PopIndent | PopIndent) 601 push_indent_match >> (space >> table_value_list >> pop_indent | pop_indent)
564 ) | ( 602 ) | (
565 Space 603 space
566 ); 604 );
567 605
568 TableBlockInner = Seperator >> KeyValueLine >> *(+SpaceBreak >> KeyValueLine); 606 table_block_inner = Seperator >> key_value_line >> *(+space_break >> key_value_line);
569 TableBlock = +SpaceBreak >> Advance >> ensure(TableBlockInner, PopIndent); 607 TableBlock = +space_break >> advance_match >> ensure(table_block_inner, pop_indent);
570 TableBlockIndent = '*' >> Seperator >> disable_arg_table_block( 608 TableBlockIndent = '*' >> Seperator >> disable_arg_table_block_rule(
571 Space >> KeyValueList >> -(Space >> ',') >> 609 space >> key_value_list >> -(space >> ',') >>
572 -(+SpaceBreak >> Advance >> Space >> ensure(KeyValueList >> -(Space >> ',') >> *(+SpaceBreak >> KeyValueLine), PopIndent))); 610 -(+space_break >> advance_match >> space >> ensure(key_value_list >> -(space >> ',') >> *(+space_break >> key_value_line), pop_indent)));
573 611
574 class_member_list = Seperator >> KeyValue >> *(Space >> ',' >> Space >> KeyValue); 612 ClassMemberList = Seperator >> key_value >> *(space >> ',' >> space >> key_value);
575 ClassLine = CheckIndent >> Space >> (class_member_list | Statement) >> -(Space >> ','); 613 class_line = check_indent_match >> space >> (ClassMemberList | Statement) >> -(space >> ',');
576 ClassBlock = seq({+SpaceBreak, Advance, Seperator, ClassLine, *(+SpaceBreak >> ClassLine), PopIndent}); 614 ClassBlock = seq({+space_break, advance_match, Seperator, class_line, *(+space_break >> class_line), pop_indent});
577 615
578 ClassDecl = seq({ 616 ClassDecl = seq({
579 key("class"), not_(':'), 617 key("class"), not_(':'),
580 disable_arg_table_block(seq({ 618 disable_arg_table_block_rule(seq({
581 -(Space >> Assignable), 619 -(space >> Assignable),
582 -seq({Space, key("extends"), PreventIndent, Space, ensure(Exp, PopIndent)}), 620 -seq({space, key("extends"), prevent_indent, space, ensure(Exp, pop_indent)}),
583 -seq({Space, key("using"), PreventIndent, Space, ensure(ExpList, PopIndent)}) 621 -seq({space, key("using"), prevent_indent, space, ensure(ExpList, pop_indent)})
584 })), 622 })),
585 -ClassBlock 623 -ClassBlock
586 }); 624 });
587 625
588 global_values = NameList >> -(Space >> '=' >> Space >> (TableBlock | ExpListLow)); 626 GlobalValues = NameList >> -(space >> '=' >> space >> (TableBlock | ExpListLow));
589 global_op = sel({'*', '^'}); 627 GlobalOp = sel({'*', '^'});
590 Global = key("global") >> Space >> sel({ClassDecl, global_op, global_values}); 628 Global = key("global") >> space >> sel({ClassDecl, GlobalOp, GlobalValues});
591 629
592 export_default = key("default"); 630 ExportDefault = key("default");
593 631
594 Export = pl::user(key("export"), [](const item_t& item) { 632 Export = pl::user(key("export"), [](const item_t& item) {
595 State* st = reinterpret_cast<State*>(item.user_data); 633 State* st = reinterpret_cast<State*>(item.user_data);
596 st->exportCount++; 634 st->exportCount++;
597 return true; 635 return true;
598 }) >> (pl::user(Space >> export_default >> Space >> Exp, [](const item_t& item) { 636 }) >> (pl::user(space >> ExportDefault >> space >> Exp, [](const item_t& item) {
599 State* st = reinterpret_cast<State*>(item.user_data); 637 State* st = reinterpret_cast<State*>(item.user_data);
600 if (st->exportDefault) { 638 if (st->exportDefault) {
601 throw ParserError("export default has already been declared", *item.begin, *item.end); 639 throw ParserError("export default has already been declared", *item.begin, *item.end);
@@ -606,99 +644,99 @@ YueParser::YueParser() {
606 st->exportDefault = true; 644 st->exportDefault = true;
607 return true; 645 return true;
608 }) 646 })
609 | (not_(Space >> export_default) >> pl::user(true_(), [](const item_t& item) { 647 | (not_(space >> ExportDefault) >> pl::user(true_(), [](const item_t& item) {
610 State* st = reinterpret_cast<State*>(item.user_data); 648 State* st = reinterpret_cast<State*>(item.user_data);
611 if (st->exportDefault && st->exportCount > 1) { 649 if (st->exportDefault && st->exportCount > 1) {
612 throw ParserError("can not export any more items when 'export default' is declared", *item.begin, *item.end); 650 throw ParserError("can not export any more items when 'export default' is declared", *item.begin, *item.end);
613 } 651 }
614 return true; 652 return true;
615 }) >> Space >> ExpList >> -(Space >> Assign)) 653 }) >> space >> ExpList >> -(space >> Assign))
616 | Space >> pl::user(Macro, [](const item_t& item) { 654 | space >> pl::user(Macro, [](const item_t& item) {
617 State* st = reinterpret_cast<State*>(item.user_data); 655 State* st = reinterpret_cast<State*>(item.user_data);
618 st->exportMacro = true; 656 st->exportMacro = true;
619 return true; 657 return true;
620 })) >> not_(Space >> statement_appendix); 658 })) >> not_(space >> StatementAppendix);
621 659
622 variable_pair = ':' >> Variable; 660 VariablePair = ':' >> Variable;
623 661
624 normal_pair = seq({ 662 NormalPair = seq({
625 sel({ 663 sel({
626 KeyName, 664 KeyName,
627 seq({'[', not_('['), Space, Exp, Space, ']'}), 665 seq({'[', not_('['), space, Exp, space, ']'}),
628 String 666 String
629 }), 667 }),
630 ':', not_(':'), Space, 668 ':', not_(':'), space,
631 sel({Exp, TableBlock, +SpaceBreak >> Space >> Exp}) 669 sel({Exp, TableBlock, +space_break >> space >> Exp})
632 }); 670 });
633 671
634 meta_variable_pair = ":<" >> Space >> Variable >> Space >> '>'; 672 MetaVariablePair = ":<" >> space >> Variable >> space >> '>';
635 673
636 meta_normal_pair = '<' >> Space >> -meta_index >> Space >> ">:" >> Space >> 674 MetaNormalPair = '<' >> space >> -meta_index >> space >> ">:" >> space >>
637 sel({Exp, TableBlock, +(SpaceBreak) >> Space >> Exp}); 675 sel({Exp, TableBlock, +space_break >> space >> Exp});
638 676
639 destruct_def = -seq({Space, '=', Space, Exp}); 677 destruct_def = -seq({space, '=', space, Exp});
640 variable_pair_def = variable_pair >> destruct_def; 678 VariablePairDef = VariablePair >> destruct_def;
641 normal_pair_def = normal_pair >> destruct_def; 679 NormalPairDef = NormalPair >> destruct_def;
642 meta_variable_pair_def = meta_variable_pair >> destruct_def; 680 MetaVariablePairDef = MetaVariablePair >> destruct_def;
643 meta_normal_pair_def = meta_normal_pair >> destruct_def; 681 MetaNormalPairDef = MetaNormalPair >> destruct_def;
644 normal_def = Exp >> Seperator >> destruct_def; 682 NormalDef = Exp >> Seperator >> destruct_def;
645 683
646 KeyValue = sel({ 684 key_value = sel({
647 variable_pair, 685 VariablePair,
648 normal_pair, 686 NormalPair,
649 meta_variable_pair, 687 MetaVariablePair,
650 meta_normal_pair 688 MetaNormalPair
651 }); 689 });
652 KeyValueList = KeyValue >> *(Space >> ',' >> Space >> KeyValue); 690 key_value_list = key_value >> *(space >> ',' >> space >> key_value);
653 KeyValueLine = CheckIndent >> Space >> sel({ 691 key_value_line = check_indent_match >> space >> sel({
654 KeyValueList >> -(Space >> ','), 692 key_value_list >> -(space >> ','),
655 TableBlockIndent, 693 TableBlockIndent,
656 '*' >> Space >> sel({SpreadExp, Exp, TableBlock}) 694 '*' >> space >> sel({SpreadExp, Exp, TableBlock})
657 }); 695 });
658 696
659 FnArgDef = (Variable | SelfName >> -existential_op) >> -(Space >> '=' >> Space >> Exp); 697 FnArgDef = (Variable | SelfItem >> -ExistentialOp) >> -(space >> '=' >> space >> Exp);
660 698
661 FnArgDefList = Seperator >> ( 699 FnArgDefList = Seperator >> (
662 seq({ 700 seq({
663 FnArgDef, 701 FnArgDef,
664 *seq({Space, ',' | Break, White, FnArgDef}), 702 *seq({space, ',' | line_break, white, FnArgDef}),
665 -seq({Space, ',' | Break, White, VarArg}) 703 -seq({space, ',' | line_break, white, VarArg})
666 }) | 704 }) |
667 VarArg 705 VarArg
668 ); 706 );
669 707
670 outer_var_shadow = key("using") >> Space >> (NameList | key("nil")); 708 OuterVarShadow = key("using") >> space >> (NameList | key("nil"));
671 709
672 FnArgsDef = seq({'(', White, -FnArgDefList, -(Space >> outer_var_shadow), White, ')'}); 710 FnArgsDef = seq({'(', white, -FnArgDefList, -(space >> OuterVarShadow), white, ')'});
673 fn_arrow = sel({"->", "=>"}); 711 FnArrow = sel({"->", "=>"});
674 FunLit = seq({-FnArgsDef, Space, fn_arrow, -(Space >> Body)}); 712 FunLit = seq({-FnArgsDef, space, FnArrow, -(space >> Body)});
675 713
676 MacroName = '$' >> Name; 714 MacroName = '$' >> Name;
677 macro_args_def = '(' >> White >> -FnArgDefList >> White >> ')'; 715 macro_args_def = '(' >> white >> -FnArgDefList >> white >> ')';
678 MacroLit = -(macro_args_def >> Space) >> "->" >> Space >> Body; 716 MacroLit = -(macro_args_def >> space) >> "->" >> space >> Body;
679 Macro = key("macro") >> Space >> Name >> Space >> '=' >> Space >> MacroLit; 717 Macro = key("macro") >> space >> Name >> space >> '=' >> space >> MacroLit;
680 MacroInPlace = '$' >> Space >> "->" >> Space >> Body; 718 MacroInPlace = '$' >> space >> "->" >> space >> Body;
681 719
682 NameList = Seperator >> Variable >> *(Space >> ',' >> Space >> Variable); 720 NameList = Seperator >> Variable >> *(space >> ',' >> space >> Variable);
683 NameOrDestructure = Variable | TableLit; 721 NameOrDestructure = Variable | TableLit;
684 AssignableNameList = Seperator >> NameOrDestructure >> *(Space >> ',' >> Space >> NameOrDestructure); 722 AssignableNameList = Seperator >> NameOrDestructure >> *(space >> ',' >> space >> NameOrDestructure);
685 723
686 fn_arrow_back = '<' >> set("-="); 724 FnArrowBack = '<' >> set("-=");
687 Backcall = seq({-(FnArgsDef >> Space), fn_arrow_back, Space, ChainValue}); 725 Backcall = seq({-(FnArgsDef >> space), FnArrowBack, space, ChainValue});
688 726
689 PipeBody = seq({ 727 PipeBody = seq({
690 Seperator, 728 Seperator,
691 PipeOperator, 729 pipe_operator,
692 Space, 730 space,
693 unary_exp, 731 UnaryExp,
694 *seq({+SpaceBreak, CheckIndent, Space, PipeOperator, Space, unary_exp}) 732 *seq({+space_break, check_indent_match, space, pipe_operator, space, UnaryExp})
695 }); 733 });
696 734
697 ExpList = Seperator >> Exp >> *(Space >> ',' >> Space >> Exp); 735 ExpList = Seperator >> Exp >> *(space >> ',' >> space >> Exp);
698 ExpListLow = Seperator >> Exp >> *(Space >> set(",;") >> Space >> Exp); 736 ExpListLow = Seperator >> Exp >> *(space >> set(",;") >> space >> Exp);
699 737
700 ArgLine = CheckIndent >> Space >> Exp >> *(Space >> ',' >> Space >> Exp); 738 arg_line = check_indent_match >> space >> Exp >> *(space >> ',' >> space >> Exp);
701 ArgBlock = ArgLine >> *(Space >> ',' >> SpaceBreak >> ArgLine) >> PopIndent; 739 arg_block = arg_line >> *(space >> ',' >> space_break >> arg_line) >> pop_indent;
702 740
703 arg_table_block = pl::user(true_(), [](const item_t& item) { 741 arg_table_block = pl::user(true_(), [](const item_t& item) {
704 State* st = reinterpret_cast<State*>(item.user_data); 742 State* st = reinterpret_cast<State*>(item.user_data);
@@ -708,38 +746,38 @@ YueParser::YueParser() {
708 invoke_args_with_table = 746 invoke_args_with_table =
709 ',' >> ( 747 ',' >> (
710 TableBlock | 748 TableBlock |
711 SpaceBreak >> Advance >> ArgBlock >> -arg_table_block 749 space_break >> advance_match >> arg_block >> -arg_table_block
712 ) | arg_table_block; 750 ) | arg_table_block;
713 751
714 leading_spaces_error = pl::user(+space_one >> '(' >> Space >> Exp >> +(Space >> ',' >> Space >> Exp) >> Space >> ')', [](const item_t& item) { 752 leading_spaces_error = pl::user(+space_one >> '(' >> space >> Exp >> +(space >> ',' >> space >> Exp) >> space >> ')', [](const item_t& item) {
715 throw ParserError("write invoke arguments in parentheses without leading spaces or just leading spaces without parentheses", *item.begin, *item.end); 753 throw ParserError("write invoke arguments in parentheses without leading spaces or just leading spaces without parentheses", *item.begin, *item.end);
716 return false; 754 return false;
717 }); 755 });
718 756
719 InvokeArgs = 757 InvokeArgs =
720 not_(set("-~")) >> Space >> Seperator >> 758 not_(set("-~")) >> space >> Seperator >>
721 sel({ 759 sel({
722 Exp >> *(Space >> ',' >> Space >> Exp) >> -(Space >> invoke_args_with_table), 760 Exp >> *(space >> ',' >> space >> Exp) >> -(space >> invoke_args_with_table),
723 arg_table_block, 761 arg_table_block,
724 leading_spaces_error 762 leading_spaces_error
725 }); 763 });
726 764
727 const_value = sel({"nil", "true", "false"}) >> not_(AlphaNum); 765 ConstValue = sel({"nil", "true", "false"}) >> not_(alpha_num);
728 766
729 SimpleValue = sel({ 767 SimpleValue = sel({
730 TableLit, const_value, If, Switch, Try, With, 768 TableLit, ConstValue, If, Switch, Try, With,
731 ClassDecl, ForEach, For, While, Do, 769 ClassDecl, ForEach, For, While, Do,
732 unary_value, TblComprehension, Comprehension, 770 UnaryValue, TblComprehension, Comprehension,
733 FunLit, Num 771 FunLit, Num
734 }); 772 });
735 773
736 ExpListAssign = ExpList >> -(Space >> (Update | Assign)) >> not_(Space >> '='); 774 ExpListAssign = ExpList >> -(space >> (Update | Assign)) >> not_(space >> '=');
737 775
738 if_line = IfType >> Space >> IfCond; 776 IfLine = IfType >> space >> IfCond;
739 while_line = WhileType >> Space >> Exp; 777 WhileLine = WhileType >> space >> Exp;
740 778
741 YueLineComment = *(not_(set("\r\n")) >> Any); 779 YueLineComment = *(not_(set("\r\n")) >> any_char);
742 yue_line_comment = "--" >> YueLineComment >> and_(Stop); 780 yue_line_comment = "--" >> YueLineComment >> and_(stop);
743 YueMultilineComment = multi_line_content; 781 YueMultilineComment = multi_line_content;
744 yue_multiline_comment = multi_line_open >> YueMultilineComment >> multi_line_close; 782 yue_multiline_comment = multi_line_open >> YueMultilineComment >> multi_line_close;
745 yue_comment = check_indent >> sel({ 783 yue_comment = check_indent >> sel({
@@ -749,13 +787,13 @@ YueParser::YueParser() {
749 -yue_line_comment 787 -yue_line_comment
750 }), 788 }),
751 yue_line_comment 789 yue_line_comment
752 }) >> and_(Break); 790 }) >> and_(line_break);
753 791
754 ChainAssign = Seperator >> Exp >> +(Space >> '=' >> Space >> Exp >> Space >> and_('=')) >> Space >> Assign; 792 ChainAssign = Seperator >> Exp >> +(space >> '=' >> space >> Exp >> space >> and_('=')) >> space >> Assign;
755 793
756 statement_appendix = sel({if_line, while_line, CompInner}) >> Space; 794 StatementAppendix = sel({IfLine, WhileLine, CompInner}) >> space;
757 statement_sep = and_(seq({ 795 StatementSep = and_(seq({
758 *SpaceBreak, CheckIndent, Space, 796 *space_break, check_indent_match, space,
759 sel({ 797 sel({
760 set("($'\""), 798 set("($'\""),
761 "[[", 799 "[[",
@@ -766,46 +804,46 @@ YueParser::YueParser() {
766 Seperator, 804 Seperator,
767 -seq({ 805 -seq({
768 yue_comment, 806 yue_comment,
769 *(Break >> yue_comment), 807 *(line_break >> yue_comment),
770 Break, 808 line_break,
771 CheckIndent 809 check_indent_match
772 }), 810 }),
773 Space, 811 space,
774 sel({ 812 sel({
775 Import, While, Repeat, For, ForEach, 813 Import, While, Repeat, For, ForEach,
776 Return, Local, Global, Export, Macro, 814 Return, Local, Global, Export, Macro,
777 MacroInPlace, BreakLoop, Label, Goto, ShortTabAppending, 815 MacroInPlace, BreakLoop, Label, Goto, ShortTabAppending,
778 LocalAttrib, Backcall, PipeBody, ExpListAssign, ChainAssign, 816 LocalAttrib, Backcall, PipeBody, ExpListAssign, ChainAssign,
779 statement_appendix >> empty_block_error 817 StatementAppendix >> empty_block_error
780 }), 818 }),
781 Space, 819 space,
782 -statement_appendix, 820 -StatementAppendix,
783 -statement_sep 821 -StatementSep
784 }); 822 });
785 823
786 Body = InBlock | Statement; 824 Body = in_block | Statement;
787 825
788 empty_line_break = sel({ 826 empty_line_break = sel({
789 check_indent >> (MultiLineComment >> Space | Comment), 827 check_indent >> (multi_line_comment >> space | comment),
790 advance >> ensure(MultiLineComment >> Space | Comment, PopIndent), 828 advance >> ensure(multi_line_comment >> space | comment, pop_indent),
791 plain_space 829 plain_space
792 }) >> and_(Break); 830 }) >> and_(line_break);
793 831
794 indentation_error = pl::user(not_(PipeOperator | eof()), [](const item_t& item) { 832 indentation_error = pl::user(not_(pipe_operator | eof()), [](const item_t& item) {
795 throw ParserError("unexpected indent", *item.begin, *item.end); 833 throw ParserError("unexpected indent", *item.begin, *item.end);
796 return false; 834 return false;
797 }); 835 });
798 836
799 Line = sel({ 837 line = sel({
800 CheckIndent >> Statement, 838 check_indent_match >> Statement,
801 empty_line_break, 839 empty_line_break,
802 Advance >> ensure(Space >> (indentation_error | Statement), PopIndent) 840 advance_match >> ensure(space >> (indentation_error | Statement), pop_indent)
803 }); 841 });
804 Block = seq({Seperator, Line, *(+Break >> Line)}); 842 Block = seq({Seperator, line, *(+line_break >> line)});
805 843
806 Shebang = "#!" >> *(not_(Stop) >> Any); 844 shebang = "#!" >> *(not_(stop) >> any_char);
807 BlockEnd = seq({Block, White, Stop}); 845 BlockEnd = seq({Block, white, stop});
808 File = seq({-Shebang, -Block, White, Stop}); 846 File = seq({-shebang, -Block, white, stop});
809} 847}
810// clang-format on 848// clang-format on
811 849
diff --git a/src/yuescript/yue_parser.h b/src/yuescript/yue_parser.h
index 9323422..e98b711 100644
--- a/src/yuescript/yue_parser.h
+++ b/src/yuescript/yue_parser.h
@@ -112,7 +112,7 @@ private:
112 template <class T> 112 template <class T>
113 inline rule& getRule(identity<T>) { 113 inline rule& getRule(identity<T>) {
114 assert(false); 114 assert(false);
115 return Cut; 115 return cut;
116 } 116 }
117 117
118 rule empty_block_error; 118 rule empty_block_error;
@@ -126,94 +126,94 @@ private:
126 rule num_expo_hex; 126 rule num_expo_hex;
127 rule lj_num; 127 rule lj_num;
128 rule plain_space; 128 rule plain_space;
129 rule Break; 129 rule line_break;
130 rule Any; 130 rule any_char;
131 rule White; 131 rule white;
132 rule Stop; 132 rule stop;
133 rule Comment; 133 rule comment;
134 rule multi_line_open; 134 rule multi_line_open;
135 rule multi_line_close; 135 rule multi_line_close;
136 rule multi_line_content; 136 rule multi_line_content;
137 rule MultiLineComment; 137 rule multi_line_comment;
138 rule Indent; 138 rule indent;
139 rule EscapeNewLine; 139 rule escape_new_line;
140 rule space_one; 140 rule space_one;
141 rule Space; 141 rule space;
142 rule SpaceBreak; 142 rule space_break;
143 rule EmptyLine; 143 rule empty_line;
144 rule AlphaNum; 144 rule alpha_num;
145 rule Cut; 145 rule cut;
146 rule check_indent_match;
146 rule check_indent; 147 rule check_indent;
147 rule CheckIndent; 148 rule advance_match;
148 rule advance; 149 rule advance;
149 rule Advance; 150 rule push_indent_match;
150 rule push_indent; 151 rule push_indent;
151 rule PushIndent; 152 rule prevent_indent;
152 rule PreventIndent; 153 rule pop_indent;
153 rule PopIndent; 154 rule in_block;
154 rule InBlock; 155 rule import_name;
155 rule ImportName; 156 rule import_name_list;
156 rule ImportNameList;
157 rule import_literal_chain; 157 rule import_literal_chain;
158 rule ImportTabItem; 158 rule import_tab_item;
159 rule ImportTabList; 159 rule import_tab_list;
160 rule ImportTabLine; 160 rule import_tab_line;
161 rule import_tab_lines; 161 rule import_tab_lines;
162 rule WithExp; 162 rule with_exp;
163 rule DisableDo; 163 rule disable_do;
164 rule EnableDo; 164 rule enable_do;
165 rule DisableChain; 165 rule disable_chain;
166 rule EnableChain; 166 rule enable_chain;
167 rule DisableDoChainArgTableBlock; 167 rule disable_do_chain_arg_table_block;
168 rule EnableDoChainArgTableBlock; 168 rule enable_do_chain_arg_table_block;
169 rule DisableArgTableBlock; 169 rule disable_arg_table_block;
170 rule EnableArgTableBlock; 170 rule enable_arg_table_block;
171 rule SwitchElse; 171 rule switch_else;
172 rule SwitchBlock; 172 rule switch_block;
173 rule IfElseIf; 173 rule if_else_if;
174 rule IfElse; 174 rule if_else;
175 rule for_args; 175 rule for_args;
176 rule for_in; 176 rule for_in;
177 rule CompClause; 177 rule comp_clause;
178 rule Chain; 178 rule chain;
179 rule ChainList; 179 rule chain_list;
180 rule KeyValue; 180 rule key_value;
181 rule single_string_inner; 181 rule single_string_inner;
182 rule interp; 182 rule interp;
183 rule double_string_plain; 183 rule double_string_plain;
184 rule lua_string_open; 184 rule lua_string_open;
185 rule lua_string_close; 185 rule lua_string_close;
186 rule FnArgsExpList; 186 rule fn_args_exp_list;
187 rule FnArgs; 187 rule fn_args;
188 rule destruct_def; 188 rule destruct_def;
189 rule macro_args_def; 189 rule macro_args_def;
190 rule chain_call; 190 rule chain_call;
191 rule chain_call_list; 191 rule chain_call_list;
192 rule chain_index_chain; 192 rule chain_index_chain;
193 rule ChainItems; 193 rule chain_items;
194 rule chain_dot_chain; 194 rule chain_dot_chain;
195 rule ColonChain; 195 rule colon_chain;
196 rule chain_with_colon; 196 rule chain_with_colon;
197 rule ChainItem; 197 rule chain_item;
198 rule chain_line; 198 rule chain_line;
199 rule chain_block; 199 rule chain_block;
200 rule meta_index; 200 rule meta_index;
201 rule Index; 201 rule index;
202 rule invoke_chain; 202 rule invoke_chain;
203 rule TableValue; 203 rule table_value;
204 rule table_lit_lines; 204 rule table_lit_lines;
205 rule TableLitLine; 205 rule table_lit_line;
206 rule TableValueList; 206 rule table_value_list;
207 rule TableBlockInner; 207 rule table_block_inner;
208 rule ClassLine; 208 rule class_line;
209 rule KeyValueLine; 209 rule key_value_line;
210 rule KeyValueList; 210 rule key_value_list;
211 rule ArgLine; 211 rule arg_line;
212 rule ArgBlock; 212 rule arg_block;
213 rule invoke_args_with_table; 213 rule invoke_args_with_table;
214 rule arg_table_block; 214 rule arg_table_block;
215 rule PipeOperator; 215 rule pipe_operator;
216 rule ExponentialOperator; 216 rule exponential_operator;
217 rule pipe_value; 217 rule pipe_value;
218 rule pipe_exp; 218 rule pipe_exp;
219 rule expo_value; 219 rule expo_value;
@@ -224,42 +224,42 @@ private:
224 rule yue_comment; 224 rule yue_comment;
225 rule yue_line_comment; 225 rule yue_line_comment;
226 rule yue_multiline_comment; 226 rule yue_multiline_comment;
227 rule Line; 227 rule line;
228 rule Shebang; 228 rule shebang;
229 229
230 AST_RULE(Num) 230 AST_RULE(Num)
231 AST_RULE(Name) 231 AST_RULE(Name)
232 AST_RULE(Variable) 232 AST_RULE(Variable)
233 AST_RULE(LabelName) 233 AST_RULE(LabelName)
234 AST_RULE(LuaKeyword) 234 AST_RULE(LuaKeyword)
235 AST_RULE(self) 235 AST_RULE(Self)
236 AST_RULE(self_name)
237 AST_RULE(self_class)
238 AST_RULE(self_class_name)
239 AST_RULE(SelfName) 236 AST_RULE(SelfName)
237 AST_RULE(SelfClass)
238 AST_RULE(SelfClassName)
239 AST_RULE(SelfItem)
240 AST_RULE(KeyName) 240 AST_RULE(KeyName)
241 AST_RULE(VarArg) 241 AST_RULE(VarArg)
242 AST_RULE(Seperator) 242 AST_RULE(Seperator)
243 AST_RULE(NameList) 243 AST_RULE(NameList)
244 AST_RULE(local_flag) 244 AST_RULE(LocalFlag)
245 AST_RULE(local_values) 245 AST_RULE(LocalValues)
246 AST_RULE(Local) 246 AST_RULE(Local)
247 AST_RULE(const_attrib) 247 AST_RULE(ConstAttrib)
248 AST_RULE(close_attrib) 248 AST_RULE(CloseAttrib)
249 AST_RULE(LocalAttrib); 249 AST_RULE(LocalAttrib);
250 AST_RULE(colon_import_name) 250 AST_RULE(ColonImportName)
251 AST_RULE(import_literal_inner) 251 AST_RULE(ImportLiteralInner)
252 AST_RULE(ImportLiteral) 252 AST_RULE(ImportLiteral)
253 AST_RULE(ImportFrom) 253 AST_RULE(ImportFrom)
254 AST_RULE(macro_name_pair) 254 AST_RULE(MacroNamePair)
255 AST_RULE(import_all_macro) 255 AST_RULE(ImportAllMacro)
256 AST_RULE(ImportTabLit) 256 AST_RULE(ImportTabLit)
257 AST_RULE(ImportAs) 257 AST_RULE(ImportAs)
258 AST_RULE(Import) 258 AST_RULE(Import)
259 AST_RULE(Label) 259 AST_RULE(Label)
260 AST_RULE(Goto) 260 AST_RULE(Goto)
261 AST_RULE(ShortTabAppending) 261 AST_RULE(ShortTabAppending)
262 AST_RULE(fn_arrow_back) 262 AST_RULE(FnArrowBack)
263 AST_RULE(Backcall) 263 AST_RULE(Backcall)
264 AST_RULE(PipeBody) 264 AST_RULE(PipeBody)
265 AST_RULE(ExpListLow) 265 AST_RULE(ExpListLow)
@@ -269,38 +269,38 @@ private:
269 AST_RULE(SwitchList) 269 AST_RULE(SwitchList)
270 AST_RULE(SwitchCase) 270 AST_RULE(SwitchCase)
271 AST_RULE(Switch) 271 AST_RULE(Switch)
272 AST_RULE(assignment) 272 AST_RULE(Assignment)
273 AST_RULE(IfCond) 273 AST_RULE(IfCond)
274 AST_RULE(IfType) 274 AST_RULE(IfType)
275 AST_RULE(If) 275 AST_RULE(If)
276 AST_RULE(WhileType) 276 AST_RULE(WhileType)
277 AST_RULE(While) 277 AST_RULE(While)
278 AST_RULE(Repeat) 278 AST_RULE(Repeat)
279 AST_RULE(for_step_value) 279 AST_RULE(ForStepValue)
280 AST_RULE(For) 280 AST_RULE(For)
281 AST_RULE(ForEach) 281 AST_RULE(ForEach)
282 AST_RULE(Do) 282 AST_RULE(Do)
283 AST_RULE(catch_block) 283 AST_RULE(CatchBlock)
284 AST_RULE(Try) 284 AST_RULE(Try)
285 AST_RULE(Comprehension) 285 AST_RULE(Comprehension)
286 AST_RULE(comp_value) 286 AST_RULE(CompValue)
287 AST_RULE(TblComprehension) 287 AST_RULE(TblComprehension)
288 AST_RULE(star_exp) 288 AST_RULE(StarExp)
289 AST_RULE(CompForEach) 289 AST_RULE(CompForEach)
290 AST_RULE(CompFor) 290 AST_RULE(CompFor)
291 AST_RULE(CompInner) 291 AST_RULE(CompInner)
292 AST_RULE(Assign) 292 AST_RULE(Assign)
293 AST_RULE(update_op) 293 AST_RULE(UpdateOp)
294 AST_RULE(Update) 294 AST_RULE(Update)
295 AST_RULE(BinaryOperator) 295 AST_RULE(BinaryOperator)
296 AST_RULE(unary_operator) 296 AST_RULE(UnaryOperator)
297 AST_RULE(Assignable) 297 AST_RULE(Assignable)
298 AST_RULE(AssignableChain) 298 AST_RULE(AssignableChain)
299 AST_RULE(exp_op_value) 299 AST_RULE(ExpOpValue)
300 AST_RULE(Exp) 300 AST_RULE(Exp)
301 AST_RULE(Callable) 301 AST_RULE(Callable)
302 AST_RULE(ChainValue) 302 AST_RULE(ChainValue)
303 AST_RULE(simple_table) 303 AST_RULE(SimpleTable)
304 AST_RULE(SimpleValue) 304 AST_RULE(SimpleValue)
305 AST_RULE(Value) 305 AST_RULE(Value)
306 AST_RULE(LuaStringOpen); 306 AST_RULE(LuaStringOpen);
@@ -308,8 +308,8 @@ private:
308 AST_RULE(LuaStringClose); 308 AST_RULE(LuaStringClose);
309 AST_RULE(LuaString) 309 AST_RULE(LuaString)
310 AST_RULE(SingleString) 310 AST_RULE(SingleString)
311 AST_RULE(double_string_inner) 311 AST_RULE(DoubleStringInner)
312 AST_RULE(double_string_content) 312 AST_RULE(DoubleStringContent)
313 AST_RULE(DoubleString) 313 AST_RULE(DoubleString)
314 AST_RULE(String) 314 AST_RULE(String)
315 AST_RULE(Parens) 315 AST_RULE(Parens)
@@ -317,37 +317,37 @@ private:
317 AST_RULE(ColonChainItem) 317 AST_RULE(ColonChainItem)
318 AST_RULE(Metatable) 318 AST_RULE(Metatable)
319 AST_RULE(Metamethod) 319 AST_RULE(Metamethod)
320 AST_RULE(default_value) 320 AST_RULE(DefaultValue)
321 AST_RULE(Slice) 321 AST_RULE(Slice)
322 AST_RULE(Invoke) 322 AST_RULE(Invoke)
323 AST_RULE(existential_op) 323 AST_RULE(ExistentialOp)
324 AST_RULE(table_appending_op) 324 AST_RULE(TableAppendingOp)
325 AST_RULE(SpreadExp) 325 AST_RULE(SpreadExp)
326 AST_RULE(TableLit) 326 AST_RULE(TableLit)
327 AST_RULE(TableBlock) 327 AST_RULE(TableBlock)
328 AST_RULE(TableBlockIndent) 328 AST_RULE(TableBlockIndent)
329 AST_RULE(class_member_list) 329 AST_RULE(ClassMemberList)
330 AST_RULE(ClassBlock) 330 AST_RULE(ClassBlock)
331 AST_RULE(ClassDecl) 331 AST_RULE(ClassDecl)
332 AST_RULE(global_values) 332 AST_RULE(GlobalValues)
333 AST_RULE(global_op) 333 AST_RULE(GlobalOp)
334 AST_RULE(Global) 334 AST_RULE(Global)
335 AST_RULE(export_default) 335 AST_RULE(ExportDefault)
336 AST_RULE(Export) 336 AST_RULE(Export)
337 AST_RULE(variable_pair) 337 AST_RULE(VariablePair)
338 AST_RULE(normal_pair) 338 AST_RULE(NormalPair)
339 AST_RULE(meta_variable_pair) 339 AST_RULE(MetaVariablePair)
340 AST_RULE(meta_normal_pair) 340 AST_RULE(MetaNormalPair)
341 AST_RULE(variable_pair_def) 341 AST_RULE(VariablePairDef)
342 AST_RULE(normal_pair_def) 342 AST_RULE(NormalPairDef)
343 AST_RULE(normal_def) 343 AST_RULE(NormalDef)
344 AST_RULE(meta_variable_pair_def) 344 AST_RULE(MetaVariablePairDef)
345 AST_RULE(meta_normal_pair_def) 345 AST_RULE(MetaNormalPairDef)
346 AST_RULE(FnArgDef) 346 AST_RULE(FnArgDef)
347 AST_RULE(FnArgDefList) 347 AST_RULE(FnArgDefList)
348 AST_RULE(outer_var_shadow) 348 AST_RULE(OuterVarShadow)
349 AST_RULE(FnArgsDef) 349 AST_RULE(FnArgsDef)
350 AST_RULE(fn_arrow) 350 AST_RULE(FnArrow)
351 AST_RULE(FunLit) 351 AST_RULE(FunLit)
352 AST_RULE(MacroName) 352 AST_RULE(MacroName)
353 AST_RULE(MacroLit) 353 AST_RULE(MacroLit)
@@ -356,15 +356,15 @@ private:
356 AST_RULE(NameOrDestructure) 356 AST_RULE(NameOrDestructure)
357 AST_RULE(AssignableNameList) 357 AST_RULE(AssignableNameList)
358 AST_RULE(InvokeArgs) 358 AST_RULE(InvokeArgs)
359 AST_RULE(const_value) 359 AST_RULE(ConstValue)
360 AST_RULE(unary_value) 360 AST_RULE(UnaryValue)
361 AST_RULE(unary_exp) 361 AST_RULE(UnaryExp)
362 AST_RULE(ExpListAssign) 362 AST_RULE(ExpListAssign)
363 AST_RULE(if_line) 363 AST_RULE(IfLine)
364 AST_RULE(while_line) 364 AST_RULE(WhileLine)
365 AST_RULE(BreakLoop) 365 AST_RULE(BreakLoop)
366 AST_RULE(statement_appendix) 366 AST_RULE(StatementAppendix)
367 AST_RULE(statement_sep) 367 AST_RULE(StatementSep)
368 AST_RULE(Statement) 368 AST_RULE(Statement)
369 AST_RULE(YueLineComment) 369 AST_RULE(YueLineComment)
370 AST_RULE(YueMultilineComment) 370 AST_RULE(YueMultilineComment)