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