#pragma once #include "moon_parser.h" input& trim(input& s); class AstLeaf : public ast_node { public: const input& getValue(); private: input _value; }; #define AST_LEAF(type) \ extern rule type; \ class type##_t : public AstLeaf \ { \ public: \ virtual int get_type() override { return ast_type(); } \ virtual const char* getName() const override { return #type; } #define AST_NODE(type) \ extern rule type; \ class type##_t : public ast_container \ { \ public: \ virtual int get_type() override { return ast_type(); } \ virtual const char* getName() const override { return #type; } #define AST_END(type) \ }; AST_LEAF(Num) AST_END(Num) AST_LEAF(_Name) AST_END(_Name) AST_NODE(Name) ast_ptr<_Name_t> name; AST_END(Name) AST_LEAF(self) AST_END(self) AST_NODE(self_name) ast_ptr<_Name_t> name; AST_END(self_name) AST_LEAF(self_class) AST_END(self_class) AST_NODE(self_class_name) ast_ptr<_Name_t> name; AST_END(self_class_name) AST_NODE(SelfName) ast_ptr name; // self_class_name_t | self_class_t | self_name_t | self_t AST_END(SelfName) AST_NODE(KeyName) ast_ptr name; // SelfName_t | _Name_t AST_END(KeyName) AST_LEAF(VarArg) AST_END(VarArg) AST_LEAF(local_flag) AST_END(local_flag) AST_LEAF(Seperator) AST_END(Seperator) AST_NODE(NameList) ast_ptr sep; ast_list names; AST_END(NameList) AST_NODE(Local) ast_ptr name; // local_flag_t | NameList_t AST_END(Local) AST_NODE(colon_import_name) ast_ptr name; AST_END(colon_import_name) class Exp_t; AST_NODE(ImportName) ast_ptr name; // colon_import_name_t | Name_t AST_END(ImportName) AST_NODE(Import) ast_ptr sep; ast_list names; ast_ptr exp; AST_END(Import) AST_NODE(ExpListLow) ast_ptr sep; ast_list exprs; AST_END(ExpListLow) AST_NODE(ExpList) ast_ptr sep; ast_list exprs; AST_END(ExpList) AST_NODE(Return) ast_ptr valueList; AST_END(Return) class Assign_t; class Body_t; AST_NODE(With) ast_ptr valueList; ast_ptr assigns; ast_ptr body; AST_END(With) AST_NODE(SwitchCase) ast_ptr valueList; ast_ptr body; AST_END(SwitchCase) AST_NODE(Switch) ast_ptr target; ast_ptr sep; ast_list branches; ast_ptr lastBranch; AST_END(Switch) AST_NODE(IfCond) ast_ptr condition; ast_ptr assign; AST_END(IfCond) AST_NODE(IfElseIf) ast_ptr condition; ast_ptr body; AST_END(IfElseIf) AST_NODE(If) ast_ptr firstCondition; ast_ptr firstBody; ast_ptr sep; ast_list branches; ast_ptr lastBranch; AST_END(If) AST_NODE(Unless) ast_ptr firstCondition; ast_ptr firstBody; ast_ptr sep; ast_list branches; ast_ptr lastBranch; AST_END(Unless) AST_NODE(While) ast_ptr condition; ast_ptr body; AST_END(While) AST_NODE(for_step_value) ast_ptr value; AST_END(for_step_value) AST_NODE(For) ast_ptr varName; ast_ptr startValue; ast_ptr stopValue; ast_ptr stepValue; ast_ptr body; AST_END(For) class AssignableNameList_t; AST_NODE(ForEach) ast_ptr nameList; ast_ptr loopValue; // Exp_t | ExpList_t ast_ptr body; AST_END(ForEach) AST_NODE(Do) ast_ptr body; AST_END(Do) class CompInner_t; AST_NODE(Comprehension) ast_ptr value; ast_ptr forLoop; AST_END(Comprehension) AST_NODE(comp_value) ast_ptr value; AST_END(comp_value) AST_NODE(TblComprehension) ast_ptr key; ast_ptr value; ast_ptr forLoop; AST_END(TblComprehension) AST_NODE(star_exp) ast_ptr value; AST_END(star_exp) AST_NODE(CompForEach) ast_ptr nameList; ast_ptr loopValue; // star_exp_t | Exp_t AST_END(CompForEach) AST_NODE(CompFor) ast_ptr varName; ast_ptr startValue; ast_ptr stopValue; ast_ptr stepValue; AST_END(CompFor) AST_NODE(CompClause) ast_ptr nestExp; // CompFor_t | CompForEach_t | Exp_t AST_END(CompClause) AST_NODE(CompInner) ast_ptr compFor; // CompFor_t | CompForEach_t ast_ptr sep; ast_list clauses; AST_END(CompInner) class TableBlock_t; AST_NODE(Assign) ast_ptr value; // With_t | If_t | Switch_t | TableBlock_t | ExpListLow_t AST_END(Assign) AST_LEAF(update_op) AST_END(update_op) AST_NODE(Update) ast_ptr op; ast_ptr value; AST_END(Update) AST_LEAF(BinaryOperator) AST_END(BinaryOperator) class Chain_t; AST_NODE(Assignable) ast_ptr item; // Chain_t | Name_t | SelfName_t AST_END(Assignable) class Value_t; AST_NODE(exp_op_value) ast_ptr op; ast_ptr value; AST_END(exp_op_value) AST_NODE(Exp) ast_ptr value; ast_list opValues; AST_END(Exp) AST_NODE(Callable) ast_ptr item; // Name_t | SelfName_t | VarArg_t | Parens_t AST_END(Callable) class InvokeArgs_t; AST_NODE(ChainValue) ast_ptr caller; // Chain_t | Callable_t ast_ptr arguments; AST_END(ChainValue) class KeyValue_t; AST_NODE(simple_table) ast_ptr sep; ast_list pairs; AST_END(simple_table) class String_t; AST_NODE(SimpleValue) ast_ptr value; /* const_value_t | If_t | Unless_t | Switch_t | With_t | ClassDecl_t | ForEach_t | For_t | While_t | Do_t | unary_exp_t | TblComprehension_t | TableLit_t | Comprehension_t | FunLit_t | Num_t; */ AST_END(SimpleValue) AST_NODE(Chain) ast_ptr item; // chain_call_t | chain_item_t | chain_dot_chain_t | ColonChain_t AST_END(Chain) AST_NODE(Value) ast_ptr item; // SimpleValue_t | simple_table_t | ChainValue_t | String_t AST_END(Value) AST_LEAF(LuaString) AST_END(LuaString) AST_LEAF(SingleString) AST_END(SingleString) AST_LEAF(double_string_inner) AST_END(double_string_inner) AST_NODE(double_string_content) ast_ptr content; // double_string_inner_t | Exp_t AST_END(double_string_content) AST_NODE(DoubleString) ast_ptr sep; ast_list segments; AST_END(DoubleString) AST_NODE(String) ast_ptr str; // DoubleString_t | SingleString_t | LuaString_t AST_END(String) AST_NODE(Parens) ast_ptr expr; AST_END(Parens) AST_NODE(FnArgs) ast_ptr sep; ast_list args; AST_END(FnArgs) class ChainItems_t; AST_NODE(chain_call) ast_ptr caller; // Callable_t | String_t ast_ptr chain; AST_END(chain_call) AST_NODE(chain_item) ast_ptr chain; AST_END(chain_item) AST_NODE(DotChainItem) ast_ptr<_Name_t> name; AST_END(DotChainItem) AST_NODE(ColonChainItem) ast_ptr<_Name_t> name; AST_END(ColonChainItem) AST_NODE(chain_dot_chain) ast_ptr caller; ast_ptr chain; AST_END(chain_dot_chain) class ColonChain_t; class Invoke_t; class Slice_t; AST_NODE(ChainItem) ast_ptr item; // Invoke_t | DotChainItem_t | Slice_t | [Exp_t] AST_END(ChainItem) AST_NODE(ChainItems) ast_ptr sep; ast_list simpleChain; ast_ptr colonChain; AST_END(ChainItems) AST_NODE(invoke_chain) ast_ptr invoke; ast_ptr chain; AST_END(invoke_chain) AST_NODE(ColonChain) ast_ptr colonChain; ast_ptr invokeChain; AST_END(ColonChain) AST_LEAF(default_value) AST_END(default_value) AST_NODE(Slice) ast_ptr startValue; // Exp_t | default_value_t ast_ptr stopValue; // Exp_t | default_value_t ast_ptr stepValue; // Exp_t | default_value_t AST_END(Slice) AST_NODE(Invoke) ast_ptr argument; // FnArgs_t | SingleString_t | DoubleString_t | LuaString_t AST_END(Invoke) class KeyValue_t; AST_NODE(TableValue) ast_ptr value; // KeyValue_t | Exp_t AST_END(TableValue) AST_NODE(TableLit) ast_ptr sep; ast_list values; AST_END(TableLit) AST_NODE(TableBlock) ast_ptr sep; ast_list values; AST_END(TableBlock) AST_NODE(class_member_list) ast_ptr sep; ast_list values; AST_END(class_member_list) AST_NODE(ClassLine) ast_ptr content; // class_member_list_t | Statement_t | Exp_t AST_END(ClassLine) AST_NODE(ClassBlock) ast_ptr sep; ast_list lines; AST_END(ClassBlock) AST_NODE(ClassDecl) ast_ptr name; ast_ptr extend; ast_ptr body; AST_END(ClassDecl) AST_NODE(export_values) ast_ptr nameList; ast_ptr valueList; AST_END(export_values) AST_LEAF(export_op) AST_END(export_op) AST_NODE(Export) ast_ptr item; // ClassDecl_t | export_op_t | export_values_t AST_END(Export) AST_NODE(variable_pair) ast_ptr name; AST_END(variable_pair) AST_NODE(normal_pair) ast_ptr key; // KeyName_t | [Exp_t] | DoubleString_t | SingleString_t ast_ptr value; // Exp_t | TableBlock_t AST_END(normal_pair) AST_NODE(KeyValue) ast_ptr item; // variable_pair_t | normal_pair_t AST_END(KeyValue) AST_NODE(FnArgDef) ast_ptr name; // Name_t | SelfName_t ast_ptr defaultValue; AST_END(FnArgDef) AST_NODE(FnArgDefList) ast_ptr sep; ast_list definitions; ast_ptr varArg; AST_END(FnArgDefList) AST_NODE(outer_var_shadow) ast_ptr varList; AST_END(outer_var_shadow) AST_NODE(FnArgsDef) ast_ptr defList; ast_ptr shadowOption; AST_END(FnArgsDef) AST_LEAF(fn_arrow) AST_END(fn_arrow) AST_NODE(FunLit) ast_ptr argsDef; ast_ptr arrow; ast_ptr body; AST_END(FunLit) AST_NODE(NameOrDestructure) ast_ptr item; // Name_t | TableLit_t AST_END(NameOrDestructure) AST_NODE(AssignableNameList) ast_ptr sep; ast_list items; AST_END(AssignableNameList) AST_NODE(ArgBlock) ast_ptr sep; ast_list arguments; AST_END(ArgBlock) AST_NODE(invoke_args_with_table) ast_ptr argBlock; ast_ptr tableBlock; AST_END(invoke_args_with_table) AST_NODE(InvokeArgs) ast_ptr argsList; ast_ptr argsTableBlock; ast_ptr tableBlock; AST_END(InvokeArgs) AST_LEAF(const_value) AST_END(const_value) AST_NODE(unary_exp) ast_ptr item; AST_END(unary_exp) AST_NODE(Assignment) ast_ptr assignable; ast_ptr target; // Update_t | Assign_t AST_END(Assignment) AST_NODE(if_else_line) ast_ptr condition; ast_ptr elseExpr; // Exp_t | default_value_t AST_END(if_else_line) AST_NODE(unless_line) ast_ptr condition; AST_END(unless_line) AST_NODE(statement_appendix) ast_ptr item; // if_else_line_t | unless_line_t | CompInner_t AST_END(statement_appendix) AST_LEAF(BreakLoop) AST_END(BreakLoop) AST_NODE(Statement) ast_ptr content; /* Import_t | While_t | With_t | For_t | ForEach_t | Switch_t | Return_t | Local_t | Export_t | BreakLoop_t | Assignment_t | ExpList_t */ ast_ptr appendix; AST_END(Statement) class Block_t; AST_NODE(Body) ast_ptr content; // Block | Statement AST_END(Body) AST_NODE(Line) ast_ptr statment; AST_END(Line) AST_NODE(Block) ast_ptr sep; ast_list lines; AST_END(Block) AST_NODE(BlockEnd) ast_ptr block; AST_END(BlockEnd)