aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2022-05-06 14:29:10 +0800
committerLi Jin <dragon-fly@qq.com>2022-05-06 14:29:10 +0800
commitd20be11da9fef9309faf7f83078ed963a3b1e627 (patch)
treed597685d7634a664e03479d465c6b02e707a8b44
parent70d8bc6d5396799c71ee97a7f98791779c8f1a37 (diff)
downloadyuescript-d20be11da9fef9309faf7f83078ed963a3b1e627.tar.gz
yuescript-d20be11da9fef9309faf7f83078ed963a3b1e627.tar.bz2
yuescript-d20be11da9fef9309faf7f83078ed963a3b1e627.zip
add to_ast function.
-rw-r--r--src/yuescript/ast.hpp3
-rwxr-xr-xsrc/yuescript/yue_ast.h276
-rwxr-xr-xsrc/yuescript/yue_compiler.cpp2
-rw-r--r--src/yuescript/yuescript.cpp81
4 files changed, 224 insertions, 138 deletions
diff --git a/src/yuescript/ast.hpp b/src/yuescript/ast.hpp
index 6f89b52..4860fc9 100644
--- a/src/yuescript/ast.hpp
+++ b/src/yuescript/ast.hpp
@@ -16,6 +16,7 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16#include <list> 16#include <list>
17#include <stdexcept> 17#include <stdexcept>
18#include <type_traits> 18#include <type_traits>
19#include <string_view>
19 20
20#include "yuescript/parser.hpp" 21#include "yuescript/parser.hpp"
21 22
@@ -96,6 +97,8 @@ public:
96 97
97 virtual int getId() const = 0; 98 virtual int getId() const = 0;
98 99
100 virtual const std::string_view getName() const = 0;
101
99 template<class T> 102 template<class T>
100 inline ast_ptr<false, T> new_ptr() const { 103 inline ast_ptr<false, T> new_ptr() const {
101 auto item = new T; 104 auto item = new T;
diff --git a/src/yuescript/yue_ast.h b/src/yuescript/yue_ast.h
index 06896b8..d255236 100755
--- a/src/yuescript/yue_ast.h
+++ b/src/yuescript/yue_ast.h
@@ -11,6 +11,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
11#include "yuescript/ast.hpp" 11#include "yuescript/ast.hpp"
12 12
13namespace parserlib { 13namespace parserlib {
14using namespace std::string_view_literals;
14 15
15#define AST_LEAF(type) \ 16#define AST_LEAF(type) \
16COUNTER_INC; \ 17COUNTER_INC; \
@@ -31,71 +32,72 @@ public: \
31 add_members({__VA_ARGS__}); \ 32 add_members({__VA_ARGS__}); \
32 } 33 }
33 34
34#define AST_END(type) \ 35#define AST_END(type, name) \
36 virtual const std::string_view getName() const override { return name; } \
35}; \ 37}; \
36template<> constexpr int id<type##_t>() { return COUNTER_READ; } 38template<> constexpr int id<type##_t>() { return COUNTER_READ; }
37 39
38AST_LEAF(Num) 40AST_LEAF(Num)
39AST_END(Num) 41AST_END(Num, "num"sv)
40 42
41AST_LEAF(Name) 43AST_LEAF(Name)
42AST_END(Name) 44AST_END(Name, "name"sv)
43 45
44AST_NODE(Variable) 46AST_NODE(Variable)
45 ast_ptr<true, Name_t> name; 47 ast_ptr<true, Name_t> name;
46 AST_MEMBER(Variable, &name) 48 AST_MEMBER(Variable, &name)
47AST_END(Variable) 49AST_END(Variable, "variable"sv)
48 50
49AST_NODE(LabelName) 51AST_NODE(LabelName)
50 ast_ptr<true, Name_t> name; 52 ast_ptr<true, Name_t> name;
51 AST_MEMBER(LabelName, &name) 53 AST_MEMBER(LabelName, &name)
52AST_END(LabelName) 54AST_END(LabelName, "label_name"sv)
53 55
54AST_NODE(LuaKeyword) 56AST_NODE(LuaKeyword)
55 ast_ptr<true, Name_t> name; 57 ast_ptr<true, Name_t> name;
56 AST_MEMBER(LuaKeyword, &name) 58 AST_MEMBER(LuaKeyword, &name)
57AST_END(LuaKeyword) 59AST_END(LuaKeyword, "lua_keyword"sv)
58 60
59AST_LEAF(self) 61AST_LEAF(self)
60AST_END(self) 62AST_END(self, "self"sv)
61 63
62AST_NODE(self_name) 64AST_NODE(self_name)
63 ast_ptr<true, Name_t> name; 65 ast_ptr<true, Name_t> name;
64 AST_MEMBER(self_name, &name) 66 AST_MEMBER(self_name, &name)
65AST_END(self_name) 67AST_END(self_name, "self_name"sv)
66 68
67AST_LEAF(self_class) 69AST_LEAF(self_class)
68AST_END(self_class) 70AST_END(self_class, "self_name"sv)
69 71
70AST_NODE(self_class_name) 72AST_NODE(self_class_name)
71 ast_ptr<true, Name_t> name; 73 ast_ptr<true, Name_t> name;
72 AST_MEMBER(self_class_name, &name) 74 AST_MEMBER(self_class_name, &name)
73AST_END(self_class_name) 75AST_END(self_class_name, "self_class_name"sv)
74 76
75AST_NODE(SelfName) 77AST_NODE(SelfName)
76 ast_sel<true, self_class_name_t, self_class_t, self_name_t, self_t> name; 78 ast_sel<true, self_class_name_t, self_class_t, self_name_t, self_t> name;
77 AST_MEMBER(SelfName, &name) 79 AST_MEMBER(SelfName, &name)
78AST_END(SelfName) 80AST_END(SelfName, "self_item"sv)
79 81
80AST_NODE(KeyName) 82AST_NODE(KeyName)
81 ast_sel<true, SelfName_t, Name_t> name; 83 ast_sel<true, SelfName_t, Name_t> name;
82 AST_MEMBER(KeyName, &name) 84 AST_MEMBER(KeyName, &name)
83AST_END(KeyName) 85AST_END(KeyName, "key_name"sv)
84 86
85AST_LEAF(VarArg) 87AST_LEAF(VarArg)
86AST_END(VarArg) 88AST_END(VarArg, "var_arg"sv)
87 89
88AST_LEAF(local_flag) 90AST_LEAF(local_flag)
89AST_END(local_flag) 91AST_END(local_flag, "local_flag"sv)
90 92
91AST_LEAF(Seperator) 93AST_LEAF(Seperator)
92AST_END(Seperator) 94AST_END(Seperator, "seperator"sv)
93 95
94AST_NODE(NameList) 96AST_NODE(NameList)
95 ast_ptr<true, Seperator_t> sep; 97 ast_ptr<true, Seperator_t> sep;
96 ast_list<true, Variable_t> names; 98 ast_list<true, Variable_t> names;
97 AST_MEMBER(NameList, &sep, &names) 99 AST_MEMBER(NameList, &sep, &names)
98AST_END(NameList) 100AST_END(NameList, "name_list"sv)
99 101
100class ExpListLow_t; 102class ExpListLow_t;
101class TableBlock_t; 103class TableBlock_t;
@@ -105,7 +107,7 @@ AST_NODE(local_values)
105 ast_ptr<true, NameList_t> nameList; 107 ast_ptr<true, NameList_t> nameList;
106 ast_sel<false, TableBlock_t, ExpListLow_t> valueList; 108 ast_sel<false, TableBlock_t, ExpListLow_t> valueList;
107 AST_MEMBER(local_values, &nameList, &valueList) 109 AST_MEMBER(local_values, &nameList, &valueList)
108AST_END(local_values) 110AST_END(local_values, "local_values"sv)
109 111
110AST_NODE(Local) 112AST_NODE(Local)
111 ast_sel<true, local_flag_t, local_values_t> item; 113 ast_sel<true, local_flag_t, local_values_t> item;
@@ -114,43 +116,43 @@ AST_NODE(Local)
114 bool collected = false; 116 bool collected = false;
115 bool defined = false; 117 bool defined = false;
116 AST_MEMBER(Local, &item) 118 AST_MEMBER(Local, &item)
117AST_END(Local) 119AST_END(Local, "local"sv)
118 120
119class Assign_t; 121class Assign_t;
120 122
121AST_LEAF(Attrib) 123AST_LEAF(Attrib)
122AST_END(Attrib) 124AST_END(Attrib, "attrib"sv)
123 125
124AST_NODE(LocalAttrib) 126AST_NODE(LocalAttrib)
125 ast_ptr<true, Attrib_t> attrib; 127 ast_ptr<true, Attrib_t> attrib;
126 ast_ptr<true, NameList_t> nameList; 128 ast_ptr<true, NameList_t> nameList;
127 ast_ptr<true, Assign_t> assign; 129 ast_ptr<true, Assign_t> assign;
128 AST_MEMBER(LocalAttrib, &attrib, &nameList, &assign) 130 AST_MEMBER(LocalAttrib, &attrib, &nameList, &assign)
129AST_END(LocalAttrib) 131AST_END(LocalAttrib, "local_attrib"sv)
130 132
131AST_NODE(colon_import_name) 133AST_NODE(colon_import_name)
132 ast_ptr<true, Variable_t> name; 134 ast_ptr<true, Variable_t> name;
133 AST_MEMBER(colon_import_name, &name) 135 AST_MEMBER(colon_import_name, &name)
134AST_END(colon_import_name) 136AST_END(colon_import_name, "colon_import_name"sv)
135 137
136class Exp_t; 138class Exp_t;
137class TableLit_t; 139class TableLit_t;
138 140
139AST_LEAF(import_literal_inner) 141AST_LEAF(import_literal_inner)
140AST_END(import_literal_inner) 142AST_END(import_literal_inner, "import_literal_inner"sv)
141 143
142AST_NODE(ImportLiteral) 144AST_NODE(ImportLiteral)
143 ast_ptr<true, Seperator_t> sep; 145 ast_ptr<true, Seperator_t> sep;
144 ast_sel_list<true, import_literal_inner_t> inners; 146 ast_sel_list<true, import_literal_inner_t> inners;
145 AST_MEMBER(ImportLiteral, &sep, &inners) 147 AST_MEMBER(ImportLiteral, &sep, &inners)
146AST_END(ImportLiteral) 148AST_END(ImportLiteral, "import_literal"sv)
147 149
148AST_NODE(ImportFrom) 150AST_NODE(ImportFrom)
149 ast_ptr<true, Seperator_t> sep; 151 ast_ptr<true, Seperator_t> sep;
150 ast_sel_list<true, colon_import_name_t, Variable_t> names; 152 ast_sel_list<true, colon_import_name_t, Variable_t> names;
151 ast_ptr<true, Exp_t> exp; 153 ast_ptr<true, Exp_t> exp;
152 AST_MEMBER(ImportFrom, &sep, &names, &exp) 154 AST_MEMBER(ImportFrom, &sep, &names, &exp)
153AST_END(ImportFrom) 155AST_END(ImportFrom, "import_from"sv)
154 156
155class MacroName_t; 157class MacroName_t;
156 158
@@ -158,10 +160,10 @@ AST_NODE(macro_name_pair)
158 ast_ptr<true, MacroName_t> key; 160 ast_ptr<true, MacroName_t> key;
159 ast_ptr<true, MacroName_t> value; 161 ast_ptr<true, MacroName_t> value;
160 AST_MEMBER(macro_name_pair, &key, &value) 162 AST_MEMBER(macro_name_pair, &key, &value)
161AST_END(macro_name_pair) 163AST_END(macro_name_pair, "macro_name_pair"sv)
162 164
163AST_LEAF(import_all_macro) 165AST_LEAF(import_all_macro)
164AST_END(import_all_macro) 166AST_END(import_all_macro, "import_all_macro"sv)
165 167
166class variable_pair_t; 168class variable_pair_t;
167class normal_pair_t; 169class normal_pair_t;
@@ -172,33 +174,33 @@ AST_NODE(ImportTabLit)
172 ast_ptr<true, Seperator_t> sep; 174 ast_ptr<true, Seperator_t> sep;
173 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; 175 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;
174 AST_MEMBER(ImportTabLit, &sep, &items) 176 AST_MEMBER(ImportTabLit, &sep, &items)
175AST_END(ImportTabLit) 177AST_END(ImportTabLit, "import_tab_lit"sv)
176 178
177AST_NODE(ImportAs) 179AST_NODE(ImportAs)
178 ast_ptr<true, ImportLiteral_t> literal; 180 ast_ptr<true, ImportLiteral_t> literal;
179 ast_sel<false, Variable_t, ImportTabLit_t, import_all_macro_t> target; 181 ast_sel<false, Variable_t, ImportTabLit_t, import_all_macro_t> target;
180 AST_MEMBER(ImportAs, &literal, &target) 182 AST_MEMBER(ImportAs, &literal, &target)
181AST_END(ImportAs) 183AST_END(ImportAs, "import_as"sv)
182 184
183AST_NODE(Import) 185AST_NODE(Import)
184 ast_sel<true, ImportAs_t, ImportFrom_t> content; 186 ast_sel<true, ImportAs_t, ImportFrom_t> content;
185 AST_MEMBER(Import, &content) 187 AST_MEMBER(Import, &content)
186AST_END(Import) 188AST_END(Import, "import"sv)
187 189
188AST_NODE(Label) 190AST_NODE(Label)
189 ast_ptr<true, LabelName_t> label; 191 ast_ptr<true, LabelName_t> label;
190 AST_MEMBER(Label, &label) 192 AST_MEMBER(Label, &label)
191AST_END(Label) 193AST_END(Label, "label"sv)
192 194
193AST_NODE(Goto) 195AST_NODE(Goto)
194 ast_ptr<true, LabelName_t> label; 196 ast_ptr<true, LabelName_t> label;
195 AST_MEMBER(Goto, &label) 197 AST_MEMBER(Goto, &label)
196AST_END(Goto) 198AST_END(Goto, "goto"sv)
197 199
198class FnArgsDef_t; 200class FnArgsDef_t;
199 201
200AST_LEAF(fn_arrow_back) 202AST_LEAF(fn_arrow_back)
201AST_END(fn_arrow_back) 203AST_END(fn_arrow_back, "fn_arrow_back"sv)
202 204
203class ChainValue_t; 205class ChainValue_t;
204 206
@@ -207,19 +209,19 @@ AST_NODE(Backcall)
207 ast_ptr<true, fn_arrow_back_t> arrow; 209 ast_ptr<true, fn_arrow_back_t> arrow;
208 ast_ptr<true, ChainValue_t> value; 210 ast_ptr<true, ChainValue_t> value;
209 AST_MEMBER(Backcall, &argsDef, &arrow, &value) 211 AST_MEMBER(Backcall, &argsDef, &arrow, &value)
210AST_END(Backcall) 212AST_END(Backcall, "backcall"sv)
211 213
212AST_NODE(ExpListLow) 214AST_NODE(ExpListLow)
213 ast_ptr<true, Seperator_t> sep; 215 ast_ptr<true, Seperator_t> sep;
214 ast_list<true, Exp_t> exprs; 216 ast_list<true, Exp_t> exprs;
215 AST_MEMBER(ExpListLow, &sep, &exprs) 217 AST_MEMBER(ExpListLow, &sep, &exprs)
216AST_END(ExpListLow) 218AST_END(ExpListLow, "exp_list_low"sv)
217 219
218AST_NODE(ExpList) 220AST_NODE(ExpList)
219 ast_ptr<true, Seperator_t> sep; 221 ast_ptr<true, Seperator_t> sep;
220 ast_list<true, Exp_t> exprs; 222 ast_list<true, Exp_t> exprs;
221 AST_MEMBER(ExpList, &sep, &exprs) 223 AST_MEMBER(ExpList, &sep, &exprs)
222AST_END(ExpList) 224AST_END(ExpList, "exp_list"sv)
223 225
224class TableBlock_t; 226class TableBlock_t;
225 227
@@ -227,7 +229,7 @@ AST_NODE(Return)
227 bool allowBlockMacroReturn = false; 229 bool allowBlockMacroReturn = false;
228 ast_sel<false, TableBlock_t, ExpListLow_t> valueList; 230 ast_sel<false, TableBlock_t, ExpListLow_t> valueList;
229 AST_MEMBER(Return, &valueList) 231 AST_MEMBER(Return, &valueList)
230AST_END(Return) 232AST_END(Return, "return"sv)
231 233
232class existential_op_t; 234class existential_op_t;
233class Assign_t; 235class Assign_t;
@@ -240,13 +242,13 @@ AST_NODE(With)
240 ast_ptr<false, Assign_t> assigns; 242 ast_ptr<false, Assign_t> assigns;
241 ast_sel<true, Block_t, Statement_t> body; 243 ast_sel<true, Block_t, Statement_t> body;
242 AST_MEMBER(With, &eop, &valueList, &assigns, &body) 244 AST_MEMBER(With, &eop, &valueList, &assigns, &body)
243AST_END(With) 245AST_END(With, "with"sv)
244 246
245AST_NODE(SwitchCase) 247AST_NODE(SwitchCase)
246 ast_ptr<true, ExpList_t> valueList; 248 ast_ptr<true, ExpList_t> valueList;
247 ast_sel<true, Block_t, Statement_t> body; 249 ast_sel<true, Block_t, Statement_t> body;
248 AST_MEMBER(SwitchCase, &valueList, &body) 250 AST_MEMBER(SwitchCase, &valueList, &body)
249AST_END(SwitchCase) 251AST_END(SwitchCase, "switch_case"sv)
250 252
251AST_NODE(Switch) 253AST_NODE(Switch)
252 ast_ptr<true, Exp_t> target; 254 ast_ptr<true, Exp_t> target;
@@ -254,37 +256,37 @@ AST_NODE(Switch)
254 ast_list<true, SwitchCase_t> branches; 256 ast_list<true, SwitchCase_t> branches;
255 ast_sel<false, Block_t, Statement_t> lastBranch; 257 ast_sel<false, Block_t, Statement_t> lastBranch;
256 AST_MEMBER(Switch, &target, &sep, &branches, &lastBranch) 258 AST_MEMBER(Switch, &target, &sep, &branches, &lastBranch)
257AST_END(Switch) 259AST_END(Switch, "switch"sv)
258 260
259AST_NODE(assignment) 261AST_NODE(assignment)
260 ast_ptr<true, ExpList_t> expList; 262 ast_ptr<true, ExpList_t> expList;
261 ast_ptr<true, Assign_t> assign; 263 ast_ptr<true, Assign_t> assign;
262 AST_MEMBER(assignment, &expList, &assign) 264 AST_MEMBER(assignment, &expList, &assign)
263AST_END(assignment) 265AST_END(assignment, "assignment"sv)
264 266
265AST_NODE(IfCond) 267AST_NODE(IfCond)
266 ast_sel<true, Exp_t, assignment_t> condition; 268 ast_sel<true, Exp_t, assignment_t> condition;
267 AST_MEMBER(IfCond, &condition) 269 AST_MEMBER(IfCond, &condition)
268AST_END(IfCond) 270AST_END(IfCond, "if_cond"sv)
269 271
270AST_LEAF(IfType) 272AST_LEAF(IfType)
271AST_END(IfType) 273AST_END(IfType, "if_type"sv)
272 274
273AST_NODE(If) 275AST_NODE(If)
274 ast_ptr<true, IfType_t> type; 276 ast_ptr<true, IfType_t> type;
275 ast_sel_list<true, IfCond_t, Block_t, Statement_t> nodes; 277 ast_sel_list<true, IfCond_t, Block_t, Statement_t> nodes;
276 AST_MEMBER(If, &type, &nodes) 278 AST_MEMBER(If, &type, &nodes)
277AST_END(If) 279AST_END(If, "if"sv)
278 280
279AST_LEAF(WhileType) 281AST_LEAF(WhileType)
280AST_END(WhileType) 282AST_END(WhileType, "while_type"sv)
281 283
282AST_NODE(While) 284AST_NODE(While)
283 ast_ptr<true, WhileType_t> type; 285 ast_ptr<true, WhileType_t> type;
284 ast_ptr<true, Exp_t> condition; 286 ast_ptr<true, Exp_t> condition;
285 ast_sel<true, Block_t, Statement_t> body; 287 ast_sel<true, Block_t, Statement_t> body;
286 AST_MEMBER(While, &type, &condition, &body) 288 AST_MEMBER(While, &type, &condition, &body)
287AST_END(While) 289AST_END(While, "while"sv)
288 290
289class Body_t; 291class Body_t;
290 292
@@ -292,12 +294,12 @@ AST_NODE(Repeat)
292 ast_ptr<true, Body_t> body; 294 ast_ptr<true, Body_t> body;
293 ast_ptr<true, Exp_t> condition; 295 ast_ptr<true, Exp_t> condition;
294 AST_MEMBER(Repeat, &body, &condition) 296 AST_MEMBER(Repeat, &body, &condition)
295AST_END(Repeat) 297AST_END(Repeat, "repeat"sv)
296 298
297AST_NODE(for_step_value) 299AST_NODE(for_step_value)
298 ast_ptr<true, Exp_t> value; 300 ast_ptr<true, Exp_t> value;
299 AST_MEMBER(for_step_value, &value) 301 AST_MEMBER(for_step_value, &value)
300AST_END(for_step_value) 302AST_END(for_step_value, "for_step_value"sv)
301 303
302AST_NODE(For) 304AST_NODE(For)
303 ast_ptr<true, Variable_t> varName; 305 ast_ptr<true, Variable_t> varName;
@@ -306,7 +308,7 @@ AST_NODE(For)
306 ast_ptr<false, for_step_value_t> stepValue; 308 ast_ptr<false, for_step_value_t> stepValue;
307 ast_sel<true, Block_t, Statement_t> body; 309 ast_sel<true, Block_t, Statement_t> body;
308 AST_MEMBER(For, &varName, &startValue, &stopValue, &stepValue, &body) 310 AST_MEMBER(For, &varName, &startValue, &stopValue, &stepValue, &body)
309AST_END(For) 311AST_END(For, "for"sv)
310 312
311class AssignableNameList_t; 313class AssignableNameList_t;
312class star_exp_t; 314class star_exp_t;
@@ -316,24 +318,24 @@ AST_NODE(ForEach)
316 ast_sel<true, star_exp_t, ExpList_t> loopValue; 318 ast_sel<true, star_exp_t, ExpList_t> loopValue;
317 ast_sel<true, Block_t, Statement_t> body; 319 ast_sel<true, Block_t, Statement_t> body;
318 AST_MEMBER(ForEach, &nameList, &loopValue, &body) 320 AST_MEMBER(ForEach, &nameList, &loopValue, &body)
319AST_END(ForEach) 321AST_END(ForEach, "for_each"sv)
320 322
321AST_NODE(Do) 323AST_NODE(Do)
322 ast_ptr<true, Body_t> body; 324 ast_ptr<true, Body_t> body;
323 AST_MEMBER(Do, &body) 325 AST_MEMBER(Do, &body)
324AST_END(Do) 326AST_END(Do, "do"sv)
325 327
326AST_NODE(catch_block) 328AST_NODE(catch_block)
327 ast_ptr<true, Variable_t> err; 329 ast_ptr<true, Variable_t> err;
328 ast_ptr<true, Block_t> body; 330 ast_ptr<true, Block_t> body;
329 AST_MEMBER(catch_block, &err, &body) 331 AST_MEMBER(catch_block, &err, &body)
330AST_END(catch_block) 332AST_END(catch_block, "catch_block"sv)
331 333
332AST_NODE(Try) 334AST_NODE(Try)
333 ast_sel<true, Block_t, Exp_t> func; 335 ast_sel<true, Block_t, Exp_t> func;
334 ast_ptr<false, catch_block_t> catchBlock; 336 ast_ptr<false, catch_block_t> catchBlock;
335 AST_MEMBER(Try, &func, &catchBlock) 337 AST_MEMBER(Try, &func, &catchBlock)
336AST_END(Try) 338AST_END(Try, "try"sv)
337 339
338class CompInner_t; 340class CompInner_t;
339 341
@@ -341,30 +343,30 @@ AST_NODE(Comprehension)
341 ast_sel<true, Exp_t, Statement_t> value; 343 ast_sel<true, Exp_t, Statement_t> value;
342 ast_ptr<true, CompInner_t> forLoop; 344 ast_ptr<true, CompInner_t> forLoop;
343 AST_MEMBER(Comprehension, &value, &forLoop) 345 AST_MEMBER(Comprehension, &value, &forLoop)
344AST_END(Comprehension) 346AST_END(Comprehension, "comp"sv)
345 347
346AST_NODE(comp_value) 348AST_NODE(comp_value)
347 ast_ptr<true, Exp_t> value; 349 ast_ptr<true, Exp_t> value;
348 AST_MEMBER(comp_value, &value) 350 AST_MEMBER(comp_value, &value)
349AST_END(comp_value) 351AST_END(comp_value, "comp_value"sv)
350 352
351AST_NODE(TblComprehension) 353AST_NODE(TblComprehension)
352 ast_ptr<true, Exp_t> key; 354 ast_ptr<true, Exp_t> key;
353 ast_ptr<false, comp_value_t> value; 355 ast_ptr<false, comp_value_t> value;
354 ast_ptr<true, CompInner_t> forLoop; 356 ast_ptr<true, CompInner_t> forLoop;
355 AST_MEMBER(TblComprehension, &key, &value, &forLoop) 357 AST_MEMBER(TblComprehension, &key, &value, &forLoop)
356AST_END(TblComprehension) 358AST_END(TblComprehension, "tbl_comp"sv)
357 359
358AST_NODE(star_exp) 360AST_NODE(star_exp)
359 ast_ptr<true, Exp_t> value; 361 ast_ptr<true, Exp_t> value;
360 AST_MEMBER(star_exp, &value) 362 AST_MEMBER(star_exp, &value)
361AST_END(star_exp) 363AST_END(star_exp, "star_exp"sv)
362 364
363AST_NODE(CompForEach) 365AST_NODE(CompForEach)
364 ast_ptr<true, AssignableNameList_t> nameList; 366 ast_ptr<true, AssignableNameList_t> nameList;
365 ast_sel<true, star_exp_t, Exp_t> loopValue; 367 ast_sel<true, star_exp_t, Exp_t> loopValue;
366 AST_MEMBER(CompForEach, &nameList, &loopValue) 368 AST_MEMBER(CompForEach, &nameList, &loopValue)
367AST_END(CompForEach) 369AST_END(CompForEach, "comp_for_each"sv)
368 370
369AST_NODE(CompFor) 371AST_NODE(CompFor)
370 ast_ptr<true, Variable_t> varName; 372 ast_ptr<true, Variable_t> varName;
@@ -372,13 +374,13 @@ AST_NODE(CompFor)
372 ast_ptr<true, Exp_t> stopValue; 374 ast_ptr<true, Exp_t> stopValue;
373 ast_ptr<false, for_step_value_t> stepValue; 375 ast_ptr<false, for_step_value_t> stepValue;
374 AST_MEMBER(CompFor, &varName, &startValue, &stopValue, &stepValue) 376 AST_MEMBER(CompFor, &varName, &startValue, &stopValue, &stepValue)
375AST_END(CompFor) 377AST_END(CompFor, "comp_for"sv)
376 378
377AST_NODE(CompInner) 379AST_NODE(CompInner)
378 ast_ptr<true, Seperator_t> sep; 380 ast_ptr<true, Seperator_t> sep;
379 ast_sel_list<true, CompFor_t, CompForEach_t, Exp_t> items; 381 ast_sel_list<true, CompFor_t, CompForEach_t, Exp_t> items;
380 AST_MEMBER(CompInner, &sep, &items) 382 AST_MEMBER(CompInner, &sep, &items)
381AST_END(CompInner) 383AST_END(CompInner, "comp_inner"sv)
382 384
383class TableBlock_t; 385class TableBlock_t;
384 386
@@ -386,29 +388,29 @@ AST_NODE(Assign)
386 ast_ptr<true, Seperator_t> sep; 388 ast_ptr<true, Seperator_t> sep;
387 ast_sel_list<true, With_t, If_t, Switch_t, TableBlock_t, Exp_t> values; 389 ast_sel_list<true, With_t, If_t, Switch_t, TableBlock_t, Exp_t> values;
388 AST_MEMBER(Assign, &sep, &values) 390 AST_MEMBER(Assign, &sep, &values)
389AST_END(Assign) 391AST_END(Assign, "assign"sv)
390 392
391AST_LEAF(update_op) 393AST_LEAF(update_op)
392AST_END(update_op) 394AST_END(update_op, "update_op"sv)
393 395
394AST_NODE(Update) 396AST_NODE(Update)
395 ast_ptr<true, update_op_t> op; 397 ast_ptr<true, update_op_t> op;
396 ast_ptr<true, Exp_t> value; 398 ast_ptr<true, Exp_t> value;
397 AST_MEMBER(Update, &op, &value) 399 AST_MEMBER(Update, &op, &value)
398AST_END(Update) 400AST_END(Update, "update"sv)
399 401
400AST_LEAF(BinaryOperator) 402AST_LEAF(BinaryOperator)
401AST_END(BinaryOperator) 403AST_END(BinaryOperator, "binary_op"sv)
402 404
403AST_LEAF(unary_operator) 405AST_LEAF(unary_operator)
404AST_END(unary_operator) 406AST_END(unary_operator, "unary_op"sv)
405 407
406class AssignableChain_t; 408class AssignableChain_t;
407 409
408AST_NODE(Assignable) 410AST_NODE(Assignable)
409 ast_sel<true, AssignableChain_t, Variable_t, SelfName_t> item; 411 ast_sel<true, AssignableChain_t, Variable_t, SelfName_t> item;
410 AST_MEMBER(Assignable, &item) 412 AST_MEMBER(Assignable, &item)
411AST_END(Assignable) 413AST_END(Assignable, "assignable"sv)
412 414
413class unary_exp_t; 415class unary_exp_t;
414 416
@@ -416,7 +418,7 @@ AST_NODE(exp_op_value)
416 ast_ptr<true, BinaryOperator_t> op; 418 ast_ptr<true, BinaryOperator_t> op;
417 ast_list<true, unary_exp_t> pipeExprs; 419 ast_list<true, unary_exp_t> pipeExprs;
418 AST_MEMBER(exp_op_value, &op, &pipeExprs) 420 AST_MEMBER(exp_op_value, &op, &pipeExprs)
419AST_END(exp_op_value) 421AST_END(exp_op_value, "exp_op_value"sv)
420 422
421AST_NODE(Exp) 423AST_NODE(Exp)
422 ast_ptr<true, Seperator_t> sep; 424 ast_ptr<true, Seperator_t> sep;
@@ -424,7 +426,7 @@ AST_NODE(Exp)
424 ast_list<false, exp_op_value_t> opValues; 426 ast_list<false, exp_op_value_t> opValues;
425 ast_ptr<false, Exp_t> nilCoalesed; 427 ast_ptr<false, Exp_t> nilCoalesed;
426 AST_MEMBER(Exp, &sep, &pipeExprs, &opValues, &nilCoalesed) 428 AST_MEMBER(Exp, &sep, &pipeExprs, &opValues, &nilCoalesed)
427AST_END(Exp) 429AST_END(Exp, "exp"sv)
428 430
429class Parens_t; 431class Parens_t;
430class MacroName_t; 432class MacroName_t;
@@ -432,12 +434,12 @@ class MacroName_t;
432AST_NODE(Callable) 434AST_NODE(Callable)
433 ast_sel<true, Variable_t, SelfName_t, VarArg_t, Parens_t, MacroName_t> item; 435 ast_sel<true, Variable_t, SelfName_t, VarArg_t, Parens_t, MacroName_t> item;
434 AST_MEMBER(Callable, &item) 436 AST_MEMBER(Callable, &item)
435AST_END(Callable) 437AST_END(Callable, "callable"sv)
436 438
437AST_NODE(variable_pair) 439AST_NODE(variable_pair)
438 ast_ptr<true, Variable_t> name; 440 ast_ptr<true, Variable_t> name;
439 AST_MEMBER(variable_pair, &name) 441 AST_MEMBER(variable_pair, &name)
440AST_END(variable_pair) 442AST_END(variable_pair, "variable_pair"sv)
441 443
442class DoubleString_t; 444class DoubleString_t;
443class SingleString_t; 445class SingleString_t;
@@ -447,7 +449,7 @@ AST_NODE(normal_pair)
447 ast_sel<true, KeyName_t, Exp_t, DoubleString_t, SingleString_t, LuaString_t> key; 449 ast_sel<true, KeyName_t, Exp_t, DoubleString_t, SingleString_t, LuaString_t> key;
448 ast_sel<true, Exp_t, TableBlock_t> value; 450 ast_sel<true, Exp_t, TableBlock_t> value;
449 AST_MEMBER(normal_pair, &key, &value) 451 AST_MEMBER(normal_pair, &key, &value)
450AST_END(normal_pair) 452AST_END(normal_pair, "normal_pair"sv)
451 453
452AST_NODE(default_pair) 454AST_NODE(default_pair)
453 ast_sel<true, Variable_t, KeyName_t, Exp_t> key; 455 ast_sel<true, Variable_t, KeyName_t, Exp_t> key;
@@ -455,18 +457,18 @@ AST_NODE(default_pair)
455 ast_ptr<false, Exp_t> value; 457 ast_ptr<false, Exp_t> value;
456 ast_ptr<true, Exp_t> defVal; 458 ast_ptr<true, Exp_t> defVal;
457 AST_MEMBER(default_pair, &key, &sep, &value, &defVal) 459 AST_MEMBER(default_pair, &key, &sep, &value, &defVal)
458AST_END(default_pair) 460AST_END(default_pair, "default_pair"sv)
459 461
460AST_NODE(meta_variable_pair) 462AST_NODE(meta_variable_pair)
461 ast_ptr<true, Variable_t> name; 463 ast_ptr<true, Variable_t> name;
462 AST_MEMBER(meta_variable_pair, &name) 464 AST_MEMBER(meta_variable_pair, &name)
463AST_END(meta_variable_pair) 465AST_END(meta_variable_pair, "meta_variable_pair"sv)
464 466
465AST_NODE(meta_normal_pair) 467AST_NODE(meta_normal_pair)
466 ast_sel<false, Name_t, Exp_t> key; 468 ast_sel<false, Name_t, Exp_t> key;
467 ast_sel<true, Exp_t, TableBlock_t> value; 469 ast_sel<true, Exp_t, TableBlock_t> value;
468 AST_MEMBER(meta_normal_pair, &key, &value) 470 AST_MEMBER(meta_normal_pair, &key, &value)
469AST_END(meta_normal_pair) 471AST_END(meta_normal_pair, "meta_normal_pair"sv)
470 472
471AST_NODE(meta_default_pair) 473AST_NODE(meta_default_pair)
472 ast_sel<false, Variable_t, Name_t> key; 474 ast_sel<false, Variable_t, Name_t> key;
@@ -474,13 +476,13 @@ AST_NODE(meta_default_pair)
474 ast_ptr<false, Exp_t> value; 476 ast_ptr<false, Exp_t> value;
475 ast_ptr<true, Exp_t> defVal; 477 ast_ptr<true, Exp_t> defVal;
476 AST_MEMBER(meta_default_pair, &key, &sep, &value, &defVal) 478 AST_MEMBER(meta_default_pair, &key, &sep, &value, &defVal)
477AST_END(meta_default_pair) 479AST_END(meta_default_pair, "meta_default_pair"sv)
478 480
479AST_NODE(simple_table) 481AST_NODE(simple_table)
480 ast_ptr<true, Seperator_t> sep; 482 ast_ptr<true, Seperator_t> sep;
481 ast_sel_list<true, variable_pair_t, normal_pair_t, meta_variable_pair_t, meta_normal_pair_t> pairs; 483 ast_sel_list<true, variable_pair_t, normal_pair_t, meta_variable_pair_t, meta_normal_pair_t> pairs;
482 AST_MEMBER(simple_table, &sep, &pairs) 484 AST_MEMBER(simple_table, &sep, &pairs)
483AST_END(simple_table) 485AST_END(simple_table, "simple_table"sv)
484 486
485class String_t; 487class String_t;
486class const_value_t; 488class const_value_t;
@@ -497,64 +499,64 @@ AST_NODE(SimpleValue)
497 TblComprehension_t, TableLit_t, Comprehension_t, 499 TblComprehension_t, TableLit_t, Comprehension_t,
498 FunLit_t, Num_t> value; 500 FunLit_t, Num_t> value;
499 AST_MEMBER(SimpleValue, &value) 501 AST_MEMBER(SimpleValue, &value)
500AST_END(SimpleValue) 502AST_END(SimpleValue, "simple_value"sv)
501 503
502AST_LEAF(LuaStringOpen) 504AST_LEAF(LuaStringOpen)
503AST_END(LuaStringOpen) 505AST_END(LuaStringOpen, "lua_string_open"sv)
504 506
505AST_LEAF(LuaStringContent) 507AST_LEAF(LuaStringContent)
506AST_END(LuaStringContent) 508AST_END(LuaStringContent, "lua_string_content"sv)
507 509
508AST_LEAF(LuaStringClose) 510AST_LEAF(LuaStringClose)
509AST_END(LuaStringClose) 511AST_END(LuaStringClose, "lua_string_close"sv)
510 512
511AST_NODE(LuaString) 513AST_NODE(LuaString)
512 ast_ptr<true, LuaStringOpen_t> open; 514 ast_ptr<true, LuaStringOpen_t> open;
513 ast_ptr<true, LuaStringContent_t> content; 515 ast_ptr<true, LuaStringContent_t> content;
514 ast_ptr<true, LuaStringClose_t> close; 516 ast_ptr<true, LuaStringClose_t> close;
515 AST_MEMBER(LuaString, &open, &content, &close) 517 AST_MEMBER(LuaString, &open, &content, &close)
516AST_END(LuaString) 518AST_END(LuaString, "lua_string"sv)
517 519
518AST_LEAF(SingleString) 520AST_LEAF(SingleString)
519AST_END(SingleString) 521AST_END(SingleString, "single_string"sv)
520 522
521AST_LEAF(double_string_inner) 523AST_LEAF(double_string_inner)
522AST_END(double_string_inner) 524AST_END(double_string_inner, "double_string_inner"sv)
523 525
524AST_NODE(double_string_content) 526AST_NODE(double_string_content)
525 ast_sel<true, double_string_inner_t, Exp_t> content; 527 ast_sel<true, double_string_inner_t, Exp_t> content;
526 AST_MEMBER(double_string_content, &content) 528 AST_MEMBER(double_string_content, &content)
527AST_END(double_string_content) 529AST_END(double_string_content, "double_string_content"sv)
528 530
529AST_NODE(DoubleString) 531AST_NODE(DoubleString)
530 ast_ptr<true, Seperator_t> sep; 532 ast_ptr<true, Seperator_t> sep;
531 ast_list<false, double_string_content_t> segments; 533 ast_list<false, double_string_content_t> segments;
532 AST_MEMBER(DoubleString, &sep, &segments) 534 AST_MEMBER(DoubleString, &sep, &segments)
533AST_END(DoubleString) 535AST_END(DoubleString, "double_string"sv)
534 536
535AST_NODE(String) 537AST_NODE(String)
536 ast_sel<true, DoubleString_t, SingleString_t, LuaString_t> str; 538 ast_sel<true, DoubleString_t, SingleString_t, LuaString_t> str;
537 AST_MEMBER(String, &str) 539 AST_MEMBER(String, &str)
538AST_END(String) 540AST_END(String, "string"sv)
539 541
540AST_LEAF(Metatable) 542AST_LEAF(Metatable)
541AST_END(Metatable) 543AST_END(Metatable, "metatable"sv)
542 544
543AST_NODE(Metamethod) 545AST_NODE(Metamethod)
544 ast_ptr<true, Name_t> name; 546 ast_ptr<true, Name_t> name;
545 AST_MEMBER(Metamethod, &name) 547 AST_MEMBER(Metamethod, &name)
546AST_END(Metamethod) 548AST_END(Metamethod, "metamethod"sv)
547 549
548AST_NODE(DotChainItem) 550AST_NODE(DotChainItem)
549 ast_sel<true, Name_t, Metatable_t, Metamethod_t> name; 551 ast_sel<true, Name_t, Metatable_t, Metamethod_t> name;
550 AST_MEMBER(DotChainItem, &name) 552 AST_MEMBER(DotChainItem, &name)
551AST_END(DotChainItem) 553AST_END(DotChainItem, "dot_chain_item"sv)
552 554
553AST_NODE(ColonChainItem) 555AST_NODE(ColonChainItem)
554 ast_sel<true, LuaKeyword_t, Name_t, Metamethod_t> name; 556 ast_sel<true, LuaKeyword_t, Name_t, Metamethod_t> name;
555 bool switchToDot = false; 557 bool switchToDot = false;
556 AST_MEMBER(ColonChainItem, &name) 558 AST_MEMBER(ColonChainItem, &name)
557AST_END(ColonChainItem) 559AST_END(ColonChainItem, "colon_chain_item"sv)
558 560
559class default_value_t; 561class default_value_t;
560 562
@@ -563,24 +565,24 @@ AST_NODE(Slice)
563 ast_sel<true, Exp_t, default_value_t> stopValue; 565 ast_sel<true, Exp_t, default_value_t> stopValue;
564 ast_sel<true, Exp_t, default_value_t> stepValue; 566 ast_sel<true, Exp_t, default_value_t> stepValue;
565 AST_MEMBER(Slice, &startValue, &stopValue, &stepValue) 567 AST_MEMBER(Slice, &startValue, &stopValue, &stepValue)
566AST_END(Slice) 568AST_END(Slice, "slice"sv)
567 569
568AST_NODE(Parens) 570AST_NODE(Parens)
569 ast_ptr<true, Exp_t> expr; 571 ast_ptr<true, Exp_t> expr;
570 AST_MEMBER(Parens, &expr) 572 AST_MEMBER(Parens, &expr)
571AST_END(Parens) 573AST_END(Parens, "parens"sv)
572 574
573AST_NODE(Invoke) 575AST_NODE(Invoke)
574 ast_ptr<true, Seperator_t> sep; 576 ast_ptr<true, Seperator_t> sep;
575 ast_sel_list<false, Exp_t, SingleString_t, DoubleString_t, LuaString_t, TableLit_t> args; 577 ast_sel_list<false, Exp_t, SingleString_t, DoubleString_t, LuaString_t, TableLit_t> args;
576 AST_MEMBER(Invoke, &sep, &args) 578 AST_MEMBER(Invoke, &sep, &args)
577AST_END(Invoke) 579AST_END(Invoke, "invoke"sv)
578 580
579AST_LEAF(existential_op) 581AST_LEAF(existential_op)
580AST_END(existential_op) 582AST_END(existential_op, "existential_op"sv)
581 583
582AST_LEAF(table_appending_op) 584AST_LEAF(table_appending_op)
583AST_END(table_appending_op) 585AST_END(table_appending_op, "table_appending_op"sv)
584 586
585class InvokeArgs_t; 587class InvokeArgs_t;
586 588
@@ -588,21 +590,21 @@ AST_NODE(ChainValue)
588 ast_ptr<true, Seperator_t> sep; 590 ast_ptr<true, Seperator_t> sep;
589 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; 591 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;
590 AST_MEMBER(ChainValue, &sep, &items) 592 AST_MEMBER(ChainValue, &sep, &items)
591AST_END(ChainValue) 593AST_END(ChainValue, "chain_value"sv)
592 594
593AST_NODE(AssignableChain) 595AST_NODE(AssignableChain)
594 ast_ptr<true, Seperator_t> sep; 596 ast_ptr<true, Seperator_t> sep;
595 ast_sel_list<true, Callable_t, Invoke_t, DotChainItem_t, ColonChainItem_t, Exp_t, String_t> items; 597 ast_sel_list<true, Callable_t, Invoke_t, DotChainItem_t, ColonChainItem_t, Exp_t, String_t> items;
596 AST_MEMBER(AssignableChain, &sep, &items) 598 AST_MEMBER(AssignableChain, &sep, &items)
597AST_END(AssignableChain) 599AST_END(AssignableChain, "assignable_chain"sv)
598 600
599AST_NODE(Value) 601AST_NODE(Value)
600 ast_sel<true, SimpleValue_t, simple_table_t, ChainValue_t, String_t> item; 602 ast_sel<true, SimpleValue_t, simple_table_t, ChainValue_t, String_t> item;
601 AST_MEMBER(Value, &item) 603 AST_MEMBER(Value, &item)
602AST_END(Value) 604AST_END(Value, "value"sv)
603 605
604AST_LEAF(default_value) 606AST_LEAF(default_value)
605AST_END(default_value) 607AST_END(default_value, "default_value"sv)
606 608
607class default_pair_t; 609class default_pair_t;
608class meta_default_pair_t; 610class meta_default_pair_t;
@@ -610,7 +612,7 @@ class meta_default_pair_t;
610AST_NODE(SpreadExp) 612AST_NODE(SpreadExp)
611 ast_ptr<true, Exp_t> exp; 613 ast_ptr<true, Exp_t> exp;
612 AST_MEMBER(SpreadExp, &exp) 614 AST_MEMBER(SpreadExp, &exp)
613AST_END(SpreadExp) 615AST_END(SpreadExp, "spread_exp"sv)
614 616
615AST_NODE(TableLit) 617AST_NODE(TableLit)
616 ast_ptr<true, Seperator_t> sep; 618 ast_ptr<true, Seperator_t> sep;
@@ -618,7 +620,7 @@ AST_NODE(TableLit)
618 variable_pair_t, normal_pair_t, SpreadExp_t, Exp_t, default_pair_t, 620 variable_pair_t, normal_pair_t, SpreadExp_t, Exp_t, default_pair_t,
619 meta_variable_pair_t, meta_normal_pair_t, meta_default_pair_t> values; 621 meta_variable_pair_t, meta_normal_pair_t, meta_default_pair_t> values;
620 AST_MEMBER(TableLit, &sep, &values) 622 AST_MEMBER(TableLit, &sep, &values)
621AST_END(TableLit) 623AST_END(TableLit, "table_lit"sv)
622 624
623AST_NODE(TableBlockIndent) 625AST_NODE(TableBlockIndent)
624 ast_ptr<true, Seperator_t> sep; 626 ast_ptr<true, Seperator_t> sep;
@@ -626,26 +628,26 @@ AST_NODE(TableBlockIndent)
626 variable_pair_t, normal_pair_t, TableBlockIndent_t, default_pair_t, 628 variable_pair_t, normal_pair_t, TableBlockIndent_t, default_pair_t,
627 meta_variable_pair_t, meta_normal_pair_t, meta_default_pair_t> values; 629 meta_variable_pair_t, meta_normal_pair_t, meta_default_pair_t> values;
628 AST_MEMBER(TableBlockIndent, &sep, &values) 630 AST_MEMBER(TableBlockIndent, &sep, &values)
629AST_END(TableBlockIndent) 631AST_END(TableBlockIndent, "table_block_indent"sv)
630 632
631AST_NODE(TableBlock) 633AST_NODE(TableBlock)
632 ast_ptr<true, Seperator_t> sep; 634 ast_ptr<true, Seperator_t> sep;
633 ast_sel_list<false, variable_pair_t, normal_pair_t, TableBlockIndent_t, Exp_t, TableBlock_t, SpreadExp_t, default_pair_t, 635 ast_sel_list<false, variable_pair_t, normal_pair_t, TableBlockIndent_t, Exp_t, TableBlock_t, SpreadExp_t, default_pair_t,
634 meta_variable_pair_t, meta_normal_pair_t, meta_default_pair_t> values; 636 meta_variable_pair_t, meta_normal_pair_t, meta_default_pair_t> values;
635 AST_MEMBER(TableBlock, &sep, &values) 637 AST_MEMBER(TableBlock, &sep, &values)
636AST_END(TableBlock) 638AST_END(TableBlock, "table_block"sv)
637 639
638AST_NODE(class_member_list) 640AST_NODE(class_member_list)
639 ast_ptr<true, Seperator_t> sep; 641 ast_ptr<true, Seperator_t> sep;
640 ast_sel_list<true, variable_pair_t, normal_pair_t> values; 642 ast_sel_list<true, variable_pair_t, normal_pair_t> values;
641 AST_MEMBER(class_member_list, &sep, &values) 643 AST_MEMBER(class_member_list, &sep, &values)
642AST_END(class_member_list) 644AST_END(class_member_list, "class_member_list"sv)
643 645
644AST_NODE(ClassBlock) 646AST_NODE(ClassBlock)
645 ast_ptr<true, Seperator_t> sep; 647 ast_ptr<true, Seperator_t> sep;
646 ast_sel_list<true, class_member_list_t, Statement_t> contents; 648 ast_sel_list<true, class_member_list_t, Statement_t> contents;
647 AST_MEMBER(ClassBlock, &sep, &contents) 649 AST_MEMBER(ClassBlock, &sep, &contents)
648AST_END(ClassBlock) 650AST_END(ClassBlock, "class_block"sv)
649 651
650AST_NODE(ClassDecl) 652AST_NODE(ClassDecl)
651 ast_ptr<false, Assignable_t> name; 653 ast_ptr<false, Assignable_t> name;
@@ -653,24 +655,24 @@ AST_NODE(ClassDecl)
653 ast_ptr<false, ExpList_t> mixes; 655 ast_ptr<false, ExpList_t> mixes;
654 ast_ptr<false, ClassBlock_t> body; 656 ast_ptr<false, ClassBlock_t> body;
655 AST_MEMBER(ClassDecl, &name, &extend, &mixes, &body) 657 AST_MEMBER(ClassDecl, &name, &extend, &mixes, &body)
656AST_END(ClassDecl) 658AST_END(ClassDecl, "class_decl"sv)
657 659
658AST_NODE(global_values) 660AST_NODE(global_values)
659 ast_ptr<true, NameList_t> nameList; 661 ast_ptr<true, NameList_t> nameList;
660 ast_sel<false, TableBlock_t, ExpListLow_t> valueList; 662 ast_sel<false, TableBlock_t, ExpListLow_t> valueList;
661 AST_MEMBER(global_values, &nameList, &valueList) 663 AST_MEMBER(global_values, &nameList, &valueList)
662AST_END(global_values) 664AST_END(global_values, "global_values"sv)
663 665
664AST_LEAF(global_op) 666AST_LEAF(global_op)
665AST_END(global_op) 667AST_END(global_op, "global_op"sv)
666 668
667AST_NODE(Global) 669AST_NODE(Global)
668 ast_sel<true, ClassDecl_t, global_op_t, global_values_t> item; 670 ast_sel<true, ClassDecl_t, global_op_t, global_values_t> item;
669 AST_MEMBER(Global, &item) 671 AST_MEMBER(Global, &item)
670AST_END(Global) 672AST_END(Global, "global"sv)
671 673
672AST_LEAF(export_default) 674AST_LEAF(export_default)
673AST_END(export_default) 675AST_END(export_default, "export_default"sv)
674 676
675class Macro_t; 677class Macro_t;
676 678
@@ -679,125 +681,125 @@ AST_NODE(Export)
679 ast_sel<true, ExpList_t, Exp_t, Macro_t> target; 681 ast_sel<true, ExpList_t, Exp_t, Macro_t> target;
680 ast_ptr<false, Assign_t> assign; 682 ast_ptr<false, Assign_t> assign;
681 AST_MEMBER(Export, &def, &target, &assign) 683 AST_MEMBER(Export, &def, &target, &assign)
682AST_END(Export) 684AST_END(Export, "export"sv)
683 685
684AST_NODE(FnArgDef) 686AST_NODE(FnArgDef)
685 ast_sel<true, Variable_t, SelfName_t> name; 687 ast_sel<true, Variable_t, SelfName_t> name;
686 ast_ptr<false, existential_op_t> op; 688 ast_ptr<false, existential_op_t> op;
687 ast_ptr<false, Exp_t> defaultValue; 689 ast_ptr<false, Exp_t> defaultValue;
688 AST_MEMBER(FnArgDef, &name, &op, &defaultValue) 690 AST_MEMBER(FnArgDef, &name, &op, &defaultValue)
689AST_END(FnArgDef) 691AST_END(FnArgDef, "fn_arg_def"sv)
690 692
691AST_NODE(FnArgDefList) 693AST_NODE(FnArgDefList)
692 ast_ptr<true, Seperator_t> sep; 694 ast_ptr<true, Seperator_t> sep;
693 ast_list<false, FnArgDef_t> definitions; 695 ast_list<false, FnArgDef_t> definitions;
694 ast_ptr<false, VarArg_t> varArg; 696 ast_ptr<false, VarArg_t> varArg;
695 AST_MEMBER(FnArgDefList, &sep, &definitions, &varArg) 697 AST_MEMBER(FnArgDefList, &sep, &definitions, &varArg)
696AST_END(FnArgDefList) 698AST_END(FnArgDefList, "fn_arg_def_list"sv)
697 699
698AST_NODE(outer_var_shadow) 700AST_NODE(outer_var_shadow)
699 ast_ptr<false, NameList_t> varList; 701 ast_ptr<false, NameList_t> varList;
700 AST_MEMBER(outer_var_shadow, &varList) 702 AST_MEMBER(outer_var_shadow, &varList)
701AST_END(outer_var_shadow) 703AST_END(outer_var_shadow, "outer_var_shadow"sv)
702 704
703AST_NODE(FnArgsDef) 705AST_NODE(FnArgsDef)
704 ast_ptr<false, FnArgDefList_t> defList; 706 ast_ptr<false, FnArgDefList_t> defList;
705 ast_ptr<false, outer_var_shadow_t> shadowOption; 707 ast_ptr<false, outer_var_shadow_t> shadowOption;
706 AST_MEMBER(FnArgsDef, &defList, &shadowOption) 708 AST_MEMBER(FnArgsDef, &defList, &shadowOption)
707AST_END(FnArgsDef) 709AST_END(FnArgsDef, "fn_args_def"sv)
708 710
709AST_LEAF(fn_arrow) 711AST_LEAF(fn_arrow)
710AST_END(fn_arrow) 712AST_END(fn_arrow, "fn_arrow"sv)
711 713
712AST_NODE(FunLit) 714AST_NODE(FunLit)
713 ast_ptr<false, FnArgsDef_t> argsDef; 715 ast_ptr<false, FnArgsDef_t> argsDef;
714 ast_ptr<true, fn_arrow_t> arrow; 716 ast_ptr<true, fn_arrow_t> arrow;
715 ast_ptr<false, Body_t> body; 717 ast_ptr<false, Body_t> body;
716 AST_MEMBER(FunLit, &argsDef, &arrow, &body) 718 AST_MEMBER(FunLit, &argsDef, &arrow, &body)
717AST_END(FunLit) 719AST_END(FunLit, "fun_lit"sv)
718 720
719AST_NODE(MacroName) 721AST_NODE(MacroName)
720 ast_ptr<true, Name_t> name; 722 ast_ptr<true, Name_t> name;
721 AST_MEMBER(MacroName, &name) 723 AST_MEMBER(MacroName, &name)
722AST_END(MacroName) 724AST_END(MacroName, "macro_name"sv)
723 725
724AST_NODE(MacroLit) 726AST_NODE(MacroLit)
725 ast_ptr<false, FnArgDefList_t> argsDef; 727 ast_ptr<false, FnArgDefList_t> argsDef;
726 ast_ptr<true, Body_t> body; 728 ast_ptr<true, Body_t> body;
727 AST_MEMBER(MacroLit, &argsDef, &body) 729 AST_MEMBER(MacroLit, &argsDef, &body)
728AST_END(MacroLit) 730AST_END(MacroLit, "macro_lit"sv)
729 731
730AST_NODE(MacroInPlace) 732AST_NODE(MacroInPlace)
731 ast_ptr<true, Body_t> body; 733 ast_ptr<true, Body_t> body;
732 AST_MEMBER(MacroInPlace, &body) 734 AST_MEMBER(MacroInPlace, &body)
733AST_END(MacroInPlace) 735AST_END(MacroInPlace, "macro_in_place"sv)
734 736
735AST_NODE(Macro) 737AST_NODE(Macro)
736 ast_ptr<true, Name_t> name; 738 ast_ptr<true, Name_t> name;
737 ast_ptr<true, MacroLit_t> macroLit; 739 ast_ptr<true, MacroLit_t> macroLit;
738 AST_MEMBER(Macro, &name, &macroLit) 740 AST_MEMBER(Macro, &name, &macroLit)
739AST_END(Macro) 741AST_END(Macro, "macro"sv)
740 742
741AST_NODE(NameOrDestructure) 743AST_NODE(NameOrDestructure)
742 ast_sel<true, Variable_t, TableLit_t> item; 744 ast_sel<true, Variable_t, TableLit_t> item;
743 AST_MEMBER(NameOrDestructure, &item) 745 AST_MEMBER(NameOrDestructure, &item)
744AST_END(NameOrDestructure) 746AST_END(NameOrDestructure, "name_or_des"sv)
745 747
746AST_NODE(AssignableNameList) 748AST_NODE(AssignableNameList)
747 ast_ptr<true, Seperator_t> sep; 749 ast_ptr<true, Seperator_t> sep;
748 ast_list<true, NameOrDestructure_t> items; 750 ast_list<true, NameOrDestructure_t> items;
749 AST_MEMBER(AssignableNameList, &sep, &items) 751 AST_MEMBER(AssignableNameList, &sep, &items)
750AST_END(AssignableNameList) 752AST_END(AssignableNameList, "assignable_name_list"sv)
751 753
752AST_NODE(InvokeArgs) 754AST_NODE(InvokeArgs)
753 ast_ptr<true, Seperator_t> sep; 755 ast_ptr<true, Seperator_t> sep;
754 ast_sel_list<true, Exp_t, TableBlock_t> args; 756 ast_sel_list<true, Exp_t, TableBlock_t> args;
755 AST_MEMBER(InvokeArgs, &sep, &args) 757 AST_MEMBER(InvokeArgs, &sep, &args)
756AST_END(InvokeArgs) 758AST_END(InvokeArgs, "invoke_args"sv)
757 759
758AST_LEAF(const_value) 760AST_LEAF(const_value)
759AST_END(const_value) 761AST_END(const_value, "const_value"sv)
760 762
761AST_NODE(unary_value) 763AST_NODE(unary_value)
762 ast_list<true, unary_operator_t> ops; 764 ast_list<true, unary_operator_t> ops;
763 ast_ptr<true, Value_t> value; 765 ast_ptr<true, Value_t> value;
764 AST_MEMBER(unary_value, &ops, &value) 766 AST_MEMBER(unary_value, &ops, &value)
765AST_END(unary_value) 767AST_END(unary_value, "unary_value"sv)
766 768
767AST_NODE(unary_exp) 769AST_NODE(unary_exp)
768 ast_list<false, unary_operator_t> ops; 770 ast_list<false, unary_operator_t> ops;
769 ast_list<true, Value_t> expos; 771 ast_list<true, Value_t> expos;
770 AST_MEMBER(unary_exp, &ops, &expos) 772 AST_MEMBER(unary_exp, &ops, &expos)
771AST_END(unary_exp) 773AST_END(unary_exp, "unary_exp"sv)
772 774
773AST_NODE(ExpListAssign) 775AST_NODE(ExpListAssign)
774 ast_ptr<true, ExpList_t> expList; 776 ast_ptr<true, ExpList_t> expList;
775 ast_sel<false, Update_t, Assign_t> action; 777 ast_sel<false, Update_t, Assign_t> action;
776 AST_MEMBER(ExpListAssign, &expList, &action) 778 AST_MEMBER(ExpListAssign, &expList, &action)
777AST_END(ExpListAssign) 779AST_END(ExpListAssign, "exp_list_assign"sv)
778 780
779AST_NODE(if_line) 781AST_NODE(if_line)
780 ast_ptr<true, IfType_t> type; 782 ast_ptr<true, IfType_t> type;
781 ast_ptr<true, IfCond_t> condition; 783 ast_ptr<true, IfCond_t> condition;
782 AST_MEMBER(if_line, &type, &condition) 784 AST_MEMBER(if_line, &type, &condition)
783AST_END(if_line) 785AST_END(if_line, "if_line"sv)
784 786
785AST_LEAF(BreakLoop) 787AST_LEAF(BreakLoop)
786AST_END(BreakLoop) 788AST_END(BreakLoop, "break_loop"sv)
787 789
788AST_NODE(PipeBody) 790AST_NODE(PipeBody)
789 ast_ptr<true, Seperator_t> sep; 791 ast_ptr<true, Seperator_t> sep;
790 ast_list<true, unary_exp_t> values; 792 ast_list<true, unary_exp_t> values;
791 AST_MEMBER(PipeBody, &sep, &values) 793 AST_MEMBER(PipeBody, &sep, &values)
792AST_END(PipeBody) 794AST_END(PipeBody, "pipe_body"sv)
793 795
794AST_NODE(statement_appendix) 796AST_NODE(statement_appendix)
795 ast_sel<true, if_line_t, CompInner_t> item; 797 ast_sel<true, if_line_t, CompInner_t> item;
796 AST_MEMBER(statement_appendix, &item) 798 AST_MEMBER(statement_appendix, &item)
797AST_END(statement_appendix) 799AST_END(statement_appendix, "statement_appendix"sv)
798 800
799AST_LEAF(statement_sep) 801AST_LEAF(statement_sep)
800AST_END(statement_sep) 802AST_END(statement_sep, "statement_sep"sv)
801 803
802AST_NODE(Statement) 804AST_NODE(Statement)
803 ast_sel<true, Import_t, While_t, Repeat_t, For_t, ForEach_t, 805 ast_sel<true, Import_t, While_t, Repeat_t, For_t, ForEach_t,
@@ -807,29 +809,29 @@ AST_NODE(Statement)
807 ast_ptr<false, statement_appendix_t> appendix; 809 ast_ptr<false, statement_appendix_t> appendix;
808 ast_ptr<false, statement_sep_t> needSep; 810 ast_ptr<false, statement_sep_t> needSep;
809 AST_MEMBER(Statement, &content, &appendix, &needSep) 811 AST_MEMBER(Statement, &content, &appendix, &needSep)
810AST_END(Statement) 812AST_END(Statement, "statement"sv)
811 813
812class Block_t; 814class Block_t;
813 815
814AST_NODE(Body) 816AST_NODE(Body)
815 ast_sel<true, Block_t, Statement_t> content; 817 ast_sel<true, Block_t, Statement_t> content;
816 AST_MEMBER(Body, &content) 818 AST_MEMBER(Body, &content)
817AST_END(Body) 819AST_END(Body, "body"sv)
818 820
819AST_NODE(Block) 821AST_NODE(Block)
820 ast_ptr<true, Seperator_t> sep; 822 ast_ptr<true, Seperator_t> sep;
821 ast_list<false, Statement_t> statements; 823 ast_list<false, Statement_t> statements;
822 AST_MEMBER(Block, &sep, &statements) 824 AST_MEMBER(Block, &sep, &statements)
823AST_END(Block) 825AST_END(Block, "block"sv)
824 826
825AST_NODE(BlockEnd) 827AST_NODE(BlockEnd)
826 ast_ptr<true, Block_t> block; 828 ast_ptr<true, Block_t> block;
827 AST_MEMBER(BlockEnd, &block) 829 AST_MEMBER(BlockEnd, &block)
828AST_END(BlockEnd) 830AST_END(BlockEnd, "block_end"sv)
829 831
830AST_NODE(File) 832AST_NODE(File)
831 ast_ptr<false, Block_t> block; 833 ast_ptr<false, Block_t> block;
832 AST_MEMBER(File, &block) 834 AST_MEMBER(File, &block)
833AST_END(File) 835AST_END(File, "file"sv)
834 836
835} // namespace parserlib 837} // namespace parserlib
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp
index 1546b85..7d7bf25 100755
--- a/src/yuescript/yue_compiler.cpp
+++ b/src/yuescript/yue_compiler.cpp
@@ -60,7 +60,7 @@ using namespace parserlib;
60 60
61typedef std::list<std::string> str_list; 61typedef std::list<std::string> str_list;
62 62
63const std::string_view version = "0.10.16"sv; 63const std::string_view version = "0.10.17"sv;
64const std::string_view extension = "yue"sv; 64const std::string_view extension = "yue"sv;
65 65
66class YueCompilerImpl { 66class YueCompilerImpl {
diff --git a/src/yuescript/yuescript.cpp b/src/yuescript/yuescript.cpp
index 5e21fc5..2e96f16 100644
--- a/src/yuescript/yuescript.cpp
+++ b/src/yuescript/yuescript.cpp
@@ -5,7 +5,9 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
5The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 5The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6 6
7THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 7THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
8
8#include "yuescript/yue_compiler.h" 9#include "yuescript/yue_compiler.h"
10#include "yuescript/yue_parser.h"
9 11
10#if defined(YUE_BUILD_AS_DLL) 12#if defined(YUE_BUILD_AS_DLL)
11#define YUE_API __declspec(dllexport) 13#define YUE_API __declspec(dllexport)
@@ -130,8 +132,87 @@ static int yuetolua(lua_State* L) {
130 return 3; 132 return 3;
131} 133}
132 134
135static int yuetoast(lua_State* L) {
136 size_t size = 0;
137 const char* input = luaL_checklstring(L, 1, &size);
138 int flattenLevel = 2;
139 if (lua_isnoneornil(L, 2) == 0) {
140 flattenLevel = static_cast<int>(luaL_checkinteger(L, 2));
141 flattenLevel = std::max(std::min(2, flattenLevel), 0);
142 }
143 yue::YueParser parser;
144 auto info = parser.parse<yue::File_t>({input, size});
145 if (info.node) {
146 lua_createtable(L, 0, 0);
147 int cacheIndex = lua_gettop(L);
148 auto getName = [&](yue::ast_node* node) {
149 int id = node->getId();
150 lua_rawgeti(L, cacheIndex, id);
151 if (lua_isnil(L, -1) != 0) {
152 lua_pop(L, 1);
153 auto name = node->getName();
154 lua_pushlstring(L, &name.front(), name.length());
155 lua_pushvalue(L, -1);
156 lua_rawseti(L, cacheIndex, id);
157 }
158 };
159 std::function<void(yue::ast_node*)> visit;
160 visit = [&](yue::ast_node* node) {
161 int count = 0;
162 bool hasSep = false;
163 node->visitChild([&](yue::ast_node* child) {
164 if (yue::ast_is<yue::Seperator_t>(child)) {
165 hasSep = true;
166 return false;
167 }
168 count++;
169 visit(child);
170 return false;
171 });
172 switch (count) {
173 case 0: {
174 lua_createtable(L, 2, 0);
175 getName(node);
176 lua_rawseti(L, -2, 1);
177 auto str = parser.toString(node);
178 yue::Utils::trim(str);
179 lua_pushlstring(L, str.c_str(), str.length());
180 lua_rawseti(L, -2, 2);
181 break;
182 }
183 case 1: {
184 if (flattenLevel > 1 || (flattenLevel == 1 && !hasSep)) {
185 getName(node);
186 lua_rawseti(L, -2, 1);
187 break;
188 }
189 }
190 default: {
191 lua_createtable(L, count + 1, 0);
192 getName(node);
193 lua_rawseti(L, -2, 1);
194 for (int i = count, j = 2; i >= 1; i--, j++) {
195 lua_pushvalue(L, -1 - i);
196 lua_rawseti(L, -2, j);
197 }
198 lua_insert(L, -1 - count);
199 lua_pop(L, count);
200 break;
201 }
202 }
203 };
204 visit(info.node);
205 return 1;
206 } else {
207 lua_pushnil(L);
208 lua_pushlstring(L, info.error.c_str(), info.error.length());
209 return 2;
210 }
211}
212
133static const luaL_Reg yuelib[] = { 213static const luaL_Reg yuelib[] = {
134 {"to_lua", yuetolua}, 214 {"to_lua", yuetolua},
215 {"to_ast", yuetoast},
135 {"version", nullptr}, 216 {"version", nullptr},
136 {"options", nullptr}, 217 {"options", nullptr},
137 {"load_stacktraceplus", nullptr}, 218 {"load_stacktraceplus", nullptr},