diff options
Diffstat (limited to 'MoonParser/moon_ast.h')
-rw-r--r-- | MoonParser/moon_ast.h | 418 |
1 files changed, 250 insertions, 168 deletions
diff --git a/MoonParser/moon_ast.h b/MoonParser/moon_ast.h index 795c0c8..a77fb40 100644 --- a/MoonParser/moon_ast.h +++ b/MoonParser/moon_ast.h | |||
@@ -2,31 +2,11 @@ | |||
2 | 2 | ||
3 | #include "moon_parser.h" | 3 | #include "moon_parser.h" |
4 | 4 | ||
5 | template <typename T> | 5 | namespace MoonP { |
6 | std::basic_string<T>& trim(std::basic_string<T>& s) | ||
7 | { | ||
8 | s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](T ch) | ||
9 | { | ||
10 | return !std::isspace(ch); | ||
11 | })); | ||
12 | s.erase(std::find_if(s.rbegin(), s.rend(), [](T ch) | ||
13 | { | ||
14 | return !std::isspace(ch); | ||
15 | }).base(), s.end()); | ||
16 | return s; | ||
17 | } | ||
18 | |||
19 | class AstLeaf : public ast_node | ||
20 | { | ||
21 | public: | ||
22 | const input& getValue(); | ||
23 | private: | ||
24 | input _value; | ||
25 | }; | ||
26 | 6 | ||
27 | #define AST_LEAF(type, id) \ | 7 | #define AST_LEAF(type, id) \ |
28 | extern rule type; \ | 8 | extern rule type; \ |
29 | class type##_t : public AstLeaf \ | 9 | class type##_t : public ast_node \ |
30 | { \ | 10 | { \ |
31 | public: \ | 11 | public: \ |
32 | virtual int get_type() override { return ast_type<type##_t>(); } \ | 12 | virtual int get_type() override { return ast_type<type##_t>(); } \ |
@@ -42,6 +22,11 @@ public: \ | |||
42 | virtual size_t getId() const override { return id; } \ | 22 | virtual size_t getId() const override { return id; } \ |
43 | virtual const char* getName() const override { return #type; } | 23 | virtual const char* getName() const override { return #type; } |
44 | 24 | ||
25 | #define AST_MEMBER(type, ...) \ | ||
26 | type##_t() { \ | ||
27 | add_members({__VA_ARGS__}); \ | ||
28 | } | ||
29 | |||
45 | #define AST_END(type) \ | 30 | #define AST_END(type) \ |
46 | }; | 31 | }; |
47 | 32 | ||
@@ -52,29 +37,39 @@ AST_LEAF(Name, "Name"_id) | |||
52 | AST_END(Name) | 37 | AST_END(Name) |
53 | 38 | ||
54 | AST_NODE(Variable, "Variable"_id) | 39 | AST_NODE(Variable, "Variable"_id) |
55 | ast_ptr<Name_t> name; | 40 | ast_ptr<true, Name_t> name; |
41 | AST_MEMBER(Variable, &name) | ||
56 | AST_END(Variable) | 42 | AST_END(Variable) |
57 | 43 | ||
44 | AST_NODE(LuaKeyword, "LuaKeyword"_id) | ||
45 | ast_ptr<true, Name_t> name; | ||
46 | AST_MEMBER(LuaKeyword, &name) | ||
47 | AST_END(LuaKeyword) | ||
48 | |||
58 | AST_LEAF(self, "self"_id) | 49 | AST_LEAF(self, "self"_id) |
59 | AST_END(self) | 50 | AST_END(self) |
60 | 51 | ||
61 | AST_NODE(self_name, "self_name"_id) | 52 | AST_NODE(self_name, "self_name"_id) |
62 | ast_ptr<Name_t> name; | 53 | ast_ptr<true, Name_t> name; |
54 | AST_MEMBER(self_name, &name) | ||
63 | AST_END(self_name) | 55 | AST_END(self_name) |
64 | 56 | ||
65 | AST_LEAF(self_class, "self_class"_id) | 57 | AST_LEAF(self_class, "self_class"_id) |
66 | AST_END(self_class) | 58 | AST_END(self_class) |
67 | 59 | ||
68 | AST_NODE(self_class_name, "self_class_name"_id) | 60 | AST_NODE(self_class_name, "self_class_name"_id) |
69 | ast_ptr<Name_t> name; | 61 | ast_ptr<true, Name_t> name; |
62 | AST_MEMBER(self_class_name, &name) | ||
70 | AST_END(self_class_name) | 63 | AST_END(self_class_name) |
71 | 64 | ||
72 | AST_NODE(SelfName, "SelfName"_id) | 65 | AST_NODE(SelfName, "SelfName"_id) |
73 | ast_ptr<ast_node> name; // self_class_name_t | self_class_t | self_name_t | self_t | 66 | ast_sel<true, self_class_name_t, self_class_t, self_name_t, self_t> name; |
67 | AST_MEMBER(SelfName, &name) | ||
74 | AST_END(SelfName) | 68 | AST_END(SelfName) |
75 | 69 | ||
76 | AST_NODE(KeyName, "KeyName"_id) | 70 | AST_NODE(KeyName, "KeyName"_id) |
77 | ast_ptr<ast_node> name; // SelfName_t | Name_t | 71 | ast_sel<true, SelfName_t, Name_t> name; |
72 | AST_MEMBER(KeyName, &name) | ||
78 | AST_END(KeyName) | 73 | AST_END(KeyName) |
79 | 74 | ||
80 | AST_LEAF(VarArg, "VarArg"_id) | 75 | AST_LEAF(VarArg, "VarArg"_id) |
@@ -87,207 +82,254 @@ AST_LEAF(Seperator, "Seperator"_id) | |||
87 | AST_END(Seperator) | 82 | AST_END(Seperator) |
88 | 83 | ||
89 | AST_NODE(NameList, "NameList"_id) | 84 | AST_NODE(NameList, "NameList"_id) |
90 | ast_ptr<Seperator_t> sep; | 85 | ast_ptr<true, Seperator_t> sep; |
91 | ast_list<Variable_t> names; | 86 | ast_list<true, Variable_t> names; |
87 | AST_MEMBER(NameList, &sep, &names) | ||
92 | AST_END(NameList) | 88 | AST_END(NameList) |
93 | 89 | ||
94 | AST_NODE(Local, "Local"_id) | 90 | AST_NODE(Local, "Local"_id) |
95 | ast_ptr<ast_node> name; // local_flag_t | NameList_t | 91 | ast_sel<true, local_flag_t, NameList_t> name; |
96 | std::list<std::string> forceDecls; | 92 | std::list<std::string> forceDecls; |
97 | std::list<std::string> decls; | 93 | std::list<std::string> decls; |
94 | AST_MEMBER(Local, &name) | ||
98 | AST_END(Local) | 95 | AST_END(Local) |
99 | 96 | ||
100 | AST_NODE(colon_import_name, "colon_import_name"_id) | 97 | AST_NODE(colon_import_name, "colon_import_name"_id) |
101 | ast_ptr<Variable_t> name; | 98 | ast_ptr<true, Variable_t> name; |
99 | AST_MEMBER(colon_import_name, &name) | ||
102 | AST_END(colon_import_name) | 100 | AST_END(colon_import_name) |
103 | 101 | ||
104 | class Exp_t; | 102 | class Exp_t; |
105 | 103 | ||
106 | AST_NODE(Import, "Import"_id) | 104 | AST_NODE(Import, "Import"_id) |
107 | ast_ptr<Seperator_t> sep; | 105 | ast_ptr<true, Seperator_t> sep; |
108 | ast_sel_list<colon_import_name_t, Variable_t> names; | 106 | ast_sel_list<true, colon_import_name_t, Variable_t> names; |
109 | ast_ptr<Exp_t> exp; | 107 | ast_ptr<true, Exp_t> exp; |
108 | AST_MEMBER(Import, &sep, &names, &exp) | ||
110 | AST_END(Import) | 109 | AST_END(Import) |
111 | 110 | ||
112 | AST_NODE(ExpListLow, "ExpListLow"_id) | 111 | AST_NODE(ExpListLow, "ExpListLow"_id) |
113 | ast_ptr<Seperator_t> sep; | 112 | ast_ptr<true, Seperator_t> sep; |
114 | ast_list<Exp_t> exprs; | 113 | ast_list<true, Exp_t> exprs; |
114 | AST_MEMBER(ExpListLow, &sep, &exprs) | ||
115 | AST_END(ExpListLow) | 115 | AST_END(ExpListLow) |
116 | 116 | ||
117 | AST_NODE(ExpList, "ExpList"_id) | 117 | AST_NODE(ExpList, "ExpList"_id) |
118 | ast_ptr<Seperator_t> sep; | 118 | ast_ptr<true, Seperator_t> sep; |
119 | ast_list<Exp_t> exprs; | 119 | ast_list<true, Exp_t> exprs; |
120 | AST_MEMBER(ExpList, &sep, &exprs) | ||
120 | AST_END(ExpList) | 121 | AST_END(ExpList) |
121 | 122 | ||
122 | AST_NODE(Return, "Return"_id) | 123 | AST_NODE(Return, "Return"_id) |
123 | ast_ptr<ExpListLow_t, true> valueList; | 124 | ast_ptr<false, ExpListLow_t> valueList; |
125 | AST_MEMBER(Return, &valueList) | ||
124 | AST_END(Return) | 126 | AST_END(Return) |
125 | 127 | ||
126 | class Assign_t; | 128 | class Assign_t; |
127 | class Body_t; | 129 | class Body_t; |
128 | 130 | ||
129 | AST_NODE(With, "With"_id) | 131 | AST_NODE(With, "With"_id) |
130 | ast_ptr<ExpList_t> valueList; | 132 | ast_ptr<true, ExpList_t> valueList; |
131 | ast_ptr<Assign_t, true> assigns; | 133 | ast_ptr<false, Assign_t> assigns; |
132 | ast_ptr<Body_t> body; | 134 | ast_ptr<true, Body_t> body; |
135 | AST_MEMBER(With, &valueList, &assigns, &body) | ||
133 | AST_END(With) | 136 | AST_END(With) |
134 | 137 | ||
135 | AST_NODE(SwitchCase, "SwitchCase"_id) | 138 | AST_NODE(SwitchCase, "SwitchCase"_id) |
136 | ast_ptr<ExpList_t> valueList; | 139 | ast_ptr<true, ExpList_t> valueList; |
137 | ast_ptr<Body_t> body; | 140 | ast_ptr<true, Body_t> body; |
141 | AST_MEMBER(SwitchCase, &valueList, &body) | ||
138 | AST_END(SwitchCase) | 142 | AST_END(SwitchCase) |
139 | 143 | ||
140 | AST_NODE(Switch, "Switch"_id) | 144 | AST_NODE(Switch, "Switch"_id) |
141 | ast_ptr<Exp_t> target; | 145 | ast_ptr<true, Exp_t> target; |
142 | ast_ptr<Seperator_t> sep; | 146 | ast_ptr<true, Seperator_t> sep; |
143 | ast_list<SwitchCase_t> branches; | 147 | ast_list<true, SwitchCase_t> branches; |
144 | ast_ptr<Body_t, true> lastBranch; | 148 | ast_ptr<false, Body_t> lastBranch; |
149 | AST_MEMBER(Switch, &target, &sep, &branches, &lastBranch) | ||
145 | AST_END(Switch) | 150 | AST_END(Switch) |
146 | 151 | ||
147 | AST_NODE(IfCond, "IfCond"_id) | 152 | AST_NODE(IfCond, "IfCond"_id) |
148 | ast_ptr<Exp_t> condition; | 153 | ast_ptr<true, Exp_t> condition; |
149 | ast_ptr<Assign_t, true> assign; | 154 | ast_ptr<false, Assign_t> assign; |
155 | AST_MEMBER(IfCond, &condition, &assign) | ||
150 | AST_END(IfCond) | 156 | AST_END(IfCond) |
151 | 157 | ||
152 | AST_NODE(If, "If"_id) | 158 | AST_NODE(If, "If"_id) |
153 | ast_ptr<Seperator_t> sep; | 159 | ast_ptr<true, Seperator_t> sep; |
154 | ast_sel_list<IfCond_t, Body_t> nodes; | 160 | ast_sel_list<true, IfCond_t, Body_t> nodes; |
161 | AST_MEMBER(If, &sep, &nodes) | ||
155 | AST_END(If) | 162 | AST_END(If) |
156 | 163 | ||
157 | AST_NODE(Unless, "Unless"_id) | 164 | AST_NODE(Unless, "Unless"_id) |
158 | ast_ptr<Seperator_t> sep; | 165 | ast_ptr<true, Seperator_t> sep; |
159 | ast_sel_list<IfCond_t, Body_t> nodes; | 166 | ast_sel_list<true, IfCond_t, Body_t> nodes; |
167 | AST_MEMBER(Unless, &sep, &nodes) | ||
160 | AST_END(Unless) | 168 | AST_END(Unless) |
161 | 169 | ||
162 | AST_NODE(While, "While"_id) | 170 | AST_NODE(While, "While"_id) |
163 | ast_ptr<Exp_t> condition; | 171 | ast_ptr<true, Exp_t> condition; |
164 | ast_ptr<Body_t> body; | 172 | ast_ptr<true, Body_t> body; |
173 | AST_MEMBER(While, &condition, &body) | ||
165 | AST_END(While) | 174 | AST_END(While) |
166 | 175 | ||
167 | AST_NODE(for_step_value, "for_step_value"_id) | 176 | AST_NODE(for_step_value, "for_step_value"_id) |
168 | ast_ptr<Exp_t> value; | 177 | ast_ptr<true, Exp_t> value; |
178 | AST_MEMBER(for_step_value, &value) | ||
169 | AST_END(for_step_value) | 179 | AST_END(for_step_value) |
170 | 180 | ||
171 | AST_NODE(For, "For"_id) | 181 | AST_NODE(For, "For"_id) |
172 | ast_ptr<Variable_t> varName; | 182 | ast_ptr<true, Variable_t> varName; |
173 | ast_ptr<Exp_t> startValue; | 183 | ast_ptr<true, Exp_t> startValue; |
174 | ast_ptr<Exp_t> stopValue; | 184 | ast_ptr<true, Exp_t> stopValue; |
175 | ast_ptr<for_step_value_t, true> stepValue; | 185 | ast_ptr<false, for_step_value_t> stepValue; |
176 | ast_ptr<Body_t> body; | 186 | ast_ptr<true, Body_t> body; |
187 | AST_MEMBER(For, &varName, &startValue, &stopValue, &stepValue, &body) | ||
177 | AST_END(For) | 188 | AST_END(For) |
178 | 189 | ||
179 | class AssignableNameList_t; | 190 | class AssignableNameList_t; |
191 | class star_exp_t; | ||
180 | 192 | ||
181 | AST_NODE(ForEach, "ForEach"_id) | 193 | AST_NODE(ForEach, "ForEach"_id) |
182 | ast_ptr<AssignableNameList_t> nameList; | 194 | ast_ptr<true, AssignableNameList_t> nameList; |
183 | ast_ptr<ast_node> loopValue; // Exp_t | ExpList_t | 195 | ast_sel<true, star_exp_t, ExpList_t> loopValue; |
184 | ast_ptr<Body_t> body; | 196 | ast_ptr<true, Body_t> body; |
197 | AST_MEMBER(ForEach, &nameList, &loopValue, &body) | ||
185 | AST_END(ForEach) | 198 | AST_END(ForEach) |
186 | 199 | ||
187 | AST_NODE(Do, "Do"_id) | 200 | AST_NODE(Do, "Do"_id) |
188 | ast_ptr<Body_t> body; | 201 | ast_ptr<true, Body_t> body; |
202 | AST_MEMBER(Do, &body) | ||
189 | AST_END(Do) | 203 | AST_END(Do) |
190 | 204 | ||
191 | class CompInner_t; | 205 | class CompInner_t; |
192 | class Statement_t; | 206 | class Statement_t; |
193 | 207 | ||
194 | AST_NODE(Comprehension, "Comprehension"_id) | 208 | AST_NODE(Comprehension, "Comprehension"_id) |
195 | ast_sel<Exp_t, Statement_t> value; | 209 | ast_sel<true, Exp_t, Statement_t> value; |
196 | ast_ptr<CompInner_t> forLoop; | 210 | ast_ptr<true, CompInner_t> forLoop; |
211 | AST_MEMBER(Comprehension, &value, &forLoop) | ||
197 | AST_END(Comprehension) | 212 | AST_END(Comprehension) |
198 | 213 | ||
199 | AST_NODE(comp_value, "comp_value"_id) | 214 | AST_NODE(comp_value, "comp_value"_id) |
200 | ast_ptr<Exp_t> value; | 215 | ast_ptr<true, Exp_t> value; |
216 | AST_MEMBER(comp_value, &value) | ||
201 | AST_END(comp_value) | 217 | AST_END(comp_value) |
202 | 218 | ||
203 | AST_NODE(TblComprehension, "TblComprehension"_id) | 219 | AST_NODE(TblComprehension, "TblComprehension"_id) |
204 | ast_ptr<Exp_t> key; | 220 | ast_ptr<true, Exp_t> key; |
205 | ast_ptr<comp_value_t, true> value; | 221 | ast_ptr<false, comp_value_t> value; |
206 | ast_ptr<CompInner_t> forLoop; | 222 | ast_ptr<true, CompInner_t> forLoop; |
223 | AST_MEMBER(TblComprehension, &key, &value, &forLoop) | ||
207 | AST_END(TblComprehension) | 224 | AST_END(TblComprehension) |
208 | 225 | ||
209 | AST_NODE(star_exp, "star_exp"_id) | 226 | AST_NODE(star_exp, "star_exp"_id) |
210 | ast_ptr<Exp_t> value; | 227 | ast_ptr<true, Exp_t> value; |
228 | AST_MEMBER(star_exp, &value) | ||
211 | AST_END(star_exp) | 229 | AST_END(star_exp) |
212 | 230 | ||
213 | AST_NODE(CompForEach, "CompForEach"_id) | 231 | AST_NODE(CompForEach, "CompForEach"_id) |
214 | ast_ptr<AssignableNameList_t> nameList; | 232 | ast_ptr<true, AssignableNameList_t> nameList; |
215 | ast_ptr<ast_node> loopValue; // star_exp_t | Exp_t | 233 | ast_sel<true, star_exp_t, Exp_t> loopValue; |
234 | AST_MEMBER(CompForEach, &nameList, &loopValue) | ||
216 | AST_END(CompForEach) | 235 | AST_END(CompForEach) |
217 | 236 | ||
218 | AST_NODE(CompFor, "CompFor"_id) | 237 | AST_NODE(CompFor, "CompFor"_id) |
219 | ast_ptr<Variable_t> varName; | 238 | ast_ptr<true, Variable_t> varName; |
220 | ast_ptr<Exp_t> startValue; | 239 | ast_ptr<true, Exp_t> startValue; |
221 | ast_ptr<Exp_t> stopValue; | 240 | ast_ptr<true, Exp_t> stopValue; |
222 | ast_ptr<for_step_value_t, true> stepValue; | 241 | ast_ptr<false, for_step_value_t> stepValue; |
242 | AST_MEMBER(CompFor, &varName, &startValue, &stopValue, &stepValue) | ||
223 | AST_END(CompFor) | 243 | AST_END(CompFor) |
224 | 244 | ||
225 | AST_NODE(CompInner, "CompInner"_id) | 245 | AST_NODE(CompInner, "CompInner"_id) |
226 | ast_ptr<Seperator_t> sep; | 246 | ast_ptr<true, Seperator_t> sep; |
227 | ast_sel_list<CompFor_t, CompForEach_t, Exp_t> items; | 247 | ast_sel_list<true, CompFor_t, CompForEach_t, Exp_t> items; |
248 | AST_MEMBER(CompInner, &sep, &items) | ||
228 | AST_END(CompInner) | 249 | AST_END(CompInner) |
229 | 250 | ||
230 | class TableBlock_t; | 251 | class TableBlock_t; |
231 | 252 | ||
232 | AST_NODE(Assign, "Assign"_id) | 253 | AST_NODE(Assign, "Assign"_id) |
233 | ast_ptr<Seperator_t> sep; | 254 | ast_ptr<true, Seperator_t> sep; |
234 | ast_sel_list<With_t, If_t, Switch_t, TableBlock_t, Exp_t> values; | 255 | ast_sel_list<true, With_t, If_t, Switch_t, TableBlock_t, Exp_t> values; |
256 | AST_MEMBER(Assign, &sep, &values) | ||
235 | AST_END(Assign) | 257 | AST_END(Assign) |
236 | 258 | ||
237 | AST_LEAF(update_op, "update_op"_id) | 259 | AST_LEAF(update_op, "update_op"_id) |
238 | AST_END(update_op) | 260 | AST_END(update_op) |
239 | 261 | ||
240 | AST_NODE(Update, "Update"_id) | 262 | AST_NODE(Update, "Update"_id) |
241 | ast_ptr<update_op_t> op; | 263 | ast_ptr<true, update_op_t> op; |
242 | ast_ptr<Exp_t> value; | 264 | ast_ptr<true, Exp_t> value; |
265 | AST_MEMBER(Update, &op, &value) | ||
243 | AST_END(Update) | 266 | AST_END(Update) |
244 | 267 | ||
245 | AST_LEAF(BinaryOperator, "BinaryOperator"_id) | 268 | AST_LEAF(BinaryOperator, "BinaryOperator"_id) |
246 | AST_END(BinaryOperator) | 269 | AST_END(BinaryOperator) |
247 | 270 | ||
271 | class AssignableChain_t; | ||
272 | |||
248 | AST_NODE(Assignable, "Assignable"_id) | 273 | AST_NODE(Assignable, "Assignable"_id) |
249 | ast_ptr<ast_node> item; // AssignableChain_t | Variable_t | SelfName_t | 274 | ast_sel<true, AssignableChain_t, Variable_t, SelfName_t> item; |
275 | AST_MEMBER(Assignable, &item) | ||
250 | AST_END(Assignable) | 276 | AST_END(Assignable) |
251 | 277 | ||
252 | class Value_t; | 278 | class Value_t; |
253 | 279 | ||
254 | AST_NODE(exp_op_value, "exp_op_value"_id) | 280 | AST_NODE(exp_op_value, "exp_op_value"_id) |
255 | ast_ptr<BinaryOperator_t> op; | 281 | ast_ptr<true, BinaryOperator_t> op; |
256 | ast_ptr<Value_t> value; | 282 | ast_ptr<true, Value_t> value; |
283 | AST_MEMBER(exp_op_value, &op, &value) | ||
257 | AST_END(exp_op_value) | 284 | AST_END(exp_op_value) |
258 | 285 | ||
259 | AST_NODE(Exp, "Exp"_id) | 286 | AST_NODE(Exp, "Exp"_id) |
260 | ast_ptr<Value_t> value; | 287 | ast_ptr<true, Value_t> value; |
261 | ast_list<exp_op_value_t> opValues; | 288 | ast_list<false, exp_op_value_t> opValues; |
289 | AST_MEMBER(Exp, &value, &opValues) | ||
262 | AST_END(Exp) | 290 | AST_END(Exp) |
263 | 291 | ||
292 | class Parens_t; | ||
293 | |||
264 | AST_NODE(Callable, "Callable"_id) | 294 | AST_NODE(Callable, "Callable"_id) |
265 | ast_ptr<ast_node> item; // Variable_t | SelfName_t | VarArg_t | Parens_t | 295 | ast_sel<true, Variable_t, SelfName_t, VarArg_t, Parens_t> item; |
296 | AST_MEMBER(Callable, &item) | ||
266 | AST_END(Callable) | 297 | AST_END(Callable) |
267 | 298 | ||
268 | AST_NODE(variable_pair, "variable_pair"_id) | 299 | AST_NODE(variable_pair, "variable_pair"_id) |
269 | ast_ptr<Variable_t> name; | 300 | ast_ptr<true, Variable_t> name; |
301 | AST_MEMBER(variable_pair, &name) | ||
270 | AST_END(variable_pair) | 302 | AST_END(variable_pair) |
271 | 303 | ||
304 | class DoubleString_t; | ||
305 | class SingleString_t; | ||
306 | |||
272 | AST_NODE(normal_pair, "normal_pair"_id) | 307 | AST_NODE(normal_pair, "normal_pair"_id) |
273 | ast_ptr<ast_node> key; // KeyName_t | [Exp_t] | DoubleString_t | SingleString_t | 308 | ast_sel<true, KeyName_t, Exp_t, DoubleString_t, SingleString_t> key; |
274 | ast_ptr<ast_node> value; // Exp_t | TableBlock_t | 309 | ast_sel<true, Exp_t, TableBlock_t> value; |
310 | AST_MEMBER(normal_pair, &key, &value) | ||
275 | AST_END(normal_pair) | 311 | AST_END(normal_pair) |
276 | 312 | ||
277 | AST_NODE(simple_table, "simple_table"_id) | 313 | AST_NODE(simple_table, "simple_table"_id) |
278 | ast_ptr<Seperator_t> sep; | 314 | ast_ptr<true, Seperator_t> sep; |
279 | ast_sel_list<variable_pair_t, normal_pair_t> pairs; | 315 | ast_sel_list<true, variable_pair_t, normal_pair_t> pairs; |
316 | AST_MEMBER(simple_table, &sep, &pairs) | ||
280 | AST_END(simple_table) | 317 | AST_END(simple_table) |
281 | 318 | ||
282 | class String_t; | 319 | class String_t; |
320 | class const_value_t; | ||
321 | class ClassDecl_t; | ||
322 | class unary_exp_t; | ||
323 | class TableLit_t; | ||
324 | class FunLit_t; | ||
283 | 325 | ||
284 | AST_NODE(SimpleValue, "SimpleValue"_id) | 326 | AST_NODE(SimpleValue, "SimpleValue"_id) |
285 | ast_ptr<ast_node> value; /* | 327 | ast_sel<true, const_value_t, |
286 | const_value_t | | 328 | If_t, Unless_t, Switch_t, With_t, ClassDecl_t, |
287 | If_t | Unless_t | Switch_t | With_t | ClassDecl_t | ForEach_t | For_t | While_t | Do_t | | 329 | ForEach_t, For_t, While_t, Do_t, unary_exp_t, |
288 | unary_exp_t | | 330 | TblComprehension_t, TableLit_t, Comprehension_t, |
289 | TblComprehension_t | TableLit_t | Comprehension_t | FunLit_t | Num_t; | 331 | FunLit_t, Num_t> value; |
290 | */ | 332 | AST_MEMBER(SimpleValue, &value) |
291 | AST_END(SimpleValue) | 333 | AST_END(SimpleValue) |
292 | 334 | ||
293 | AST_LEAF(LuaStringOpen, "LuaStringOpen"_id) | 335 | AST_LEAF(LuaStringOpen, "LuaStringOpen"_id) |
@@ -300,9 +342,10 @@ AST_LEAF(LuaStringClose, "LuaStringClose"_id) | |||
300 | AST_END(LuaStringClose) | 342 | AST_END(LuaStringClose) |
301 | 343 | ||
302 | AST_NODE(LuaString, "LuaString"_id) | 344 | AST_NODE(LuaString, "LuaString"_id) |
303 | ast_ptr<LuaStringOpen_t> open; | 345 | ast_ptr<true, LuaStringOpen_t> open; |
304 | ast_ptr<LuaStringContent_t> content; | 346 | ast_ptr<true, LuaStringContent_t> content; |
305 | ast_ptr<LuaStringClose_t> close; | 347 | ast_ptr<true, LuaStringClose_t> close; |
348 | AST_MEMBER(LuaString, &open, &content, &close) | ||
306 | AST_END(LuaString) | 349 | AST_END(LuaString) |
307 | 350 | ||
308 | AST_LEAF(SingleString, "SingleString"_id) | 351 | AST_LEAF(SingleString, "SingleString"_id) |
@@ -312,188 +355,227 @@ AST_LEAF(double_string_inner, "double_string_inner"_id) | |||
312 | AST_END(double_string_inner) | 355 | AST_END(double_string_inner) |
313 | 356 | ||
314 | AST_NODE(double_string_content, "double_string_content"_id) | 357 | AST_NODE(double_string_content, "double_string_content"_id) |
315 | ast_ptr<ast_node> content; // double_string_inner_t | Exp_t | 358 | ast_sel<true, double_string_inner_t, Exp_t> content; |
359 | AST_MEMBER(double_string_content, &content) | ||
316 | AST_END(double_string_content) | 360 | AST_END(double_string_content) |
317 | 361 | ||
318 | AST_NODE(DoubleString, "DoubleString"_id) | 362 | AST_NODE(DoubleString, "DoubleString"_id) |
319 | ast_ptr<Seperator_t> sep; | 363 | ast_ptr<true, Seperator_t> sep; |
320 | ast_list<double_string_content_t> segments; | 364 | ast_list<false, double_string_content_t> segments; |
365 | AST_MEMBER(DoubleString, &sep, &segments) | ||
321 | AST_END(DoubleString) | 366 | AST_END(DoubleString) |
322 | 367 | ||
323 | AST_NODE(String, "String"_id) | 368 | AST_NODE(String, "String"_id) |
324 | ast_ptr<ast_node> str; // DoubleString_t | SingleString_t | LuaString_t | 369 | ast_sel<true, DoubleString_t, SingleString_t, LuaString_t> str; |
370 | AST_MEMBER(String, &str) | ||
325 | AST_END(String) | 371 | AST_END(String) |
326 | 372 | ||
327 | AST_NODE(DotChainItem, "DotChainItem"_id) | 373 | AST_NODE(DotChainItem, "DotChainItem"_id) |
328 | ast_ptr<Name_t> name; | 374 | ast_ptr<true, Name_t> name; |
375 | AST_MEMBER(DotChainItem, &name) | ||
329 | AST_END(DotChainItem) | 376 | AST_END(DotChainItem) |
330 | 377 | ||
331 | AST_NODE(ColonChainItem, "ColonChainItem"_id) | 378 | AST_NODE(ColonChainItem, "ColonChainItem"_id) |
332 | ast_ptr<Name_t> name; | 379 | ast_sel<true, LuaKeyword_t, Name_t> name; |
333 | bool switchToDot = false; | 380 | bool switchToDot = false; |
381 | AST_MEMBER(ColonChainItem, &name) | ||
334 | AST_END(ColonChainItem) | 382 | AST_END(ColonChainItem) |
335 | 383 | ||
384 | class default_value_t; | ||
385 | |||
336 | AST_NODE(Slice, "Slice"_id) | 386 | AST_NODE(Slice, "Slice"_id) |
337 | ast_ptr<ast_node> startValue; // Exp_t | default_value_t | 387 | ast_sel<true, Exp_t, default_value_t> startValue; |
338 | ast_ptr<ast_node> stopValue; // Exp_t | default_value_t | 388 | ast_sel<true, Exp_t, default_value_t> stopValue; |
339 | ast_ptr<ast_node> stepValue; // Exp_t | default_value_t | 389 | ast_sel<true, Exp_t, default_value_t> stepValue; |
390 | AST_MEMBER(Slice, &startValue, &stopValue, &stepValue) | ||
340 | AST_END(Slice) | 391 | AST_END(Slice) |
341 | 392 | ||
342 | AST_NODE(Parens, "Parens"_id) | 393 | AST_NODE(Parens, "Parens"_id) |
343 | ast_ptr<Exp_t> expr; | 394 | ast_ptr<true, Exp_t> expr; |
395 | AST_MEMBER(Parens, &expr) | ||
344 | AST_END(Parens) | 396 | AST_END(Parens) |
345 | 397 | ||
346 | AST_NODE(Invoke, "Invoke"_id) | 398 | AST_NODE(Invoke, "Invoke"_id) |
347 | ast_ptr<Seperator_t> sep; | 399 | ast_ptr<true, Seperator_t> sep; |
348 | ast_sel_list<Exp_t, SingleString_t, DoubleString_t, LuaString_t> args; | 400 | ast_sel_list<false, Exp_t, SingleString_t, DoubleString_t, LuaString_t> args; |
401 | AST_MEMBER(Invoke, &sep, &args) | ||
349 | AST_END(Invoke) | 402 | AST_END(Invoke) |
350 | 403 | ||
351 | class InvokeArgs_t; | 404 | class InvokeArgs_t; |
352 | 405 | ||
353 | AST_NODE(ChainValue, "ChainValue"_id) | 406 | AST_NODE(ChainValue, "ChainValue"_id) |
354 | ast_ptr<Seperator_t> sep; | 407 | ast_ptr<true, Seperator_t> sep; |
355 | ast_sel_list<Callable_t, Invoke_t, DotChainItem_t, ColonChainItem_t, Slice_t, Exp_t, String_t, InvokeArgs_t> items; | 408 | ast_sel_list<true, Callable_t, Invoke_t, DotChainItem_t, ColonChainItem_t, Slice_t, Exp_t, String_t, InvokeArgs_t> items; |
409 | AST_MEMBER(ChainValue, &sep, &items) | ||
356 | AST_END(ChainValue) | 410 | AST_END(ChainValue) |
357 | 411 | ||
358 | AST_NODE(AssignableChain, "AssignableChain"_id) | 412 | AST_NODE(AssignableChain, "AssignableChain"_id) |
359 | ast_ptr<Seperator_t> sep; | 413 | ast_ptr<true, Seperator_t> sep; |
360 | ast_sel_list<Callable_t, Invoke_t, DotChainItem_t, ColonChainItem_t, Exp_t, String_t> items; | 414 | ast_sel_list<true, Callable_t, Invoke_t, DotChainItem_t, ColonChainItem_t, Exp_t, String_t> items; |
415 | AST_MEMBER(AssignableChain, &sep, &items) | ||
361 | AST_END(AssignableChain) | 416 | AST_END(AssignableChain) |
362 | 417 | ||
363 | AST_NODE(Value, "Value"_id) | 418 | AST_NODE(Value, "Value"_id) |
364 | ast_ptr<ast_node> item; // SimpleValue_t | simple_table_t | ChainValue_t | String_t | 419 | ast_sel<true, SimpleValue_t, simple_table_t, ChainValue_t, String_t> item; |
420 | AST_MEMBER(Value, &item) | ||
365 | AST_END(Value) | 421 | AST_END(Value) |
366 | 422 | ||
367 | AST_LEAF(default_value, "default_value"_id) | 423 | AST_LEAF(default_value, "default_value"_id) |
368 | AST_END(default_value) | 424 | AST_END(default_value) |
369 | 425 | ||
370 | AST_NODE(TableLit, "TableLit"_id) | 426 | AST_NODE(TableLit, "TableLit"_id) |
371 | ast_ptr<Seperator_t> sep; | 427 | ast_ptr<true, Seperator_t> sep; |
372 | ast_sel_list<variable_pair_t, normal_pair_t, Exp_t> values; | 428 | ast_sel_list<false, variable_pair_t, normal_pair_t, Exp_t> values; |
429 | AST_MEMBER(TableLit, &sep, &values) | ||
373 | AST_END(TableLit) | 430 | AST_END(TableLit) |
374 | 431 | ||
375 | AST_NODE(TableBlock, "TableBlock"_id) | 432 | AST_NODE(TableBlock, "TableBlock"_id) |
376 | ast_ptr<Seperator_t> sep; | 433 | ast_ptr<true, Seperator_t> sep; |
377 | ast_sel_list<variable_pair_t, normal_pair_t> values; | 434 | ast_sel_list<false, variable_pair_t, normal_pair_t> values; |
435 | AST_MEMBER(TableBlock, &sep, &values) | ||
378 | AST_END(TableBlock) | 436 | AST_END(TableBlock) |
379 | 437 | ||
380 | AST_NODE(class_member_list, "class_member_list"_id) | 438 | AST_NODE(class_member_list, "class_member_list"_id) |
381 | ast_ptr<Seperator_t> sep; | 439 | ast_ptr<true, Seperator_t> sep; |
382 | ast_sel_list<variable_pair_t, normal_pair_t> values; | 440 | ast_sel_list<true, variable_pair_t, normal_pair_t> values; |
441 | AST_MEMBER(class_member_list, &sep, &values) | ||
383 | AST_END(class_member_list) | 442 | AST_END(class_member_list) |
384 | 443 | ||
385 | AST_NODE(ClassBlock, "ClassBlock"_id) | 444 | AST_NODE(ClassBlock, "ClassBlock"_id) |
386 | ast_ptr<Seperator_t> sep; | 445 | ast_ptr<true, Seperator_t> sep; |
387 | ast_sel_list<class_member_list_t, Statement_t> contents; | 446 | ast_sel_list<true, class_member_list_t, Statement_t> contents; |
447 | AST_MEMBER(ClassBlock, &sep, &contents) | ||
388 | AST_END(ClassBlock) | 448 | AST_END(ClassBlock) |
389 | 449 | ||
390 | AST_NODE(ClassDecl, "ClassDecl"_id) | 450 | AST_NODE(ClassDecl, "ClassDecl"_id) |
391 | ast_ptr<Assignable_t, true> name; | 451 | ast_ptr<false, Assignable_t> name; |
392 | ast_ptr<Exp_t, true> extend; | 452 | ast_ptr<false, Exp_t> extend; |
393 | ast_ptr<ClassBlock_t, true> body; | 453 | ast_ptr<false, ClassBlock_t> body; |
454 | AST_MEMBER(ClassDecl, &name, &extend, &body) | ||
394 | AST_END(ClassDecl) | 455 | AST_END(ClassDecl) |
395 | 456 | ||
396 | AST_NODE(export_values, "export_values"_id) | 457 | AST_NODE(export_values, "export_values"_id) |
397 | ast_ptr<NameList_t> nameList; | 458 | ast_ptr<true, NameList_t> nameList; |
398 | ast_ptr<ExpListLow_t, true> valueList; | 459 | ast_ptr<false, ExpListLow_t> valueList; |
460 | AST_MEMBER(export_values, &nameList, &valueList) | ||
399 | AST_END(export_values) | 461 | AST_END(export_values) |
400 | 462 | ||
401 | AST_LEAF(export_op, "export_op"_id) | 463 | AST_LEAF(export_op, "export_op"_id) |
402 | AST_END(export_op) | 464 | AST_END(export_op) |
403 | 465 | ||
404 | AST_NODE(Export, "Export"_id) | 466 | AST_NODE(Export, "Export"_id) |
405 | ast_ptr<ast_node> item; // ClassDecl_t | export_op_t | export_values_t | 467 | ast_sel<true, ClassDecl_t, export_op_t, export_values_t> item; |
468 | AST_MEMBER(Export, &item) | ||
406 | AST_END(Export) | 469 | AST_END(Export) |
407 | 470 | ||
408 | AST_NODE(FnArgDef, "FnArgDef"_id) | 471 | AST_NODE(FnArgDef, "FnArgDef"_id) |
409 | ast_ptr<ast_node> name; // Variable_t | SelfName_t | 472 | ast_sel<true, Variable_t, SelfName_t> name; |
410 | ast_ptr<Exp_t, true> defaultValue; | 473 | ast_ptr<false, Exp_t> defaultValue; |
474 | AST_MEMBER(FnArgDef, &name, &defaultValue) | ||
411 | AST_END(FnArgDef) | 475 | AST_END(FnArgDef) |
412 | 476 | ||
413 | AST_NODE(FnArgDefList, "FnArgDefList"_id) | 477 | AST_NODE(FnArgDefList, "FnArgDefList"_id) |
414 | ast_ptr<Seperator_t> sep; | 478 | ast_ptr<true, Seperator_t> sep; |
415 | ast_list<FnArgDef_t> definitions; | 479 | ast_list<false, FnArgDef_t> definitions; |
416 | ast_ptr<VarArg_t, true> varArg; | 480 | ast_ptr<false, VarArg_t> varArg; |
481 | AST_MEMBER(FnArgDefList, &sep, &definitions, &varArg) | ||
417 | AST_END(FnArgDefList) | 482 | AST_END(FnArgDefList) |
418 | 483 | ||
419 | AST_NODE(outer_var_shadow, "outer_var_shadow"_id) | 484 | AST_NODE(outer_var_shadow, "outer_var_shadow"_id) |
420 | ast_ptr<NameList_t, true> varList; | 485 | ast_ptr<false, NameList_t> varList; |
486 | AST_MEMBER(outer_var_shadow, &varList) | ||
421 | AST_END(outer_var_shadow) | 487 | AST_END(outer_var_shadow) |
422 | 488 | ||
423 | AST_NODE(FnArgsDef, "FnArgsDef"_id) | 489 | AST_NODE(FnArgsDef, "FnArgsDef"_id) |
424 | ast_ptr<FnArgDefList_t, true> defList; | 490 | ast_ptr<false, FnArgDefList_t> defList; |
425 | ast_ptr<outer_var_shadow_t, true> shadowOption; | 491 | ast_ptr<false, outer_var_shadow_t> shadowOption; |
492 | AST_MEMBER(FnArgsDef, &defList, &shadowOption) | ||
426 | AST_END(FnArgsDef) | 493 | AST_END(FnArgsDef) |
427 | 494 | ||
428 | AST_LEAF(fn_arrow, "fn_arrow"_id) | 495 | AST_LEAF(fn_arrow, "fn_arrow"_id) |
429 | AST_END(fn_arrow) | 496 | AST_END(fn_arrow) |
430 | 497 | ||
431 | AST_NODE(FunLit, "FunLit"_id) | 498 | AST_NODE(FunLit, "FunLit"_id) |
432 | ast_ptr<FnArgsDef_t, true> argsDef; | 499 | ast_ptr<false, FnArgsDef_t> argsDef; |
433 | ast_ptr<fn_arrow_t> arrow; | 500 | ast_ptr<true, fn_arrow_t> arrow; |
434 | ast_ptr<Body_t, true> body; | 501 | ast_ptr<false, Body_t> body; |
502 | AST_MEMBER(FunLit, &argsDef, &arrow, &body) | ||
435 | AST_END(FunLit) | 503 | AST_END(FunLit) |
436 | 504 | ||
437 | AST_NODE(NameOrDestructure, "NameOrDestructure"_id) | 505 | AST_NODE(NameOrDestructure, "NameOrDestructure"_id) |
438 | ast_ptr<ast_node> item; // Variable_t | TableLit_t | 506 | ast_sel<true, Variable_t, TableLit_t> item; |
507 | AST_MEMBER(NameOrDestructure, &item) | ||
439 | AST_END(NameOrDestructure) | 508 | AST_END(NameOrDestructure) |
440 | 509 | ||
441 | AST_NODE(AssignableNameList, "AssignableNameList"_id) | 510 | AST_NODE(AssignableNameList, "AssignableNameList"_id) |
442 | ast_ptr<Seperator_t> sep; | 511 | ast_ptr<true, Seperator_t> sep; |
443 | ast_list<NameOrDestructure_t> items; | 512 | ast_list<true, NameOrDestructure_t> items; |
513 | AST_MEMBER(AssignableNameList, &sep, &items) | ||
444 | AST_END(AssignableNameList) | 514 | AST_END(AssignableNameList) |
445 | 515 | ||
446 | AST_NODE(InvokeArgs, "InvokeArgs"_id) | 516 | AST_NODE(InvokeArgs, "InvokeArgs"_id) |
447 | ast_ptr<Seperator_t> sep; | 517 | ast_ptr<true, Seperator_t> sep; |
448 | ast_sel_list<Exp_t, TableBlock_t> args; | 518 | ast_sel_list<true, Exp_t, TableBlock_t> args; |
519 | AST_MEMBER(InvokeArgs, &sep, &args) | ||
449 | AST_END(InvokeArgs) | 520 | AST_END(InvokeArgs) |
450 | 521 | ||
451 | AST_LEAF(const_value, "const_value"_id) | 522 | AST_LEAF(const_value, "const_value"_id) |
452 | AST_END(const_value) | 523 | AST_END(const_value) |
453 | 524 | ||
454 | AST_NODE(unary_exp, "unary_exp"_id) | 525 | AST_NODE(unary_exp, "unary_exp"_id) |
455 | ast_ptr<Exp_t> item; | 526 | ast_ptr<true, Exp_t> item; |
527 | AST_MEMBER(unary_exp, &item) | ||
456 | AST_END(unary_exp) | 528 | AST_END(unary_exp) |
457 | 529 | ||
458 | AST_NODE(Assignment, "Assignment"_id) | 530 | AST_NODE(ExpListAssign, "ExpListAssign"_id) |
459 | ast_ptr<ExpList_t> assignable; | 531 | ast_ptr<true, ExpList_t> expList; |
460 | ast_ptr<ast_node> target; // Update_t | Assign_t | 532 | ast_sel<false, Update_t, Assign_t> action; |
461 | AST_END(Assignment) | 533 | AST_MEMBER(ExpListAssign, &expList, &action) |
534 | AST_END(ExpListAssign) | ||
462 | 535 | ||
463 | AST_NODE(if_else_line, "if_else_line"_id) | 536 | AST_NODE(if_else_line, "if_else_line"_id) |
464 | ast_ptr<Exp_t> condition; | 537 | ast_ptr<true, Exp_t> condition; |
465 | ast_ptr<ast_node> elseExpr; // Exp_t | default_value_t | 538 | ast_sel<false, Exp_t, default_value_t> elseExpr; |
539 | AST_MEMBER(if_else_line, &condition, &elseExpr) | ||
466 | AST_END(if_else_line) | 540 | AST_END(if_else_line) |
467 | 541 | ||
468 | AST_NODE(unless_line, "unless_line"_id) | 542 | AST_NODE(unless_line, "unless_line"_id) |
469 | ast_ptr<Exp_t> condition; | 543 | ast_ptr<true, Exp_t> condition; |
544 | AST_MEMBER(unless_line, &condition) | ||
470 | AST_END(unless_line) | 545 | AST_END(unless_line) |
471 | 546 | ||
472 | AST_NODE(statement_appendix, "statement_appendix"_id) | 547 | AST_NODE(statement_appendix, "statement_appendix"_id) |
473 | ast_ptr<ast_node> item; // if_else_line_t | unless_line_t | CompInner_t | 548 | ast_sel<true, if_else_line_t, unless_line_t, CompInner_t> item; |
549 | AST_MEMBER(statement_appendix, &item) | ||
474 | AST_END(statement_appendix) | 550 | AST_END(statement_appendix) |
475 | 551 | ||
476 | AST_LEAF(BreakLoop, "BreakLoop"_id) | 552 | AST_LEAF(BreakLoop, "BreakLoop"_id) |
477 | AST_END(BreakLoop) | 553 | AST_END(BreakLoop) |
478 | 554 | ||
479 | AST_NODE(Statement, "Statement"_id) | 555 | AST_NODE(Statement, "Statement"_id) |
480 | ast_sel<Import_t, While_t, For_t, ForEach_t, | 556 | ast_sel<true, Import_t, While_t, For_t, ForEach_t, |
481 | Return_t, Local_t, Export_t, BreakLoop_t, | 557 | Return_t, Local_t, Export_t, BreakLoop_t, |
482 | Assignment_t, ExpList_t> content; | 558 | ExpListAssign_t> content; |
483 | ast_ptr<statement_appendix_t, true> appendix; | 559 | ast_ptr<false, statement_appendix_t> appendix; |
560 | AST_MEMBER(Statement, &content, &appendix) | ||
484 | AST_END(Statement) | 561 | AST_END(Statement) |
485 | 562 | ||
486 | class Block_t; | 563 | class Block_t; |
487 | 564 | ||
488 | AST_NODE(Body, "Body"_id) | 565 | AST_NODE(Body, "Body"_id) |
489 | ast_ptr<ast_node> content; // Block | Statement | 566 | ast_sel<true, Block_t, Statement_t> content; |
567 | AST_MEMBER(Body, &content) | ||
490 | AST_END(Body) | 568 | AST_END(Body) |
491 | 569 | ||
492 | AST_NODE(Block, "Block"_id) | 570 | AST_NODE(Block, "Block"_id) |
493 | ast_ptr<Seperator_t> sep; | 571 | ast_ptr<true, Seperator_t> sep; |
494 | ast_list<Statement_t> statements; | 572 | ast_list<false, Statement_t> statements; |
573 | AST_MEMBER(Block, &sep, &statements) | ||
495 | AST_END(Block) | 574 | AST_END(Block) |
496 | 575 | ||
497 | AST_NODE(File, "File"_id) | 576 | AST_NODE(File, "File"_id) |
498 | ast_ptr<Block_t> block; | 577 | ast_ptr<true, Block_t> block; |
578 | AST_MEMBER(File, &block) | ||
499 | AST_END(File) | 579 | AST_END(File) |
580 | |||
581 | } // namespace MoonP | ||