aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2024-08-09 02:55:56 +0800
committerLi Jin <dragon-fly@qq.com>2024-08-09 02:55:56 +0800
commitb6c86d19d74ac90a2450cf979a92187e691ea5fa (patch)
tree6073623a0cca27aa64c68f0c554116e7475e0531
parent94edfbc8c7d62d700dfb59334a0ed3beedd49493 (diff)
downloadyuescript-b6c86d19d74ac90a2450cf979a92187e691ea5fa.tar.gz
yuescript-b6c86d19d74ac90a2450cf979a92187e691ea5fa.tar.bz2
yuescript-b6c86d19d74ac90a2450cf979a92187e691ea5fa.zip
add yue.is_ast().
-rw-r--r--spec/inputs/macro.yue8
-rw-r--r--spec/outputs/macro.lua6
-rw-r--r--src/yuescript/yue_ast.h322
-rw-r--r--src/yuescript/yue_compiler.cpp48
-rw-r--r--src/yuescript/yue_parser.cpp27
-rw-r--r--src/yuescript/yue_parser.h21
-rw-r--r--src/yuescript/yuescript.cpp26
7 files changed, 269 insertions, 189 deletions
diff --git a/spec/inputs/macro.yue b/spec/inputs/macro.yue
index a2e1046..3d4fb10 100644
--- a/spec/inputs/macro.yue
+++ b/spec/inputs/macro.yue
@@ -38,6 +38,14 @@ print $WindowFlag(
38 NoScrollbar 38 NoScrollbar
39) 39)
40 40
41macro NumAndStr = (num, str) ->
42 import "yue"
43 unless yue.is_ast("Num", "123")
44 error "unmatched tokens got"
45 "[#{num}, #{str}]"
46
47print $NumAndStr 123, 'xyz'
48
41$asserts item == nil 49$asserts item == nil
42 50
43$myconfig false 51$myconfig false
diff --git a/spec/outputs/macro.lua b/spec/outputs/macro.lua
index 953c260..4492827 100644
--- a/spec/outputs/macro.lua
+++ b/spec/outputs/macro.lua
@@ -7,6 +7,10 @@ print({
7 "NoMove", 7 "NoMove",
8 "NoScrollbar" 8 "NoScrollbar"
9}) 9})
10print({
11 123,
12 'xyz'
13})
10do 14do
11 assert(item == nil) 15 assert(item == nil)
12end 16end
@@ -294,7 +298,7 @@ print((setmetatable({
294 return 998 298 return 998
295 end 299 end
296})) 300}))
297print("current line: " .. tostring(301)) 301print("current line: " .. tostring(309))
298do 302do
299-- TODO 303-- TODO
300end 304end
diff --git a/src/yuescript/yue_ast.h b/src/yuescript/yue_ast.h
index b287202..7bf17fe 100644
--- a/src/yuescript/yue_ast.h
+++ b/src/yuescript/yue_ast.h
@@ -12,13 +12,17 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
12 12
13namespace parserlib { 13namespace parserlib {
14 14
15template <class T>
16std::string_view ast_name() { }
17
15#define AST_LEAF(type) \ 18#define AST_LEAF(type) \
16 COUNTER_INC; \ 19 COUNTER_INC; \
17 namespace yue { \ 20 namespace yue { \
18 class type##_t : public ast_node { \ 21 class type##_t : public ast_node { \
19 public: \ 22 public: \
20 virtual int get_id() const override { return COUNTER_READ; } \ 23 virtual int get_id() const override { return COUNTER_READ; } \
21 virtual std::string to_string(void*) const override; 24 virtual std::string to_string(void*) const override; \
25 virtual const std::string_view get_name() const override { return #type ""sv; }
22 26
23#define AST_NODE(type) \ 27#define AST_NODE(type) \
24 COUNTER_INC; \ 28 COUNTER_INC; \
@@ -26,20 +30,22 @@ namespace parserlib {
26 class type##_t : public ast_container { \ 30 class type##_t : public ast_container { \
27 public: \ 31 public: \
28 virtual int get_id() const override { return COUNTER_READ; } \ 32 virtual int get_id() const override { return COUNTER_READ; } \
29 virtual std::string to_string(void*) const override; 33 virtual std::string to_string(void*) const override; \
34 virtual const std::string_view get_name() const override { return #type ""sv; }
30 35
31#define AST_MEMBER(type, ...) \ 36#define AST_MEMBER(type, ...) \
32 type##_t() { \ 37 type##_t() { \
33 add_members({__VA_ARGS__}); \ 38 add_members({__VA_ARGS__}); \
34 } 39 }
35 40
36#define AST_END(type, name) \ 41#define AST_END(type) \
37 virtual const std::string_view get_name() const override { return name; } \
38 } \ 42 } \
39 ; \ 43 ; \
40 } \ 44 } \
41 template <> \ 45 template <> \
42 constexpr int id<yue::type##_t>() { return COUNTER_READ; } 46 constexpr int id<yue::type##_t>() { return COUNTER_READ; } \
47 template <> \
48 constexpr std::string_view ast_name<yue::type##_t>() { return #type ""sv; }
43 49
44// clang-format off 50// clang-format off
45 51
@@ -85,75 +91,75 @@ class Value_t;
85} // namespace yue 91} // namespace yue
86 92
87AST_LEAF(Num) 93AST_LEAF(Num)
88AST_END(Num, "num"sv) 94AST_END(Num)
89 95
90AST_LEAF(Name) 96AST_LEAF(Name)
91AST_END(Name, "name"sv) 97AST_END(Name)
92 98
93AST_LEAF(UnicodeName) 99AST_LEAF(UnicodeName)
94AST_END(UnicodeName, "unicode_name"sv) 100AST_END(UnicodeName)
95 101
96AST_NODE(Variable) 102AST_NODE(Variable)
97 ast_sel<true, Name_t, UnicodeName_t> name; 103 ast_sel<true, Name_t, UnicodeName_t> name;
98 AST_MEMBER(Variable, &name) 104 AST_MEMBER(Variable, &name)
99AST_END(Variable, "variable"sv) 105AST_END(Variable)
100 106
101AST_NODE(LabelName) 107AST_NODE(LabelName)
102 ast_ptr<true, UnicodeName_t> name; 108 ast_ptr<true, UnicodeName_t> name;
103 AST_MEMBER(LabelName, &name) 109 AST_MEMBER(LabelName, &name)
104AST_END(LabelName, "label_name"sv) 110AST_END(LabelName)
105 111
106AST_NODE(LuaKeyword) 112AST_NODE(LuaKeyword)
107 ast_ptr<true, Name_t> name; 113 ast_ptr<true, Name_t> name;
108 AST_MEMBER(LuaKeyword, &name) 114 AST_MEMBER(LuaKeyword, &name)
109AST_END(LuaKeyword, "lua_keyword"sv) 115AST_END(LuaKeyword)
110 116
111AST_LEAF(Self) 117AST_LEAF(Self)
112AST_END(Self, "self"sv) 118AST_END(Self)
113 119
114AST_NODE(SelfName) 120AST_NODE(SelfName)
115 ast_sel<true, Name_t, UnicodeName_t> name; 121 ast_sel<true, Name_t, UnicodeName_t> name;
116 AST_MEMBER(SelfName, &name) 122 AST_MEMBER(SelfName, &name)
117AST_END(SelfName, "self_name"sv) 123AST_END(SelfName)
118 124
119AST_LEAF(SelfClass) 125AST_LEAF(SelfClass)
120AST_END(SelfClass, "self_class"sv) 126AST_END(SelfClass)
121 127
122AST_NODE(SelfClassName) 128AST_NODE(SelfClassName)
123 ast_sel<true, Name_t, UnicodeName_t> name; 129 ast_sel<true, Name_t, UnicodeName_t> name;
124 AST_MEMBER(SelfClassName, &name) 130 AST_MEMBER(SelfClassName, &name)
125AST_END(SelfClassName, "self_class_name"sv) 131AST_END(SelfClassName)
126 132
127AST_NODE(SelfItem) 133AST_NODE(SelfItem)
128 ast_sel<true, SelfClassName_t, SelfClass_t, SelfName_t, Self_t> name; 134 ast_sel<true, SelfClassName_t, SelfClass_t, SelfName_t, Self_t> name;
129 AST_MEMBER(SelfItem, &name) 135 AST_MEMBER(SelfItem, &name)
130AST_END(SelfItem, "self_item"sv) 136AST_END(SelfItem)
131 137
132AST_NODE(KeyName) 138AST_NODE(KeyName)
133 ast_sel<true, SelfItem_t, Name_t, UnicodeName_t> name; 139 ast_sel<true, SelfItem_t, Name_t, UnicodeName_t> name;
134 AST_MEMBER(KeyName, &name) 140 AST_MEMBER(KeyName, &name)
135AST_END(KeyName, "key_name"sv) 141AST_END(KeyName)
136 142
137AST_LEAF(VarArg) 143AST_LEAF(VarArg)
138AST_END(VarArg, "var_arg"sv) 144AST_END(VarArg)
139 145
140AST_LEAF(LocalFlag) 146AST_LEAF(LocalFlag)
141AST_END(LocalFlag, "local_flag"sv) 147AST_END(LocalFlag)
142 148
143AST_LEAF(Seperator) 149AST_LEAF(Seperator)
144AST_END(Seperator, "seperator"sv) 150AST_END(Seperator)
145 151
146AST_NODE(NameList) 152AST_NODE(NameList)
147 ast_ptr<true, Seperator_t> sep; 153 ast_ptr<true, Seperator_t> sep;
148 ast_list<true, Variable_t> names; 154 ast_list<true, Variable_t> names;
149 AST_MEMBER(NameList, &sep, &names) 155 AST_MEMBER(NameList, &sep, &names)
150AST_END(NameList, "name_list"sv) 156AST_END(NameList)
151 157
152AST_NODE(LocalValues) 158AST_NODE(LocalValues)
153 ast_ptr<true, NameList_t> nameList; 159 ast_ptr<true, NameList_t> nameList;
154 ast_sel<false, TableBlock_t, ExpListLow_t> valueList; 160 ast_sel<false, TableBlock_t, ExpListLow_t> valueList;
155 AST_MEMBER(LocalValues, &nameList, &valueList) 161 AST_MEMBER(LocalValues, &nameList, &valueList)
156AST_END(LocalValues, "local_values"sv) 162AST_END(LocalValues)
157 163
158AST_NODE(Local) 164AST_NODE(Local)
159 ast_sel<true, LocalFlag_t, LocalValues_t> item; 165 ast_sel<true, LocalFlag_t, LocalValues_t> item;
@@ -162,13 +168,13 @@ AST_NODE(Local)
162 bool collected = false; 168 bool collected = false;
163 bool defined = false; 169 bool defined = false;
164 AST_MEMBER(Local, &item) 170 AST_MEMBER(Local, &item)
165AST_END(Local, "local"sv) 171AST_END(Local)
166 172
167AST_LEAF(ConstAttrib) 173AST_LEAF(ConstAttrib)
168AST_END(ConstAttrib, "const"sv) 174AST_END(ConstAttrib)
169 175
170AST_LEAF(CloseAttrib) 176AST_LEAF(CloseAttrib)
171AST_END(CloseAttrib, "close"sv) 177AST_END(CloseAttrib)
172 178
173AST_NODE(LocalAttrib) 179AST_NODE(LocalAttrib)
174 ast_sel<true, ConstAttrib_t, CloseAttrib_t> attrib; 180 ast_sel<true, ConstAttrib_t, CloseAttrib_t> attrib;
@@ -176,104 +182,104 @@ AST_NODE(LocalAttrib)
176 ast_sel_list<true, Variable_t, SimpleTable_t, TableLit_t, Comprehension_t> leftList; 182 ast_sel_list<true, Variable_t, SimpleTable_t, TableLit_t, Comprehension_t> leftList;
177 ast_ptr<true, Assign_t> assign; 183 ast_ptr<true, Assign_t> assign;
178 AST_MEMBER(LocalAttrib, &attrib, &sep, &leftList, &assign) 184 AST_MEMBER(LocalAttrib, &attrib, &sep, &leftList, &assign)
179AST_END(LocalAttrib, "local_attrib"sv) 185AST_END(LocalAttrib)
180 186
181AST_NODE(ColonImportName) 187AST_NODE(ColonImportName)
182 ast_ptr<true, Variable_t> name; 188 ast_ptr<true, Variable_t> name;
183 AST_MEMBER(ColonImportName, &name) 189 AST_MEMBER(ColonImportName, &name)
184AST_END(ColonImportName, "colon_import_name"sv) 190AST_END(ColonImportName)
185 191
186AST_LEAF(ImportLiteralInner) 192AST_LEAF(ImportLiteralInner)
187AST_END(ImportLiteralInner, "import_literal_inner"sv) 193AST_END(ImportLiteralInner)
188 194
189AST_NODE(ImportLiteral) 195AST_NODE(ImportLiteral)
190 ast_ptr<true, Seperator_t> sep; 196 ast_ptr<true, Seperator_t> sep;
191 ast_sel_list<true, ImportLiteralInner_t> inners; 197 ast_sel_list<true, ImportLiteralInner_t> inners;
192 AST_MEMBER(ImportLiteral, &sep, &inners) 198 AST_MEMBER(ImportLiteral, &sep, &inners)
193AST_END(ImportLiteral, "import_literal"sv) 199AST_END(ImportLiteral)
194 200
195AST_NODE(ImportFrom) 201AST_NODE(ImportFrom)
196 ast_ptr<true, Seperator_t> sep; 202 ast_ptr<true, Seperator_t> sep;
197 ast_sel_list<true, ColonImportName_t, Variable_t> names; 203 ast_sel_list<true, ColonImportName_t, Variable_t> names;
198 ast_sel<true, ImportLiteral_t, Exp_t> item; 204 ast_sel<true, ImportLiteral_t, Exp_t> item;
199 AST_MEMBER(ImportFrom, &sep, &names, &item) 205 AST_MEMBER(ImportFrom, &sep, &names, &item)
200AST_END(ImportFrom, "import_from"sv) 206AST_END(ImportFrom)
201 207
202AST_NODE(FromImport) 208AST_NODE(FromImport)
203 ast_sel<true, ImportLiteral_t, Exp_t> item; 209 ast_sel<true, ImportLiteral_t, Exp_t> item;
204 ast_ptr<true, Seperator_t> sep; 210 ast_ptr<true, Seperator_t> sep;
205 ast_sel_list<true, ColonImportName_t, Variable_t> names; 211 ast_sel_list<true, ColonImportName_t, Variable_t> names;
206 AST_MEMBER(FromImport, &item, &sep, &names) 212 AST_MEMBER(FromImport, &item, &sep, &names)
207AST_END(FromImport, "from_import"sv) 213AST_END(FromImport)
208 214
209AST_NODE(MacroNamePair) 215AST_NODE(MacroNamePair)
210 ast_ptr<true, MacroName_t> key; 216 ast_ptr<true, MacroName_t> key;
211 ast_ptr<true, MacroName_t> value; 217 ast_ptr<true, MacroName_t> value;
212 AST_MEMBER(MacroNamePair, &key, &value) 218 AST_MEMBER(MacroNamePair, &key, &value)
213AST_END(MacroNamePair, "macro_name_pair"sv) 219AST_END(MacroNamePair)
214 220
215AST_LEAF(ImportAllMacro) 221AST_LEAF(ImportAllMacro)
216AST_END(ImportAllMacro, "import_all_macro"sv) 222AST_END(ImportAllMacro)
217 223
218AST_NODE(ImportTabLit) 224AST_NODE(ImportTabLit)
219 ast_ptr<true, Seperator_t> sep; 225 ast_ptr<true, Seperator_t> sep;
220 ast_sel_list<false, VariablePair_t, NormalPair_t, MacroName_t, MacroNamePair_t, ImportAllMacro_t, Exp_t, MetaVariablePair_t, MetaNormalPair_t> items; 226 ast_sel_list<false, VariablePair_t, NormalPair_t, MacroName_t, MacroNamePair_t, ImportAllMacro_t, Exp_t, MetaVariablePair_t, MetaNormalPair_t> items;
221 AST_MEMBER(ImportTabLit, &sep, &items) 227 AST_MEMBER(ImportTabLit, &sep, &items)
222AST_END(ImportTabLit, "import_tab_lit"sv) 228AST_END(ImportTabLit)
223 229
224AST_NODE(ImportAs) 230AST_NODE(ImportAs)
225 ast_ptr<true, ImportLiteral_t> literal; 231 ast_ptr<true, ImportLiteral_t> literal;
226 ast_sel<false, Variable_t, ImportTabLit_t, ImportAllMacro_t> target; 232 ast_sel<false, Variable_t, ImportTabLit_t, ImportAllMacro_t> target;
227 AST_MEMBER(ImportAs, &literal, &target) 233 AST_MEMBER(ImportAs, &literal, &target)
228AST_END(ImportAs, "import_as"sv) 234AST_END(ImportAs)
229 235
230AST_NODE(Import) 236AST_NODE(Import)
231 ast_sel<true, ImportAs_t, ImportFrom_t, FromImport_t> content; 237 ast_sel<true, ImportAs_t, ImportFrom_t, FromImport_t> content;
232 AST_MEMBER(Import, &content) 238 AST_MEMBER(Import, &content)
233AST_END(Import, "import"sv) 239AST_END(Import)
234 240
235AST_NODE(Label) 241AST_NODE(Label)
236 ast_ptr<true, LabelName_t> label; 242 ast_ptr<true, LabelName_t> label;
237 AST_MEMBER(Label, &label) 243 AST_MEMBER(Label, &label)
238AST_END(Label, "label"sv) 244AST_END(Label)
239 245
240AST_NODE(Goto) 246AST_NODE(Goto)
241 ast_ptr<true, LabelName_t> label; 247 ast_ptr<true, LabelName_t> label;
242 AST_MEMBER(Goto, &label) 248 AST_MEMBER(Goto, &label)
243AST_END(Goto, "goto"sv) 249AST_END(Goto)
244 250
245AST_NODE(ShortTabAppending) 251AST_NODE(ShortTabAppending)
246 ast_ptr<true, Assign_t> assign; 252 ast_ptr<true, Assign_t> assign;
247 AST_MEMBER(ShortTabAppending, &assign) 253 AST_MEMBER(ShortTabAppending, &assign)
248AST_END(ShortTabAppending, "short_table_appending"sv) 254AST_END(ShortTabAppending)
249 255
250AST_LEAF(FnArrowBack) 256AST_LEAF(FnArrowBack)
251AST_END(FnArrowBack, "fn_arrow_back"sv) 257AST_END(FnArrowBack)
252 258
253AST_NODE(Backcall) 259AST_NODE(Backcall)
254 ast_ptr<false, FnArgsDef_t> argsDef; 260 ast_ptr<false, FnArgsDef_t> argsDef;
255 ast_ptr<true, FnArrowBack_t> arrow; 261 ast_ptr<true, FnArrowBack_t> arrow;
256 ast_ptr<true, ChainValue_t> value; 262 ast_ptr<true, ChainValue_t> value;
257 AST_MEMBER(Backcall, &argsDef, &arrow, &value) 263 AST_MEMBER(Backcall, &argsDef, &arrow, &value)
258AST_END(Backcall, "backcall"sv) 264AST_END(Backcall)
259 265
260AST_NODE(ExpListLow) 266AST_NODE(ExpListLow)
261 ast_ptr<true, Seperator_t> sep; 267 ast_ptr<true, Seperator_t> sep;
262 ast_list<true, Exp_t> exprs; 268 ast_list<true, Exp_t> exprs;
263 AST_MEMBER(ExpListLow, &sep, &exprs) 269 AST_MEMBER(ExpListLow, &sep, &exprs)
264AST_END(ExpListLow, "exp_list_low"sv) 270AST_END(ExpListLow)
265 271
266AST_NODE(ExpList) 272AST_NODE(ExpList)
267 ast_ptr<true, Seperator_t> sep; 273 ast_ptr<true, Seperator_t> sep;
268 ast_list<true, Exp_t> exprs; 274 ast_list<true, Exp_t> exprs;
269 AST_MEMBER(ExpList, &sep, &exprs) 275 AST_MEMBER(ExpList, &sep, &exprs)
270AST_END(ExpList, "exp_list"sv) 276AST_END(ExpList)
271 277
272AST_NODE(Return) 278AST_NODE(Return)
273 bool allowBlockMacroReturn = false; 279 bool allowBlockMacroReturn = false;
274 ast_sel<false, TableBlock_t, ExpListLow_t> valueList; 280 ast_sel<false, TableBlock_t, ExpListLow_t> valueList;
275 AST_MEMBER(Return, &valueList) 281 AST_MEMBER(Return, &valueList)
276AST_END(Return, "return"sv) 282AST_END(Return)
277 283
278AST_NODE(With) 284AST_NODE(With)
279 ast_ptr<false, ExistentialOp_t> eop; 285 ast_ptr<false, ExistentialOp_t> eop;
@@ -281,19 +287,19 @@ AST_NODE(With)
281 ast_ptr<false, Assign_t> assigns; 287 ast_ptr<false, Assign_t> assigns;
282 ast_sel<true, Block_t, Statement_t> body; 288 ast_sel<true, Block_t, Statement_t> body;
283 AST_MEMBER(With, &eop, &valueList, &assigns, &body) 289 AST_MEMBER(With, &eop, &valueList, &assigns, &body)
284AST_END(With, "with"sv) 290AST_END(With)
285 291
286AST_NODE(SwitchList) 292AST_NODE(SwitchList)
287 ast_ptr<true, Seperator_t> sep; 293 ast_ptr<true, Seperator_t> sep;
288 ast_list<true, Exp_t> exprs; 294 ast_list<true, Exp_t> exprs;
289 AST_MEMBER(SwitchList, &sep, &exprs) 295 AST_MEMBER(SwitchList, &sep, &exprs)
290AST_END(SwitchList, "switch_list"sv) 296AST_END(SwitchList)
291 297
292AST_NODE(SwitchCase) 298AST_NODE(SwitchCase)
293 ast_ptr<true, SwitchList_t> condition; 299 ast_ptr<true, SwitchList_t> condition;
294 ast_sel<true, Block_t, Statement_t> body; 300 ast_sel<true, Block_t, Statement_t> body;
295 AST_MEMBER(SwitchCase, &condition, &body) 301 AST_MEMBER(SwitchCase, &condition, &body)
296AST_END(SwitchCase, "switch_case"sv) 302AST_END(SwitchCase)
297 303
298AST_NODE(Switch) 304AST_NODE(Switch)
299 ast_ptr<true, Exp_t> target; 305 ast_ptr<true, Exp_t> target;
@@ -301,49 +307,49 @@ AST_NODE(Switch)
301 ast_list<true, SwitchCase_t> branches; 307 ast_list<true, SwitchCase_t> branches;
302 ast_sel<false, Block_t, Statement_t> lastBranch; 308 ast_sel<false, Block_t, Statement_t> lastBranch;
303 AST_MEMBER(Switch, &target, &sep, &branches, &lastBranch) 309 AST_MEMBER(Switch, &target, &sep, &branches, &lastBranch)
304AST_END(Switch, "switch"sv) 310AST_END(Switch)
305 311
306AST_NODE(Assignment) 312AST_NODE(Assignment)
307 ast_ptr<false, ExpList_t> expList; 313 ast_ptr<false, ExpList_t> expList;
308 ast_ptr<true, Assign_t> assign; 314 ast_ptr<true, Assign_t> assign;
309 AST_MEMBER(Assignment, &expList, &assign) 315 AST_MEMBER(Assignment, &expList, &assign)
310AST_END(Assignment, "assignment"sv) 316AST_END(Assignment)
311 317
312AST_NODE(IfCond) 318AST_NODE(IfCond)
313 ast_ptr<true, Exp_t> condition; 319 ast_ptr<true, Exp_t> condition;
314 ast_ptr<false, Assignment_t> assignment; 320 ast_ptr<false, Assignment_t> assignment;
315 AST_MEMBER(IfCond, &condition, &assignment) 321 AST_MEMBER(IfCond, &condition, &assignment)
316AST_END(IfCond, "if_cond"sv) 322AST_END(IfCond)
317 323
318AST_LEAF(IfType) 324AST_LEAF(IfType)
319AST_END(IfType, "if_type"sv) 325AST_END(IfType)
320 326
321AST_NODE(If) 327AST_NODE(If)
322 ast_ptr<true, IfType_t> type; 328 ast_ptr<true, IfType_t> type;
323 ast_sel_list<true, IfCond_t, Block_t, Statement_t> nodes; 329 ast_sel_list<true, IfCond_t, Block_t, Statement_t> nodes;
324 AST_MEMBER(If, &type, &nodes) 330 AST_MEMBER(If, &type, &nodes)
325AST_END(If, "if"sv) 331AST_END(If)
326 332
327AST_LEAF(WhileType) 333AST_LEAF(WhileType)
328AST_END(WhileType, "while_type"sv) 334AST_END(WhileType)
329 335
330AST_NODE(While) 336AST_NODE(While)
331 ast_ptr<true, WhileType_t> type; 337 ast_ptr<true, WhileType_t> type;
332 ast_ptr<true, Exp_t> condition; 338 ast_ptr<true, Exp_t> condition;
333 ast_sel<true, Block_t, Statement_t> body; 339 ast_sel<true, Block_t, Statement_t> body;
334 AST_MEMBER(While, &type, &condition, &body) 340 AST_MEMBER(While, &type, &condition, &body)
335AST_END(While, "while"sv) 341AST_END(While)
336 342
337AST_NODE(Repeat) 343AST_NODE(Repeat)
338 ast_ptr<true, Body_t> body; 344 ast_ptr<true, Body_t> body;
339 ast_ptr<true, Exp_t> condition; 345 ast_ptr<true, Exp_t> condition;
340 AST_MEMBER(Repeat, &body, &condition) 346 AST_MEMBER(Repeat, &body, &condition)
341AST_END(Repeat, "repeat"sv) 347AST_END(Repeat)
342 348
343AST_NODE(ForStepValue) 349AST_NODE(ForStepValue)
344 ast_ptr<true, Exp_t> value; 350 ast_ptr<true, Exp_t> value;
345 AST_MEMBER(ForStepValue, &value) 351 AST_MEMBER(ForStepValue, &value)
346AST_END(ForStepValue, "for_step_value"sv) 352AST_END(ForStepValue)
347 353
348AST_NODE(For) 354AST_NODE(For)
349 ast_ptr<true, Variable_t> varName; 355 ast_ptr<true, Variable_t> varName;
@@ -352,61 +358,61 @@ AST_NODE(For)
352 ast_ptr<false, ForStepValue_t> stepValue; 358 ast_ptr<false, ForStepValue_t> stepValue;
353 ast_sel<true, Block_t, Statement_t> body; 359 ast_sel<true, Block_t, Statement_t> body;
354 AST_MEMBER(For, &varName, &startValue, &stopValue, &stepValue, &body) 360 AST_MEMBER(For, &varName, &startValue, &stopValue, &stepValue, &body)
355AST_END(For, "for"sv) 361AST_END(For)
356 362
357AST_NODE(ForEach) 363AST_NODE(ForEach)
358 ast_ptr<true, AssignableNameList_t> nameList; 364 ast_ptr<true, AssignableNameList_t> nameList;
359 ast_sel<true, StarExp_t, ExpList_t> loopValue; 365 ast_sel<true, StarExp_t, ExpList_t> loopValue;
360 ast_sel<true, Block_t, Statement_t> body; 366 ast_sel<true, Block_t, Statement_t> body;
361 AST_MEMBER(ForEach, &nameList, &loopValue, &body) 367 AST_MEMBER(ForEach, &nameList, &loopValue, &body)
362AST_END(ForEach, "for_each"sv) 368AST_END(ForEach)
363 369
364AST_NODE(Do) 370AST_NODE(Do)
365 ast_ptr<true, Body_t> body; 371 ast_ptr<true, Body_t> body;
366 AST_MEMBER(Do, &body) 372 AST_MEMBER(Do, &body)
367AST_END(Do, "do"sv) 373AST_END(Do)
368 374
369AST_NODE(CatchBlock) 375AST_NODE(CatchBlock)
370 ast_ptr<true, Variable_t> err; 376 ast_ptr<true, Variable_t> err;
371 ast_ptr<true, Block_t> block; 377 ast_ptr<true, Block_t> block;
372 AST_MEMBER(CatchBlock, &err, &block) 378 AST_MEMBER(CatchBlock, &err, &block)
373AST_END(CatchBlock, "catch_block"sv) 379AST_END(CatchBlock)
374 380
375AST_NODE(Try) 381AST_NODE(Try)
376 ast_sel<true, Block_t, Exp_t> func; 382 ast_sel<true, Block_t, Exp_t> func;
377 ast_ptr<false, CatchBlock_t> catchBlock; 383 ast_ptr<false, CatchBlock_t> catchBlock;
378 AST_MEMBER(Try, &func, &catchBlock) 384 AST_MEMBER(Try, &func, &catchBlock)
379AST_END(Try, "try"sv) 385AST_END(Try)
380 386
381AST_NODE(Comprehension) 387AST_NODE(Comprehension)
382 ast_ptr<true, Seperator_t> sep; 388 ast_ptr<true, Seperator_t> sep;
383 ast_sel_list<false, NormalDef_t, SpreadListExp_t, CompInner_t, 389 ast_sel_list<false, NormalDef_t, SpreadListExp_t, CompInner_t,
384 /*non-syntax-rule*/ Statement_t> items; 390 /*non-syntax-rule*/ Statement_t> items;
385 AST_MEMBER(Comprehension, &sep, &items) 391 AST_MEMBER(Comprehension, &sep, &items)
386AST_END(Comprehension, "comp"sv) 392AST_END(Comprehension)
387 393
388AST_NODE(CompValue) 394AST_NODE(CompValue)
389 ast_ptr<true, Exp_t> value; 395 ast_ptr<true, Exp_t> value;
390 AST_MEMBER(CompValue, &value) 396 AST_MEMBER(CompValue, &value)
391AST_END(CompValue, "comp_value"sv) 397AST_END(CompValue)
392 398
393AST_NODE(TblComprehension) 399AST_NODE(TblComprehension)
394 ast_ptr<true, Exp_t> key; 400 ast_ptr<true, Exp_t> key;
395 ast_ptr<false, CompValue_t> value; 401 ast_ptr<false, CompValue_t> value;
396 ast_ptr<true, CompInner_t> forLoop; 402 ast_ptr<true, CompInner_t> forLoop;
397 AST_MEMBER(TblComprehension, &key, &value, &forLoop) 403 AST_MEMBER(TblComprehension, &key, &value, &forLoop)
398AST_END(TblComprehension, "tbl_comp"sv) 404AST_END(TblComprehension)
399 405
400AST_NODE(StarExp) 406AST_NODE(StarExp)
401 ast_ptr<true, Exp_t> value; 407 ast_ptr<true, Exp_t> value;
402 AST_MEMBER(StarExp, &value) 408 AST_MEMBER(StarExp, &value)
403AST_END(StarExp, "star_exp"sv) 409AST_END(StarExp)
404 410
405AST_NODE(CompForEach) 411AST_NODE(CompForEach)
406 ast_ptr<true, AssignableNameList_t> nameList; 412 ast_ptr<true, AssignableNameList_t> nameList;
407 ast_sel<true, StarExp_t, Exp_t> loopValue; 413 ast_sel<true, StarExp_t, Exp_t> loopValue;
408 AST_MEMBER(CompForEach, &nameList, &loopValue) 414 AST_MEMBER(CompForEach, &nameList, &loopValue)
409AST_END(CompForEach, "comp_for_each"sv) 415AST_END(CompForEach)
410 416
411AST_NODE(CompFor) 417AST_NODE(CompFor)
412 ast_ptr<true, Variable_t> varName; 418 ast_ptr<true, Variable_t> varName;
@@ -414,54 +420,54 @@ AST_NODE(CompFor)
414 ast_ptr<true, Exp_t> stopValue; 420 ast_ptr<true, Exp_t> stopValue;
415 ast_ptr<false, ForStepValue_t> stepValue; 421 ast_ptr<false, ForStepValue_t> stepValue;
416 AST_MEMBER(CompFor, &varName, &startValue, &stopValue, &stepValue) 422 AST_MEMBER(CompFor, &varName, &startValue, &stopValue, &stepValue)
417AST_END(CompFor, "comp_for"sv) 423AST_END(CompFor)
418 424
419AST_NODE(CompInner) 425AST_NODE(CompInner)
420 ast_ptr<true, Seperator_t> sep; 426 ast_ptr<true, Seperator_t> sep;
421 ast_sel_list<true, CompFor_t, CompForEach_t, Exp_t> items; 427 ast_sel_list<true, CompFor_t, CompForEach_t, Exp_t> items;
422 AST_MEMBER(CompInner, &sep, &items) 428 AST_MEMBER(CompInner, &sep, &items)
423AST_END(CompInner, "comp_inner"sv) 429AST_END(CompInner)
424 430
425AST_NODE(Assign) 431AST_NODE(Assign)
426 ast_ptr<true, Seperator_t> sep; 432 ast_ptr<true, Seperator_t> sep;
427 ast_sel_list<true, With_t, If_t, Switch_t, TableBlock_t, Exp_t> values; 433 ast_sel_list<true, With_t, If_t, Switch_t, TableBlock_t, Exp_t> values;
428 AST_MEMBER(Assign, &sep, &values) 434 AST_MEMBER(Assign, &sep, &values)
429AST_END(Assign, "assign"sv) 435AST_END(Assign)
430 436
431AST_LEAF(UpdateOp) 437AST_LEAF(UpdateOp)
432AST_END(UpdateOp, "update_op"sv) 438AST_END(UpdateOp)
433 439
434AST_NODE(Update) 440AST_NODE(Update)
435 ast_ptr<true, UpdateOp_t> op; 441 ast_ptr<true, UpdateOp_t> op;
436 ast_ptr<true, Exp_t> value; 442 ast_ptr<true, Exp_t> value;
437 AST_MEMBER(Update, &op, &value) 443 AST_MEMBER(Update, &op, &value)
438AST_END(Update, "update"sv) 444AST_END(Update)
439 445
440AST_LEAF(BinaryOperator) 446AST_LEAF(BinaryOperator)
441AST_END(BinaryOperator, "binary_op"sv) 447AST_END(BinaryOperator)
442 448
443AST_LEAF(UnaryOperator) 449AST_LEAF(UnaryOperator)
444AST_END(UnaryOperator, "unary_op"sv) 450AST_END(UnaryOperator)
445 451
446AST_LEAF(NotIn) 452AST_LEAF(NotIn)
447AST_END(NotIn, "not_in"sv) 453AST_END(NotIn)
448 454
449AST_NODE(In) 455AST_NODE(In)
450 ast_ptr<false, NotIn_t> not_; 456 ast_ptr<false, NotIn_t> not_;
451 ast_ptr<true, Value_t> value; 457 ast_ptr<true, Value_t> value;
452 AST_MEMBER(In, &not_, &value) 458 AST_MEMBER(In, &not_, &value)
453AST_END(In, "in"sv) 459AST_END(In)
454 460
455AST_NODE(Assignable) 461AST_NODE(Assignable)
456 ast_sel<true, AssignableChain_t, Variable_t, SelfItem_t> item; 462 ast_sel<true, AssignableChain_t, Variable_t, SelfItem_t> item;
457 AST_MEMBER(Assignable, &item) 463 AST_MEMBER(Assignable, &item)
458AST_END(Assignable, "assignable"sv) 464AST_END(Assignable)
459 465
460AST_NODE(ExpOpValue) 466AST_NODE(ExpOpValue)
461 ast_ptr<true, BinaryOperator_t> op; 467 ast_ptr<true, BinaryOperator_t> op;
462 ast_list<true, UnaryExp_t> pipeExprs; 468 ast_list<true, UnaryExp_t> pipeExprs;
463 AST_MEMBER(ExpOpValue, &op, &pipeExprs) 469 AST_MEMBER(ExpOpValue, &op, &pipeExprs)
464AST_END(ExpOpValue, "exp_op_value"sv) 470AST_END(ExpOpValue)
465 471
466AST_NODE(Exp) 472AST_NODE(Exp)
467 ast_ptr<true, Seperator_t> sep; 473 ast_ptr<true, Seperator_t> sep;
@@ -469,71 +475,71 @@ AST_NODE(Exp)
469 ast_list<false, ExpOpValue_t> opValues; 475 ast_list<false, ExpOpValue_t> opValues;
470 ast_ptr<false, Exp_t> nilCoalesed; 476 ast_ptr<false, Exp_t> nilCoalesed;
471 AST_MEMBER(Exp, &sep, &pipeExprs, &opValues, &nilCoalesed) 477 AST_MEMBER(Exp, &sep, &pipeExprs, &opValues, &nilCoalesed)
472AST_END(Exp, "exp"sv) 478AST_END(Exp)
473 479
474AST_NODE(Callable) 480AST_NODE(Callable)
475 ast_sel<true, Variable_t, SelfItem_t, Parens_t, MacroName_t> item; 481 ast_sel<true, Variable_t, SelfItem_t, Parens_t, MacroName_t> item;
476 AST_MEMBER(Callable, &item) 482 AST_MEMBER(Callable, &item)
477AST_END(Callable, "callable"sv) 483AST_END(Callable)
478 484
479AST_NODE(VariablePair) 485AST_NODE(VariablePair)
480 ast_ptr<true, Variable_t> name; 486 ast_ptr<true, Variable_t> name;
481 AST_MEMBER(VariablePair, &name) 487 AST_MEMBER(VariablePair, &name)
482AST_END(VariablePair, "variable_pair"sv) 488AST_END(VariablePair)
483 489
484AST_NODE(VariablePairDef) 490AST_NODE(VariablePairDef)
485 ast_ptr<true, VariablePair_t> pair; 491 ast_ptr<true, VariablePair_t> pair;
486 ast_ptr<false, Exp_t> defVal; 492 ast_ptr<false, Exp_t> defVal;
487 AST_MEMBER(VariablePairDef, &pair, &defVal) 493 AST_MEMBER(VariablePairDef, &pair, &defVal)
488AST_END(VariablePairDef, "variable_pair_def"sv) 494AST_END(VariablePairDef)
489 495
490AST_NODE(NormalPair) 496AST_NODE(NormalPair)
491 ast_sel<true, KeyName_t, Exp_t, String_t> key; 497 ast_sel<true, KeyName_t, Exp_t, String_t> key;
492 ast_sel<true, Exp_t, TableBlock_t> value; 498 ast_sel<true, Exp_t, TableBlock_t> value;
493 AST_MEMBER(NormalPair, &key, &value) 499 AST_MEMBER(NormalPair, &key, &value)
494AST_END(NormalPair, "normal_pair"sv) 500AST_END(NormalPair)
495 501
496AST_NODE(NormalPairDef) 502AST_NODE(NormalPairDef)
497 ast_ptr<true, NormalPair_t> pair; 503 ast_ptr<true, NormalPair_t> pair;
498 ast_ptr<false, Exp_t> defVal; 504 ast_ptr<false, Exp_t> defVal;
499 AST_MEMBER(NormalPairDef, &pair, &defVal) 505 AST_MEMBER(NormalPairDef, &pair, &defVal)
500AST_END(NormalPairDef, "normal_pair_def"sv) 506AST_END(NormalPairDef)
501 507
502AST_NODE(NormalDef) 508AST_NODE(NormalDef)
503 ast_ptr<true, Exp_t> item; 509 ast_ptr<true, Exp_t> item;
504 ast_ptr<true, Seperator_t> sep; 510 ast_ptr<true, Seperator_t> sep;
505 ast_ptr<false, Exp_t> defVal; 511 ast_ptr<false, Exp_t> defVal;
506 AST_MEMBER(NormalDef, &item, &sep, &defVal) 512 AST_MEMBER(NormalDef, &item, &sep, &defVal)
507AST_END(NormalDef, "normal_def") 513AST_END(NormalDef)
508 514
509AST_NODE(MetaVariablePair) 515AST_NODE(MetaVariablePair)
510 ast_ptr<true, Variable_t> name; 516 ast_ptr<true, Variable_t> name;
511 AST_MEMBER(MetaVariablePair, &name) 517 AST_MEMBER(MetaVariablePair, &name)
512AST_END(MetaVariablePair, "meta_variable_pair"sv) 518AST_END(MetaVariablePair)
513 519
514AST_NODE(MetaVariablePairDef) 520AST_NODE(MetaVariablePairDef)
515 ast_ptr<true, MetaVariablePair_t> pair; 521 ast_ptr<true, MetaVariablePair_t> pair;
516 ast_ptr<false, Exp_t> defVal; 522 ast_ptr<false, Exp_t> defVal;
517 AST_MEMBER(MetaVariablePairDef, &pair, &defVal) 523 AST_MEMBER(MetaVariablePairDef, &pair, &defVal)
518AST_END(MetaVariablePairDef, "meta_variable_pair_def"sv) 524AST_END(MetaVariablePairDef)
519 525
520AST_NODE(MetaNormalPair) 526AST_NODE(MetaNormalPair)
521 ast_sel<false, Name_t, Exp_t, String_t> key; 527 ast_sel<false, Name_t, Exp_t, String_t> key;
522 ast_sel<true, Exp_t, TableBlock_t> value; 528 ast_sel<true, Exp_t, TableBlock_t> value;
523 AST_MEMBER(MetaNormalPair, &key, &value) 529 AST_MEMBER(MetaNormalPair, &key, &value)
524AST_END(MetaNormalPair, "meta_normal_pair"sv) 530AST_END(MetaNormalPair)
525 531
526AST_NODE(MetaNormalPairDef) 532AST_NODE(MetaNormalPairDef)
527 ast_ptr<true, MetaNormalPair_t> pair; 533 ast_ptr<true, MetaNormalPair_t> pair;
528 ast_ptr<false, Exp_t> defVal; 534 ast_ptr<false, Exp_t> defVal;
529 AST_MEMBER(MetaNormalPairDef, &pair, &defVal) 535 AST_MEMBER(MetaNormalPairDef, &pair, &defVal)
530AST_END(MetaNormalPairDef, "meta_normal_pair_def"sv) 536AST_END(MetaNormalPairDef)
531 537
532AST_NODE(SimpleTable) 538AST_NODE(SimpleTable)
533 ast_ptr<true, Seperator_t> sep; 539 ast_ptr<true, Seperator_t> sep;
534 ast_sel_list<true, VariablePair_t, NormalPair_t, MetaVariablePair_t, MetaNormalPair_t> pairs; 540 ast_sel_list<true, VariablePair_t, NormalPair_t, MetaVariablePair_t, MetaNormalPair_t> pairs;
535 AST_MEMBER(SimpleTable, &sep, &pairs) 541 AST_MEMBER(SimpleTable, &sep, &pairs)
536AST_END(SimpleTable, "simple_table"sv) 542AST_END(SimpleTable)
537 543
538AST_NODE(SimpleValue) 544AST_NODE(SimpleValue)
539 ast_sel<true, 545 ast_sel<true,
@@ -544,118 +550,118 @@ AST_NODE(SimpleValue)
544 TblComprehension_t, Comprehension_t, 550 TblComprehension_t, Comprehension_t,
545 FunLit_t, Num_t, VarArg_t> value; 551 FunLit_t, Num_t, VarArg_t> value;
546 AST_MEMBER(SimpleValue, &value) 552 AST_MEMBER(SimpleValue, &value)
547AST_END(SimpleValue, "simple_value"sv) 553AST_END(SimpleValue)
548 554
549AST_LEAF(LuaStringOpen) 555AST_LEAF(LuaStringOpen)
550AST_END(LuaStringOpen, "lua_string_open"sv) 556AST_END(LuaStringOpen)
551 557
552AST_LEAF(LuaStringContent) 558AST_LEAF(LuaStringContent)
553AST_END(LuaStringContent, "lua_string_content"sv) 559AST_END(LuaStringContent)
554 560
555AST_LEAF(LuaStringClose) 561AST_LEAF(LuaStringClose)
556AST_END(LuaStringClose, "lua_string_close"sv) 562AST_END(LuaStringClose)
557 563
558AST_NODE(LuaString) 564AST_NODE(LuaString)
559 ast_ptr<true, LuaStringOpen_t> open; 565 ast_ptr<true, LuaStringOpen_t> open;
560 ast_ptr<true, LuaStringContent_t> content; 566 ast_ptr<true, LuaStringContent_t> content;
561 ast_ptr<true, LuaStringClose_t> close; 567 ast_ptr<true, LuaStringClose_t> close;
562 AST_MEMBER(LuaString, &open, &content, &close) 568 AST_MEMBER(LuaString, &open, &content, &close)
563AST_END(LuaString, "lua_string"sv) 569AST_END(LuaString)
564 570
565AST_LEAF(SingleString) 571AST_LEAF(SingleString)
566AST_END(SingleString, "single_string"sv) 572AST_END(SingleString)
567 573
568AST_LEAF(DoubleStringInner) 574AST_LEAF(DoubleStringInner)
569AST_END(DoubleStringInner, "double_string_inner"sv) 575AST_END(DoubleStringInner)
570 576
571AST_NODE(DoubleStringContent) 577AST_NODE(DoubleStringContent)
572 ast_sel<true, DoubleStringInner_t, Exp_t> content; 578 ast_sel<true, DoubleStringInner_t, Exp_t> content;
573 AST_MEMBER(DoubleStringContent, &content) 579 AST_MEMBER(DoubleStringContent, &content)
574AST_END(DoubleStringContent, "double_string_content"sv) 580AST_END(DoubleStringContent)
575 581
576AST_NODE(DoubleString) 582AST_NODE(DoubleString)
577 ast_ptr<true, Seperator_t> sep; 583 ast_ptr<true, Seperator_t> sep;
578 ast_list<false, DoubleStringContent_t> segments; 584 ast_list<false, DoubleStringContent_t> segments;
579 AST_MEMBER(DoubleString, &sep, &segments) 585 AST_MEMBER(DoubleString, &sep, &segments)
580AST_END(DoubleString, "double_string"sv) 586AST_END(DoubleString)
581 587
582AST_NODE(String) 588AST_NODE(String)
583 ast_sel<true, DoubleString_t, SingleString_t, LuaString_t> str; 589 ast_sel<true, DoubleString_t, SingleString_t, LuaString_t> str;
584 AST_MEMBER(String, &str) 590 AST_MEMBER(String, &str)
585AST_END(String, "string"sv) 591AST_END(String)
586 592
587AST_LEAF(Metatable) 593AST_LEAF(Metatable)
588AST_END(Metatable, "metatable"sv) 594AST_END(Metatable)
589 595
590AST_NODE(Metamethod) 596AST_NODE(Metamethod)
591 ast_sel<true, Name_t, Exp_t, String_t> item; 597 ast_sel<true, Name_t, Exp_t, String_t> item;
592 AST_MEMBER(Metamethod, &item) 598 AST_MEMBER(Metamethod, &item)
593AST_END(Metamethod, "metamethod"sv) 599AST_END(Metamethod)
594 600
595AST_NODE(DotChainItem) 601AST_NODE(DotChainItem)
596 ast_sel<true, Name_t, Metatable_t, Metamethod_t, UnicodeName_t> name; 602 ast_sel<true, Name_t, Metatable_t, Metamethod_t, UnicodeName_t> name;
597 AST_MEMBER(DotChainItem, &name) 603 AST_MEMBER(DotChainItem, &name)
598AST_END(DotChainItem, "dot_chain_item"sv) 604AST_END(DotChainItem)
599 605
600AST_NODE(ColonChainItem) 606AST_NODE(ColonChainItem)
601 ast_sel<true, Name_t, LuaKeyword_t, Metamethod_t, UnicodeName_t> name; 607 ast_sel<true, Name_t, LuaKeyword_t, Metamethod_t, UnicodeName_t> name;
602 bool switchToDot = false; 608 bool switchToDot = false;
603 AST_MEMBER(ColonChainItem, &name) 609 AST_MEMBER(ColonChainItem, &name)
604AST_END(ColonChainItem, "colon_chain_item"sv) 610AST_END(ColonChainItem)
605 611
606AST_NODE(Slice) 612AST_NODE(Slice)
607 ast_sel<true, Exp_t, DefaultValue_t> startValue; 613 ast_sel<true, Exp_t, DefaultValue_t> startValue;
608 ast_sel<true, Exp_t, DefaultValue_t> stopValue; 614 ast_sel<true, Exp_t, DefaultValue_t> stopValue;
609 ast_sel<true, Exp_t, DefaultValue_t> stepValue; 615 ast_sel<true, Exp_t, DefaultValue_t> stepValue;
610 AST_MEMBER(Slice, &startValue, &stopValue, &stepValue) 616 AST_MEMBER(Slice, &startValue, &stopValue, &stepValue)
611AST_END(Slice, "slice"sv) 617AST_END(Slice)
612 618
613AST_NODE(Parens) 619AST_NODE(Parens)
614 ast_ptr<true, Exp_t> expr; 620 ast_ptr<true, Exp_t> expr;
615 AST_MEMBER(Parens, &expr) 621 AST_MEMBER(Parens, &expr)
616AST_END(Parens, "parens"sv) 622AST_END(Parens)
617 623
618AST_NODE(Invoke) 624AST_NODE(Invoke)
619 ast_ptr<true, Seperator_t> sep; 625 ast_ptr<true, Seperator_t> sep;
620 ast_sel_list<false, Exp_t, SingleString_t, DoubleString_t, LuaString_t, TableLit_t> args; 626 ast_sel_list<false, Exp_t, SingleString_t, DoubleString_t, LuaString_t, TableLit_t> args;
621 AST_MEMBER(Invoke, &sep, &args) 627 AST_MEMBER(Invoke, &sep, &args)
622AST_END(Invoke, "invoke"sv) 628AST_END(Invoke)
623 629
624AST_LEAF(ExistentialOp) 630AST_LEAF(ExistentialOp)
625AST_END(ExistentialOp, "existential_op"sv) 631AST_END(ExistentialOp)
626 632
627AST_LEAF(TableAppendingOp) 633AST_LEAF(TableAppendingOp)
628AST_END(TableAppendingOp, "table_appending_op"sv) 634AST_END(TableAppendingOp)
629 635
630AST_NODE(ChainValue) 636AST_NODE(ChainValue)
631 ast_ptr<true, Seperator_t> sep; 637 ast_ptr<true, Seperator_t> sep;
632 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; 638 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;
633 AST_MEMBER(ChainValue, &sep, &items) 639 AST_MEMBER(ChainValue, &sep, &items)
634AST_END(ChainValue, "chain_value"sv) 640AST_END(ChainValue)
635 641
636AST_NODE(AssignableChain) 642AST_NODE(AssignableChain)
637 ast_ptr<true, Seperator_t> sep; 643 ast_ptr<true, Seperator_t> sep;
638 ast_sel_list<true, Callable_t, Invoke_t, DotChainItem_t, ColonChainItem_t, Exp_t, String_t> items; 644 ast_sel_list<true, Callable_t, Invoke_t, DotChainItem_t, ColonChainItem_t, Exp_t, String_t> items;
639 AST_MEMBER(AssignableChain, &sep, &items) 645 AST_MEMBER(AssignableChain, &sep, &items)
640AST_END(AssignableChain, "assignable_chain"sv) 646AST_END(AssignableChain)
641 647
642AST_NODE(Value) 648AST_NODE(Value)
643 ast_sel<true, SimpleValue_t, SimpleTable_t, ChainValue_t, String_t> item; 649 ast_sel<true, SimpleValue_t, SimpleTable_t, ChainValue_t, String_t> item;
644 AST_MEMBER(Value, &item) 650 AST_MEMBER(Value, &item)
645AST_END(Value, "value"sv) 651AST_END(Value)
646 652
647AST_LEAF(DefaultValue) 653AST_LEAF(DefaultValue)
648AST_END(DefaultValue, "default_value"sv) 654AST_END(DefaultValue)
649 655
650AST_NODE(SpreadExp) 656AST_NODE(SpreadExp)
651 ast_ptr<true, Exp_t> exp; 657 ast_ptr<true, Exp_t> exp;
652 AST_MEMBER(SpreadExp, &exp) 658 AST_MEMBER(SpreadExp, &exp)
653AST_END(SpreadExp, "spread_exp"sv) 659AST_END(SpreadExp)
654 660
655AST_NODE(SpreadListExp) 661AST_NODE(SpreadListExp)
656 ast_ptr<true, Exp_t> exp; 662 ast_ptr<true, Exp_t> exp;
657 AST_MEMBER(SpreadListExp, &exp) 663 AST_MEMBER(SpreadListExp, &exp)
658AST_END(SpreadListExp, "spread_list_exp"sv) 664AST_END(SpreadListExp)
659 665
660AST_NODE(TableLit) 666AST_NODE(TableLit)
661 ast_ptr<true, Seperator_t> sep; 667 ast_ptr<true, Seperator_t> sep;
@@ -666,7 +672,7 @@ AST_NODE(TableLit)
666 MetaVariablePair_t, MetaNormalPair_t, 672 MetaVariablePair_t, MetaNormalPair_t,
667 /*non-syntax-rule*/ TableBlockIndent_t, SpreadListExp_t> values; 673 /*non-syntax-rule*/ TableBlockIndent_t, SpreadListExp_t> values;
668 AST_MEMBER(TableLit, &sep, &values) 674 AST_MEMBER(TableLit, &sep, &values)
669AST_END(TableLit, "table_lit"sv) 675AST_END(TableLit)
670 676
671AST_NODE(TableBlockIndent) 677AST_NODE(TableBlockIndent)
672 ast_ptr<true, Seperator_t> sep; 678 ast_ptr<true, Seperator_t> sep;
@@ -674,25 +680,25 @@ AST_NODE(TableBlockIndent)
674 VariablePair_t, NormalPair_t, Exp_t, TableBlockIndent_t, 680 VariablePair_t, NormalPair_t, Exp_t, TableBlockIndent_t,
675 MetaVariablePair_t, MetaNormalPair_t> values; 681 MetaVariablePair_t, MetaNormalPair_t> values;
676 AST_MEMBER(TableBlockIndent, &sep, &values) 682 AST_MEMBER(TableBlockIndent, &sep, &values)
677AST_END(TableBlockIndent, "table_block_indent"sv) 683AST_END(TableBlockIndent)
678 684
679AST_NODE(TableBlock) 685AST_NODE(TableBlock)
680 ast_ptr<true, Seperator_t> sep; 686 ast_ptr<true, Seperator_t> sep;
681 ast_sel_list<false, VariablePair_t, NormalPair_t, TableBlockIndent_t, Exp_t, TableBlock_t, SpreadExp_t, MetaVariablePair_t, MetaNormalPair_t> values; 687 ast_sel_list<false, VariablePair_t, NormalPair_t, TableBlockIndent_t, Exp_t, TableBlock_t, SpreadExp_t, MetaVariablePair_t, MetaNormalPair_t> values;
682 AST_MEMBER(TableBlock, &sep, &values) 688 AST_MEMBER(TableBlock, &sep, &values)
683AST_END(TableBlock, "table_block"sv) 689AST_END(TableBlock)
684 690
685AST_NODE(ClassMemberList) 691AST_NODE(ClassMemberList)
686 ast_ptr<true, Seperator_t> sep; 692 ast_ptr<true, Seperator_t> sep;
687 ast_sel_list<true, VariablePair_t, NormalPair_t, MetaVariablePair_t, MetaNormalPair_t> values; 693 ast_sel_list<true, VariablePair_t, NormalPair_t, MetaVariablePair_t, MetaNormalPair_t> values;
688 AST_MEMBER(ClassMemberList, &sep, &values) 694 AST_MEMBER(ClassMemberList, &sep, &values)
689AST_END(ClassMemberList, "class_member_list"sv) 695AST_END(ClassMemberList)
690 696
691AST_NODE(ClassBlock) 697AST_NODE(ClassBlock)
692 ast_ptr<true, Seperator_t> sep; 698 ast_ptr<true, Seperator_t> sep;
693 ast_sel_list<true, ClassMemberList_t, Statement_t> contents; 699 ast_sel_list<true, ClassMemberList_t, Statement_t> contents;
694 AST_MEMBER(ClassBlock, &sep, &contents) 700 AST_MEMBER(ClassBlock, &sep, &contents)
695AST_END(ClassBlock, "class_block"sv) 701AST_END(ClassBlock)
696 702
697AST_NODE(ClassDecl) 703AST_NODE(ClassDecl)
698 ast_ptr<false, Assignable_t> name; 704 ast_ptr<false, Assignable_t> name;
@@ -700,59 +706,59 @@ AST_NODE(ClassDecl)
700 ast_ptr<false, ExpList_t> mixes; 706 ast_ptr<false, ExpList_t> mixes;
701 ast_ptr<false, ClassBlock_t> body; 707 ast_ptr<false, ClassBlock_t> body;
702 AST_MEMBER(ClassDecl, &name, &extend, &mixes, &body) 708 AST_MEMBER(ClassDecl, &name, &extend, &mixes, &body)
703AST_END(ClassDecl, "class_decl"sv) 709AST_END(ClassDecl)
704 710
705AST_NODE(GlobalValues) 711AST_NODE(GlobalValues)
706 ast_ptr<true, NameList_t> nameList; 712 ast_ptr<true, NameList_t> nameList;
707 ast_sel<false, TableBlock_t, ExpListLow_t> valueList; 713 ast_sel<false, TableBlock_t, ExpListLow_t> valueList;
708 AST_MEMBER(GlobalValues, &nameList, &valueList) 714 AST_MEMBER(GlobalValues, &nameList, &valueList)
709AST_END(GlobalValues, "global_values"sv) 715AST_END(GlobalValues)
710 716
711AST_LEAF(GlobalOp) 717AST_LEAF(GlobalOp)
712AST_END(GlobalOp, "global_op"sv) 718AST_END(GlobalOp)
713 719
714AST_NODE(Global) 720AST_NODE(Global)
715 ast_sel<true, ClassDecl_t, GlobalOp_t, GlobalValues_t> item; 721 ast_sel<true, ClassDecl_t, GlobalOp_t, GlobalValues_t> item;
716 AST_MEMBER(Global, &item) 722 AST_MEMBER(Global, &item)
717AST_END(Global, "global"sv) 723AST_END(Global)
718 724
719AST_LEAF(ExportDefault) 725AST_LEAF(ExportDefault)
720AST_END(ExportDefault, "export_default"sv) 726AST_END(ExportDefault)
721 727
722AST_NODE(Export) 728AST_NODE(Export)
723 ast_ptr<false, ExportDefault_t> def; 729 ast_ptr<false, ExportDefault_t> def;
724 ast_sel<true, ExpList_t, Exp_t, Macro_t, DotChainItem_t> target; 730 ast_sel<true, ExpList_t, Exp_t, Macro_t, DotChainItem_t> target;
725 ast_ptr<false, Assign_t> assign; 731 ast_ptr<false, Assign_t> assign;
726 AST_MEMBER(Export, &def, &target, &assign) 732 AST_MEMBER(Export, &def, &target, &assign)
727AST_END(Export, "export"sv) 733AST_END(Export)
728 734
729AST_NODE(FnArgDef) 735AST_NODE(FnArgDef)
730 ast_sel<true, Variable_t, SelfItem_t> name; 736 ast_sel<true, Variable_t, SelfItem_t> name;
731 ast_ptr<false, ExistentialOp_t> op; 737 ast_ptr<false, ExistentialOp_t> op;
732 ast_ptr<false, Exp_t> defaultValue; 738 ast_ptr<false, Exp_t> defaultValue;
733 AST_MEMBER(FnArgDef, &name, &op, &defaultValue) 739 AST_MEMBER(FnArgDef, &name, &op, &defaultValue)
734AST_END(FnArgDef, "fn_arg_def"sv) 740AST_END(FnArgDef)
735 741
736AST_NODE(FnArgDefList) 742AST_NODE(FnArgDefList)
737 ast_ptr<true, Seperator_t> sep; 743 ast_ptr<true, Seperator_t> sep;
738 ast_list<false, FnArgDef_t> definitions; 744 ast_list<false, FnArgDef_t> definitions;
739 ast_ptr<false, VarArg_t> varArg; 745 ast_ptr<false, VarArg_t> varArg;
740 AST_MEMBER(FnArgDefList, &sep, &definitions, &varArg) 746 AST_MEMBER(FnArgDefList, &sep, &definitions, &varArg)
741AST_END(FnArgDefList, "fn_arg_def_list"sv) 747AST_END(FnArgDefList)
742 748
743AST_NODE(OuterVarShadow) 749AST_NODE(OuterVarShadow)
744 ast_ptr<false, NameList_t> varList; 750 ast_ptr<false, NameList_t> varList;
745 AST_MEMBER(OuterVarShadow, &varList) 751 AST_MEMBER(OuterVarShadow, &varList)
746AST_END(OuterVarShadow, "outer_var_shadow"sv) 752AST_END(OuterVarShadow)
747 753
748AST_NODE(FnArgsDef) 754AST_NODE(FnArgsDef)
749 ast_ptr<false, FnArgDefList_t> defList; 755 ast_ptr<false, FnArgDefList_t> defList;
750 ast_ptr<false, OuterVarShadow_t> shadowOption; 756 ast_ptr<false, OuterVarShadow_t> shadowOption;
751 AST_MEMBER(FnArgsDef, &defList, &shadowOption) 757 AST_MEMBER(FnArgsDef, &defList, &shadowOption)
752AST_END(FnArgsDef, "fn_args_def"sv) 758AST_END(FnArgsDef)
753 759
754AST_LEAF(FnArrow) 760AST_LEAF(FnArrow)
755AST_END(FnArrow, "fn_arrow"sv) 761AST_END(FnArrow)
756 762
757AST_NODE(FunLit) 763AST_NODE(FunLit)
758 ast_ptr<false, FnArgsDef_t> argsDef; 764 ast_ptr<false, FnArgsDef_t> argsDef;
@@ -761,121 +767,121 @@ AST_NODE(FunLit)
761 ast_ptr<false, Body_t> body; 767 ast_ptr<false, Body_t> body;
762 bool noRecursion = false; 768 bool noRecursion = false;
763 AST_MEMBER(FunLit, &argsDef, &defaultReturn, &arrow, &body) 769 AST_MEMBER(FunLit, &argsDef, &defaultReturn, &arrow, &body)
764AST_END(FunLit, "fun_lit"sv) 770AST_END(FunLit)
765 771
766AST_NODE(MacroName) 772AST_NODE(MacroName)
767 ast_ptr<true, UnicodeName_t> name; 773 ast_ptr<true, UnicodeName_t> name;
768 AST_MEMBER(MacroName, &name) 774 AST_MEMBER(MacroName, &name)
769AST_END(MacroName, "macro_name"sv) 775AST_END(MacroName)
770 776
771AST_NODE(MacroLit) 777AST_NODE(MacroLit)
772 ast_ptr<false, FnArgDefList_t> argsDef; 778 ast_ptr<false, FnArgDefList_t> argsDef;
773 ast_ptr<true, Body_t> body; 779 ast_ptr<true, Body_t> body;
774 AST_MEMBER(MacroLit, &argsDef, &body) 780 AST_MEMBER(MacroLit, &argsDef, &body)
775AST_END(MacroLit, "macro_lit"sv) 781AST_END(MacroLit)
776 782
777AST_NODE(MacroFunc) 783AST_NODE(MacroFunc)
778 ast_ptr<true, MacroName_t> name; 784 ast_ptr<true, MacroName_t> name;
779 ast_sel<true, Invoke_t, InvokeArgs_t> invoke; 785 ast_sel<true, Invoke_t, InvokeArgs_t> invoke;
780 AST_MEMBER(MacroFunc, &name, &invoke) 786 AST_MEMBER(MacroFunc, &name, &invoke)
781AST_END(MacroFunc, "macro_func"sv) 787AST_END(MacroFunc)
782 788
783AST_NODE(MacroInPlace) 789AST_NODE(MacroInPlace)
784 ast_ptr<true, Body_t> body; 790 ast_ptr<true, Body_t> body;
785 AST_MEMBER(MacroInPlace, &body) 791 AST_MEMBER(MacroInPlace, &body)
786AST_END(MacroInPlace, "macro_in_place"sv) 792AST_END(MacroInPlace)
787 793
788AST_NODE(Macro) 794AST_NODE(Macro)
789 ast_ptr<true, UnicodeName_t> name; 795 ast_ptr<true, UnicodeName_t> name;
790 ast_sel<true, MacroLit_t, MacroFunc_t> decl; 796 ast_sel<true, MacroLit_t, MacroFunc_t> decl;
791 AST_MEMBER(Macro, &name, &decl) 797 AST_MEMBER(Macro, &name, &decl)
792AST_END(Macro, "macro"sv) 798AST_END(Macro)
793 799
794AST_NODE(NameOrDestructure) 800AST_NODE(NameOrDestructure)
795 ast_sel<true, Variable_t, TableLit_t, Comprehension_t> item; 801 ast_sel<true, Variable_t, TableLit_t, Comprehension_t> item;
796 AST_MEMBER(NameOrDestructure, &item) 802 AST_MEMBER(NameOrDestructure, &item)
797AST_END(NameOrDestructure, "name_or_des"sv) 803AST_END(NameOrDestructure)
798 804
799AST_NODE(AssignableNameList) 805AST_NODE(AssignableNameList)
800 ast_ptr<true, Seperator_t> sep; 806 ast_ptr<true, Seperator_t> sep;
801 ast_list<true, NameOrDestructure_t> items; 807 ast_list<true, NameOrDestructure_t> items;
802 AST_MEMBER(AssignableNameList, &sep, &items) 808 AST_MEMBER(AssignableNameList, &sep, &items)
803AST_END(AssignableNameList, "assignable_name_list"sv) 809AST_END(AssignableNameList)
804 810
805AST_NODE(InvokeArgs) 811AST_NODE(InvokeArgs)
806 ast_ptr<true, Seperator_t> sep; 812 ast_ptr<true, Seperator_t> sep;
807 ast_sel_list<true, Exp_t, TableBlock_t> args; 813 ast_sel_list<true, Exp_t, TableBlock_t> args;
808 AST_MEMBER(InvokeArgs, &sep, &args) 814 AST_MEMBER(InvokeArgs, &sep, &args)
809AST_END(InvokeArgs, "invoke_args"sv) 815AST_END(InvokeArgs)
810 816
811AST_LEAF(ConstValue) 817AST_LEAF(ConstValue)
812AST_END(ConstValue, "const_value"sv) 818AST_END(ConstValue)
813 819
814AST_NODE(UnaryValue) 820AST_NODE(UnaryValue)
815 ast_list<true, UnaryOperator_t> ops; 821 ast_list<true, UnaryOperator_t> ops;
816 ast_ptr<true, Value_t> value; 822 ast_ptr<true, Value_t> value;
817 AST_MEMBER(UnaryValue, &ops, &value) 823 AST_MEMBER(UnaryValue, &ops, &value)
818AST_END(UnaryValue, "unary_value"sv) 824AST_END(UnaryValue)
819 825
820AST_NODE(UnaryExp) 826AST_NODE(UnaryExp)
821 ast_list<false, UnaryOperator_t> ops; 827 ast_list<false, UnaryOperator_t> ops;
822 ast_list<true, Value_t> expos; 828 ast_list<true, Value_t> expos;
823 ast_ptr<false, In_t> inExp; 829 ast_ptr<false, In_t> inExp;
824 AST_MEMBER(UnaryExp, &ops, &expos, &inExp) 830 AST_MEMBER(UnaryExp, &ops, &expos, &inExp)
825AST_END(UnaryExp, "unary_exp"sv) 831AST_END(UnaryExp)
826 832
827AST_NODE(ExpListAssign) 833AST_NODE(ExpListAssign)
828 ast_ptr<true, ExpList_t> expList; 834 ast_ptr<true, ExpList_t> expList;
829 ast_sel<false, Update_t, Assign_t> action; 835 ast_sel<false, Update_t, Assign_t> action;
830 AST_MEMBER(ExpListAssign, &expList, &action) 836 AST_MEMBER(ExpListAssign, &expList, &action)
831AST_END(ExpListAssign, "exp_list_assign"sv) 837AST_END(ExpListAssign)
832 838
833AST_NODE(IfLine) 839AST_NODE(IfLine)
834 ast_ptr<true, IfType_t> type; 840 ast_ptr<true, IfType_t> type;
835 ast_ptr<true, IfCond_t> condition; 841 ast_ptr<true, IfCond_t> condition;
836 AST_MEMBER(IfLine, &type, &condition) 842 AST_MEMBER(IfLine, &type, &condition)
837AST_END(IfLine, "if_line"sv) 843AST_END(IfLine)
838 844
839AST_NODE(WhileLine) 845AST_NODE(WhileLine)
840 ast_ptr<true, WhileType_t> type; 846 ast_ptr<true, WhileType_t> type;
841 ast_ptr<true, Exp_t> condition; 847 ast_ptr<true, Exp_t> condition;
842 AST_MEMBER(WhileLine, &type, &condition) 848 AST_MEMBER(WhileLine, &type, &condition)
843AST_END(WhileLine, "while_line"sv) 849AST_END(WhileLine)
844 850
845AST_LEAF(BreakLoop) 851AST_LEAF(BreakLoop)
846AST_END(BreakLoop, "break_loop"sv) 852AST_END(BreakLoop)
847 853
848AST_NODE(PipeBody) 854AST_NODE(PipeBody)
849 ast_ptr<true, Seperator_t> sep; 855 ast_ptr<true, Seperator_t> sep;
850 ast_list<true, UnaryExp_t> values; 856 ast_list<true, UnaryExp_t> values;
851 AST_MEMBER(PipeBody, &sep, &values) 857 AST_MEMBER(PipeBody, &sep, &values)
852AST_END(PipeBody, "pipe_body"sv) 858AST_END(PipeBody)
853 859
854AST_NODE(StatementAppendix) 860AST_NODE(StatementAppendix)
855 ast_sel<true, IfLine_t, WhileLine_t, CompInner_t> item; 861 ast_sel<true, IfLine_t, WhileLine_t, CompInner_t> item;
856 AST_MEMBER(StatementAppendix, &item) 862 AST_MEMBER(StatementAppendix, &item)
857AST_END(StatementAppendix, "statement_appendix"sv) 863AST_END(StatementAppendix)
858 864
859AST_LEAF(StatementSep) 865AST_LEAF(StatementSep)
860AST_END(StatementSep, "statement_sep"sv) 866AST_END(StatementSep)
861 867
862AST_LEAF(YueLineComment) 868AST_LEAF(YueLineComment)
863AST_END(YueLineComment, "comment"sv) 869AST_END(YueLineComment)
864 870
865AST_LEAF(MultilineCommentInner) 871AST_LEAF(MultilineCommentInner)
866AST_END(MultilineCommentInner, "comment"sv) 872AST_END(MultilineCommentInner)
867 873
868AST_NODE(YueMultilineComment) 874AST_NODE(YueMultilineComment)
869 ast_ptr<true, MultilineCommentInner_t> inner; 875 ast_ptr<true, MultilineCommentInner_t> inner;
870 AST_MEMBER(YueMultilineComment, &inner) 876 AST_MEMBER(YueMultilineComment, &inner)
871AST_END(YueMultilineComment, "comment"sv) 877AST_END(YueMultilineComment)
872 878
873AST_NODE(ChainAssign) 879AST_NODE(ChainAssign)
874 ast_ptr<true, Seperator_t> sep; 880 ast_ptr<true, Seperator_t> sep;
875 ast_list<true, Exp_t> exprs; 881 ast_list<true, Exp_t> exprs;
876 ast_ptr<true, Assign_t> assign; 882 ast_ptr<true, Assign_t> assign;
877 AST_MEMBER(ChainAssign, &sep, &exprs, &assign) 883 AST_MEMBER(ChainAssign, &sep, &exprs, &assign)
878AST_END(ChainAssign, "chain_assign") 884AST_END(ChainAssign)
879 885
880AST_NODE(Statement) 886AST_NODE(Statement)
881 ast_ptr<true, Seperator_t> sep; 887 ast_ptr<true, Seperator_t> sep;
@@ -888,28 +894,28 @@ AST_NODE(Statement)
888 > content; 894 > content;
889 ast_ptr<false, StatementAppendix_t> appendix; 895 ast_ptr<false, StatementAppendix_t> appendix;
890 AST_MEMBER(Statement, &sep, &comments, &content, &appendix) 896 AST_MEMBER(Statement, &sep, &comments, &content, &appendix)
891AST_END(Statement, "statement"sv) 897AST_END(Statement)
892 898
893AST_NODE(Body) 899AST_NODE(Body)
894 ast_sel<true, Block_t, Statement_t> content; 900 ast_sel<true, Block_t, Statement_t> content;
895 AST_MEMBER(Body, &content) 901 AST_MEMBER(Body, &content)
896AST_END(Body, "body"sv) 902AST_END(Body)
897 903
898AST_NODE(Block) 904AST_NODE(Block)
899 ast_ptr<true, Seperator_t> sep; 905 ast_ptr<true, Seperator_t> sep;
900 ast_list<false, Statement_t> statements; 906 ast_list<false, Statement_t> statements;
901 AST_MEMBER(Block, &sep, &statements) 907 AST_MEMBER(Block, &sep, &statements)
902AST_END(Block, "block"sv) 908AST_END(Block)
903 909
904AST_NODE(BlockEnd) 910AST_NODE(BlockEnd)
905 ast_ptr<true, Block_t> block; 911 ast_ptr<true, Block_t> block;
906 AST_MEMBER(BlockEnd, &block) 912 AST_MEMBER(BlockEnd, &block)
907AST_END(BlockEnd, "block_end"sv) 913AST_END(BlockEnd)
908 914
909AST_NODE(File) 915AST_NODE(File)
910 ast_ptr<false, Block_t> block; 916 ast_ptr<false, Block_t> block;
911 AST_MEMBER(File, &block) 917 AST_MEMBER(File, &block)
912AST_END(File, "file"sv) 918AST_END(File)
913 919
914// clang-format on 920// clang-format on
915 921
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp
index 994ab57..a661356 100644
--- a/src/yuescript/yue_compiler.cpp
+++ b/src/yuescript/yue_compiler.cpp
@@ -29,7 +29,7 @@ extern "C" {
29} // extern "C" 29} // extern "C"
30 30
31// name of table stored in lua registry 31// name of table stored in lua registry
32#define YUE_MODULE "__yue_modules__" 32#define YUE_MODULES "__yue_modules__"
33 33
34#if LUA_VERSION_NUM > 501 34#if LUA_VERSION_NUM > 501
35#ifndef LUA_COMPAT_5_1 35#ifndef LUA_COMPAT_5_1
@@ -75,7 +75,7 @@ static std::unordered_set<std::string> Metamethods = {
75 "close"s // Lua 5.4 75 "close"s // Lua 5.4
76}; 76};
77 77
78const std::string_view version = "0.23.9"sv; 78const std::string_view version = "0.24.0"sv;
79const std::string_view extension = "yue"sv; 79const std::string_view extension = "yue"sv;
80 80
81class CompileError : public std::logic_error { 81class CompileError : public std::logic_error {
@@ -136,8 +136,8 @@ public:
136 _sameModule = true; 136 _sameModule = true;
137 int top = lua_gettop(L); 137 int top = lua_gettop(L);
138 DEFER(lua_settop(L, top)); 138 DEFER(lua_settop(L, top));
139 lua_pushliteral(L, YUE_MODULE); // YUE_MODULE 139 lua_pushliteral(L, YUE_MODULES); // YUE_MODULES
140 lua_rawget(L, LUA_REGISTRYINDEX); // reg[YUE_MODULE], tb 140 lua_rawget(L, LUA_REGISTRYINDEX); // reg[YUE_MODULES], tb
141 BREAK_IF(lua_istable(L, -1) == 0); 141 BREAK_IF(lua_istable(L, -1) == 0);
142 int idx = static_cast<int>(lua_objlen(L, -1)); // idx = #tb, tb 142 int idx = static_cast<int>(lua_objlen(L, -1)); // idx = #tb, tb
143 BREAK_IF(idx == 0); 143 BREAK_IF(idx == 0);
@@ -351,8 +351,8 @@ public:
351 if (!_sameModule) { 351 if (!_sameModule) {
352 int top = lua_gettop(L); 352 int top = lua_gettop(L);
353 DEFER(lua_settop(L, top)); 353 DEFER(lua_settop(L, top));
354 lua_pushliteral(L, YUE_MODULE); // YUE_MODULE 354 lua_pushliteral(L, YUE_MODULES); // YUE_MODULES
355 lua_rawget(L, LUA_REGISTRYINDEX); // reg[YUE_MODULE], tb 355 lua_rawget(L, LUA_REGISTRYINDEX); // reg[YUE_MODULES], tb
356 int idx = static_cast<int>(lua_objlen(L, -1)); 356 int idx = static_cast<int>(lua_objlen(L, -1));
357 lua_pushnil(L); // tb nil 357 lua_pushnil(L); // tb nil
358 lua_rawseti(L, -2, idx); // tb[idx] = nil, tb 358 lua_rawseti(L, -2, idx); // tb[idx] = nil, tb
@@ -370,7 +370,7 @@ private:
370 std::function<void(void*)> _luaOpen; 370 std::function<void(void*)> _luaOpen;
371#endif // YUE_NO_MACRO 371#endif // YUE_NO_MACRO
372 YueConfig _config; 372 YueConfig _config;
373 YueParser _parser; 373 YueParser& _parser = YueParser::shared();
374 ParseInfo _info; 374 ParseInfo _info;
375 int _indentOffset = 0; 375 int _indentOffset = 0;
376 struct VarArgState { 376 struct VarArgState {
@@ -4960,8 +4960,8 @@ private:
4960 4960
4961 void pushCurrentModule() { 4961 void pushCurrentModule() {
4962 if (_useModule) { 4962 if (_useModule) {
4963 lua_pushliteral(L, YUE_MODULE); // YUE_MODULE 4963 lua_pushliteral(L, YUE_MODULES); // YUE_MODULES
4964 lua_rawget(L, LUA_REGISTRYINDEX); // reg[YUE_MODULE], tb 4964 lua_rawget(L, LUA_REGISTRYINDEX); // reg[YUE_MODULES], tb
4965 int idx = static_cast<int>(lua_objlen(L, -1)); // idx = #tb, tb 4965 int idx = static_cast<int>(lua_objlen(L, -1)); // idx = #tb, tb
4966 lua_rawgeti(L, -1, idx); // tb[idx], tb cur 4966 lua_rawgeti(L, -1, idx); // tb[idx], tb cur
4967 lua_remove(L, -2); // cur 4967 lua_remove(L, -2); // cur
@@ -4987,14 +4987,14 @@ private:
4987 } 4987 }
4988 _stateOwner = true; 4988 _stateOwner = true;
4989 } 4989 }
4990 lua_pushliteral(L, YUE_MODULE); // YUE_MODULE 4990 lua_pushliteral(L, YUE_MODULES); // YUE_MODULES
4991 lua_rawget(L, LUA_REGISTRYINDEX); // reg[YUE_MODULE], tb 4991 lua_rawget(L, LUA_REGISTRYINDEX); // reg[YUE_MODULES], tb
4992 if (lua_isnil(L, -1) != 0) { // tb == nil 4992 if (lua_isnil(L, -1) != 0) { // tb == nil
4993 lua_pop(L, 1); 4993 lua_pop(L, 1);
4994 lua_newtable(L); // tb 4994 lua_newtable(L); // tb
4995 lua_pushliteral(L, YUE_MODULE); // tb YUE_MODULE 4995 lua_pushliteral(L, YUE_MODULES); // tb YUE_MODULES
4996 lua_pushvalue(L, -2); // tb YUE_MODULE tb 4996 lua_pushvalue(L, -2); // tb YUE_MODULE tb
4997 lua_rawset(L, LUA_REGISTRYINDEX); // reg[YUE_MODULE] = tb, tb 4997 lua_rawset(L, LUA_REGISTRYINDEX); // reg[YUE_MODULES] = tb, tb
4998 } // tb 4998 } // tb
4999 int idx = static_cast<int>(lua_objlen(L, -1)); // idx = #tb, tb 4999 int idx = static_cast<int>(lua_objlen(L, -1)); // idx = #tb, tb
5000 lua_newtable(L); // tb cur 5000 lua_newtable(L); // tb cur
@@ -5016,7 +5016,7 @@ private:
5016 bool isModuleLoaded(std::string_view name) { 5016 bool isModuleLoaded(std::string_view name) {
5017 int top = lua_gettop(L); 5017 int top = lua_gettop(L);
5018 DEFER(lua_settop(L, top)); 5018 DEFER(lua_settop(L, top));
5019 lua_pushliteral(L, YUE_MODULE); // YUE_MODULE 5019 lua_pushliteral(L, YUE_MODULES); // YUE_MODULES
5020 lua_rawget(L, LUA_REGISTRYINDEX); // modules 5020 lua_rawget(L, LUA_REGISTRYINDEX); // modules
5021 lua_pushlstring(L, &name.front(), name.size()); 5021 lua_pushlstring(L, &name.front(), name.size());
5022 lua_rawget(L, -2); // modules module 5022 lua_rawget(L, -2); // modules module
@@ -5027,7 +5027,7 @@ private:
5027 } 5027 }
5028 5028
5029 void pushModuleTable(std::string_view name) { 5029 void pushModuleTable(std::string_view name) {
5030 lua_pushliteral(L, YUE_MODULE); // YUE_MODULE 5030 lua_pushliteral(L, YUE_MODULES); // YUE_MODULES
5031 lua_rawget(L, LUA_REGISTRYINDEX); // modules 5031 lua_rawget(L, LUA_REGISTRYINDEX); // modules
5032 lua_pushlstring(L, &name.front(), name.size()); 5032 lua_pushlstring(L, &name.front(), name.size());
5033 lua_rawget(L, -2); // modules module 5033 lua_rawget(L, -2); // modules module
@@ -9869,9 +9869,17 @@ private:
9869 if (importAllMacro) { 9869 if (importAllMacro) {
9870 lua_pushnil(L); // cur mod startKey 9870 lua_pushnil(L); // cur mod startKey
9871 while (lua_next(L, -2) != 0) { // cur mod key value 9871 while (lua_next(L, -2) != 0) { // cur mod key value
9872 lua_pushvalue(L, -2); // cur mod key value key 9872 const char* key = lua_tostring(L, -2);
9873 lua_insert(L, -2); // cur mod key key value 9873 auto it = std::find_if(macroPairs.begin(), macroPairs.end(), [&](const auto& item) {
9874 lua_rawset(L, -5); // cur[key] = value, cur mod key 9874 return key == item.first;
9875 });
9876 if (it == macroPairs.end()) {
9877 lua_pushvalue(L, -2); // cur mod key value key
9878 lua_insert(L, -2); // cur mod key key value
9879 lua_rawset(L, -5); // cur[key] = value, cur mod key
9880 } else {
9881 lua_pop(L, 1); // cur mod key
9882 }
9875 } 9883 }
9876 } 9884 }
9877 for (const auto& pair : macroPairs) { 9885 for (const auto& pair : macroPairs) {
@@ -10696,9 +10704,9 @@ CompileInfo YueCompiler::compile(std::string_view codes, const YueConfig& config
10696void YueCompiler::clear(void* luaState) { 10704void YueCompiler::clear(void* luaState) {
10697#ifndef YUE_NO_MACRO 10705#ifndef YUE_NO_MACRO
10698 auto L = static_cast<lua_State*>(luaState); 10706 auto L = static_cast<lua_State*>(luaState);
10699 lua_pushliteral(L, YUE_MODULE); // YUE_MODULE 10707 lua_pushliteral(L, YUE_MODULES); // YUE_MODULES
10700 lua_pushnil(L); 10708 lua_pushnil(L);
10701 lua_rawset(L, LUA_REGISTRYINDEX); // reg[YUE_MODULE] = nil 10709 lua_rawset(L, LUA_REGISTRYINDEX); // reg[YUE_MODULES] = nil
10702#else 10710#else
10703 (void)(luaState); 10711 (void)(luaState);
10704#endif // YUE_NO_MACRO 10712#endif // YUE_NO_MACRO
diff --git a/src/yuescript/yue_parser.cpp b/src/yuescript/yue_parser.cpp
index 986f67a..83aba40 100644
--- a/src/yuescript/yue_parser.cpp
+++ b/src/yuescript/yue_parser.cpp
@@ -309,7 +309,7 @@ YueParser::YueParser() {
309 ); 309 );
310 310
311 MacroNamePair = MacroName >> ':' >> space >> MacroName; 311 MacroNamePair = MacroName >> ':' >> space >> MacroName;
312 ImportAllMacro = '$'; 312 ImportAllMacro = '$' >> not_(UnicodeName);
313 import_tab_item = 313 import_tab_item =
314 VariablePair | 314 VariablePair |
315 NormalPair | 315 NormalPair |
@@ -324,6 +324,7 @@ YueParser::YueParser() {
324 push_indent_match >> (space >> import_tab_list >> pop_indent | pop_indent) 324 push_indent_match >> (space >> import_tab_list >> pop_indent | pop_indent)
325 ) | space; 325 ) | space;
326 import_tab_lines = space_break >> import_tab_line >> *(-(space >> ',') >> space_break >> import_tab_line) >> -(space >> ','); 326 import_tab_lines = space_break >> import_tab_line >> *(-(space >> ',') >> space_break >> import_tab_line) >> -(space >> ',');
327 import_tab_key_value = key_value | ':' >> MacroName | MacroNamePair | ImportAllMacro;
327 ImportTabLit = ( 328 ImportTabLit = (
328 '{' >> Seperator >> 329 '{' >> Seperator >>
329 -(space >> import_tab_list) >> 330 -(space >> import_tab_list) >>
@@ -332,7 +333,7 @@ YueParser::YueParser() {
332 white >> 333 white >>
333 '}' 334 '}'
334 ) | ( 335 ) | (
335 Seperator >> key_value >> *(space >> ',' >> space >> key_value) 336 Seperator >> import_tab_key_value >> *(space >> ',' >> space >> import_tab_key_value)
336 ); 337 );
337 338
338 ImportAs = ImportLiteral >> -(space >> key("as") >> space >> (ImportTabLit | Variable | ImportAllMacro)); 339 ImportAs = ImportLiteral >> -(space >> key("as") >> space >> (ImportTabLit | Variable | ImportAllMacro));
@@ -1083,6 +1084,23 @@ ParseInfo YueParser::parse(std::string_view codes, rule& r) {
1083 return res; 1084 return res;
1084} 1085}
1085 1086
1087ParseInfo YueParser::parse(std::string_view astName, std::string_view codes) {
1088 auto it = _rules.find(astName);
1089 if (it != _rules.end()) {
1090 return parse(codes, *it->second);
1091 }
1092 return {};
1093}
1094
1095bool YueParser::match(std::string_view astName, std::string_view codes) {
1096 auto it = _rules.find(astName);
1097 if (it != _rules.end()) {
1098 auto rEnd = rule(*it->second >> eof());
1099 return parse(codes, rEnd).node;
1100 }
1101 return false;
1102}
1103
1086std::string YueParser::toString(ast_node* node) { 1104std::string YueParser::toString(ast_node* node) {
1087 return _converter.to_bytes(std::wstring(node->m_begin.m_it, node->m_end.m_it)); 1105 return _converter.to_bytes(std::wstring(node->m_begin.m_it, node->m_end.m_it));
1088} 1106}
@@ -1091,6 +1109,11 @@ std::string YueParser::toString(input::iterator begin, input::iterator end) {
1091 return _converter.to_bytes(std::wstring(begin, end)); 1109 return _converter.to_bytes(std::wstring(begin, end));
1092} 1110}
1093 1111
1112YueParser& YueParser::shared() {
1113 thread_local static YueParser parser;
1114 return parser;
1115}
1116
1094namespace Utils { 1117namespace Utils {
1095void replace(std::string& str, std::string_view from, std::string_view to) { 1118void replace(std::string& str, std::string_view from, std::string_view to) {
1096 size_t start_pos = 0; 1119 size_t start_pos = 0;
diff --git a/src/yuescript/yue_parser.h b/src/yuescript/yue_parser.h
index 6623653..3c50602 100644
--- a/src/yuescript/yue_parser.h
+++ b/src/yuescript/yue_parser.h
@@ -16,6 +16,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
16#include <stack> 16#include <stack>
17#include <string> 17#include <string>
18#include <string_view> 18#include <string_view>
19#include <unordered_map>
19#include <unordered_set> 20#include <unordered_set>
20 21
21#include "yuescript/ast.hpp" 22#include "yuescript/ast.hpp"
@@ -55,7 +56,7 @@ struct identity {
55 56
56#define AST_RULE(type) \ 57#define AST_RULE(type) \
57 rule type; \ 58 rule type; \
58 ast<type##_t> type##_impl = type; \ 59 ast<type##_t> type##_impl{collect(ast_name<type##_t>(), type)}; \
59 inline rule& getRule(identity<type##_t>) { return type; } 60 inline rule& getRule(identity<type##_t>) { return type; }
60#else // NDEBUG 61#else // NDEBUG
61#define NONE_AST_RULE(type) \ 62#define NONE_AST_RULE(type) \
@@ -63,7 +64,7 @@ struct identity {
63 64
64#define AST_RULE(type) \ 65#define AST_RULE(type) \
65 rule type{#type, rule::initTag{}}; \ 66 rule type{#type, rule::initTag{}}; \
66 ast<type##_t> type##_impl = type; \ 67 ast<type##_t> type##_impl{collect(ast_name<type##_t>(), type)}; \
67 inline rule& getRule(identity<type##_t>) { return type; } 68 inline rule& getRule(identity<type##_t>) { return type; }
68#endif // NDEBUG 69#endif // NDEBUG
69 70
@@ -72,19 +73,21 @@ extern std::unordered_set<std::string> Keywords;
72 73
73class YueParser { 74class YueParser {
74public: 75public:
75 YueParser();
76
77 template <class AST> 76 template <class AST>
78 ParseInfo parse(std::string_view codes) { 77 ParseInfo parse(std::string_view codes) {
79 return parse(codes, getRule<AST>()); 78 return parse(codes, getRule<AST>());
80 } 79 }
81 80
81 ParseInfo parse(std::string_view astName, std::string_view codes);
82
82 template <class AST> 83 template <class AST>
83 bool match(std::string_view codes) { 84 bool match(std::string_view codes) {
84 auto rEnd = rule(getRule<AST>() >> eof()); 85 auto rEnd = rule(getRule<AST>() >> eof());
85 return parse(codes, rEnd).node; 86 return parse(codes, rEnd).node;
86 } 87 }
87 88
89 bool match(std::string_view astName, std::string_view codes);
90
88 template <class AST> 91 template <class AST>
89 bool startWith(std::string_view codes) { 92 bool startWith(std::string_view codes) {
90 return startWith(codes, getRule<AST>()); 93 return startWith(codes, getRule<AST>());
@@ -93,7 +96,10 @@ public:
93 std::string toString(ast_node* node); 96 std::string toString(ast_node* node);
94 std::string toString(input::iterator begin, input::iterator end); 97 std::string toString(input::iterator begin, input::iterator end);
95 98
99 static YueParser& shared();
100
96protected: 101protected:
102 YueParser();
97 ParseInfo parse(std::string_view codes, rule& r); 103 ParseInfo parse(std::string_view codes, rule& r);
98 bool startWith(std::string_view codes, rule& r); 104 bool startWith(std::string_view codes, rule& r);
99 105
@@ -125,6 +131,7 @@ protected:
125 131
126private: 132private:
127 Converter _converter; 133 Converter _converter;
134 std::unordered_map<std::string_view, rule*> _rules;
128 135
129 template <class T> 136 template <class T>
130 inline rule& getRule(identity<T>) { 137 inline rule& getRule(identity<T>) {
@@ -132,6 +139,11 @@ private:
132 return cut; 139 return cut;
133 } 140 }
134 141
142 inline rule& collect(std::string_view name, rule& rule) {
143 _rules[name] = rule.this_ptr();
144 return rule;
145 }
146
135 NONE_AST_RULE(empty_block_error); 147 NONE_AST_RULE(empty_block_error);
136 NONE_AST_RULE(leading_spaces_error); 148 NONE_AST_RULE(leading_spaces_error);
137 NONE_AST_RULE(indentation_error); 149 NONE_AST_RULE(indentation_error);
@@ -188,6 +200,7 @@ private:
188 NONE_AST_RULE(import_tab_list); 200 NONE_AST_RULE(import_tab_list);
189 NONE_AST_RULE(import_tab_line); 201 NONE_AST_RULE(import_tab_line);
190 NONE_AST_RULE(import_tab_lines); 202 NONE_AST_RULE(import_tab_lines);
203 NONE_AST_RULE(import_tab_key_value);
191 NONE_AST_RULE(with_exp); 204 NONE_AST_RULE(with_exp);
192 NONE_AST_RULE(disable_do); 205 NONE_AST_RULE(disable_do);
193 NONE_AST_RULE(enable_do); 206 NONE_AST_RULE(enable_do);
diff --git a/src/yuescript/yuescript.cpp b/src/yuescript/yuescript.cpp
index 2de5571..84a9554 100644
--- a/src/yuescript/yuescript.cpp
+++ b/src/yuescript/yuescript.cpp
@@ -180,7 +180,7 @@ static int yueformat(lua_State* L) {
180 tabSize = static_cast<int>(luaL_checkinteger(L, 2)); 180 tabSize = static_cast<int>(luaL_checkinteger(L, 2));
181 } 181 }
182 std::string_view codes(input, len); 182 std::string_view codes(input, len);
183 auto info = yue::YueParser{}.parse<yue::File_t>(codes); 183 auto info = yue::YueParser::shared().parse<yue::File_t>(codes);
184 if (info.error) { 184 if (info.error) {
185 const auto& error = info.error.value(); 185 const auto& error = info.error.value();
186 if (!info.codes) { 186 if (!info.codes) {
@@ -271,12 +271,19 @@ static int yuetoast(lua_State* L) {
271 size_t size = 0; 271 size_t size = 0;
272 const char* input = luaL_checklstring(L, 1, &size); 272 const char* input = luaL_checklstring(L, 1, &size);
273 int flattenLevel = 0; 273 int flattenLevel = 0;
274 if (lua_isnoneornil(L, 2) == 0) { 274 if (!lua_isnoneornil(L, 2)) {
275 flattenLevel = static_cast<int>(luaL_checkinteger(L, 2)); 275 flattenLevel = static_cast<int>(luaL_checkinteger(L, 2));
276 flattenLevel = std::max(std::min(2, flattenLevel), 0); 276 flattenLevel = std::max(std::min(2, flattenLevel), 0);
277 } 277 }
278 yue::YueParser parser; 278 std::string_view ruleName;
279 auto info = parser.parse<yue::File_t>({input, size}); 279 if (!lua_isnoneornil(L, 3)) {
280 size_t nameSize = 0;
281 if (auto name = luaL_checklstring(L, 3, &nameSize)) {
282 ruleName = {name, nameSize};
283 }
284 }
285 auto& yueParser = yue::YueParser::shared();
286 auto info = ruleName.empty() ? yueParser.parse<yue::File_t>({input, size}) : yueParser.parse(ruleName, {input, size});
280 if (!info.error) { 287 if (!info.error) {
281 lua_createtable(L, 0, 0); 288 lua_createtable(L, 0, 0);
282 int tableIndex = lua_gettop(L); 289 int tableIndex = lua_gettop(L);
@@ -413,9 +420,20 @@ static int yuetoast(lua_State* L) {
413 } 420 }
414} 421}
415 422
423static int yueisast(lua_State* L) {
424 size_t nameLen = 0;
425 auto name = luaL_tolstring(L, 1, &nameLen);
426 size_t codeLen = 0;
427 auto code = luaL_tolstring(L, 2, &codeLen);
428 bool result = yue::YueParser::shared().match({name, nameLen}, {code, codeLen});
429 lua_pushboolean(L, result ? 1 : 0);
430 return 1;
431}
432
416static const luaL_Reg yuelib[] = { 433static const luaL_Reg yuelib[] = {
417 {"to_lua", yuetolua}, 434 {"to_lua", yuetolua},
418 {"to_ast", yuetoast}, 435 {"to_ast", yuetoast},
436 {"is_ast", yueisast},
419 {"check", yuecheck}, 437 {"check", yuecheck},
420 {"format", yueformat}, 438 {"format", yueformat},
421 {"version", nullptr}, 439 {"version", nullptr},