From ee9f984341a3e5b52ae97573d97e20cde57ada94 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Thu, 19 Jan 2023 15:29:34 +0800 Subject: make syntax rule names consistent. --- src/yuescript/yue_ast.h | 402 ++++++++++++------------ src/yuescript/yue_compiler.cpp | 504 +++++++++++++++--------------- src/yuescript/yue_parser.cpp | 684 ++++++++++++++++++++++------------------- src/yuescript/yue_parser.h | 220 ++++++------- 4 files changed, 924 insertions(+), 886 deletions(-) diff --git a/src/yuescript/yue_ast.h b/src/yuescript/yue_ast.h index 076d5f4..9101b2f 100644 --- a/src/yuescript/yue_ast.h +++ b/src/yuescript/yue_ast.h @@ -60,37 +60,37 @@ AST_NODE(LuaKeyword) AST_MEMBER(LuaKeyword, &name) AST_END(LuaKeyword, "lua_keyword"sv) -AST_LEAF(self) -AST_END(self, "self"sv) +AST_LEAF(Self) +AST_END(Self, "self"sv) -AST_NODE(self_name) +AST_NODE(SelfName) ast_ptr name; - AST_MEMBER(self_name, &name) -AST_END(self_name, "self_name"sv) + AST_MEMBER(SelfName, &name) +AST_END(SelfName, "self_name"sv) -AST_LEAF(self_class) -AST_END(self_class, "self_name"sv) +AST_LEAF(SelfClass) +AST_END(SelfClass, "self_class"sv) -AST_NODE(self_class_name) +AST_NODE(SelfClassName) ast_ptr name; - AST_MEMBER(self_class_name, &name) -AST_END(self_class_name, "self_class_name"sv) + AST_MEMBER(SelfClassName, &name) +AST_END(SelfClassName, "self_class_name"sv) -AST_NODE(SelfName) - ast_sel name; - AST_MEMBER(SelfName, &name) -AST_END(SelfName, "self_item"sv) +AST_NODE(SelfItem) + ast_sel name; + AST_MEMBER(SelfItem, &name) +AST_END(SelfItem, "self_item"sv) AST_NODE(KeyName) - ast_sel name; + ast_sel name; AST_MEMBER(KeyName, &name) AST_END(KeyName, "key_name"sv) AST_LEAF(VarArg) AST_END(VarArg, "var_arg"sv) -AST_LEAF(local_flag) -AST_END(local_flag, "local_flag"sv) +AST_LEAF(LocalFlag) +AST_END(LocalFlag, "local_flag"sv) AST_LEAF(Seperator) AST_END(Seperator, "seperator"sv) @@ -105,14 +105,14 @@ class ExpListLow_t; class TableBlock_t; class Attrib_t; -AST_NODE(local_values) +AST_NODE(LocalValues) ast_ptr nameList; ast_sel valueList; - AST_MEMBER(local_values, &nameList, &valueList) -AST_END(local_values, "local_values"sv) + AST_MEMBER(LocalValues, &nameList, &valueList) +AST_END(LocalValues, "local_values"sv) AST_NODE(Local) - ast_sel item; + ast_sel item; std::list forceDecls; std::list decls; bool collected = false; @@ -120,35 +120,35 @@ AST_NODE(Local) AST_MEMBER(Local, &item) AST_END(Local, "local"sv) -AST_LEAF(const_attrib) -AST_END(const_attrib, "const"sv) +AST_LEAF(ConstAttrib) +AST_END(ConstAttrib, "const"sv) -AST_LEAF(close_attrib) -AST_END(close_attrib, "close"sv) +AST_LEAF(CloseAttrib) +AST_END(CloseAttrib, "close"sv) -class simple_table_t; +class SimpleTable_t; class TableLit_t; class Assign_t; AST_NODE(LocalAttrib) - ast_sel attrib; + ast_sel attrib; ast_ptr sep; - ast_sel_list leftList; + ast_sel_list leftList; ast_ptr assign; AST_MEMBER(LocalAttrib, &attrib, &sep, &leftList, &assign) AST_END(LocalAttrib, "local_attrib"sv) -AST_NODE(colon_import_name) +AST_NODE(ColonImportName) ast_ptr name; - AST_MEMBER(colon_import_name, &name) -AST_END(colon_import_name, "colon_import_name"sv) + AST_MEMBER(ColonImportName, &name) +AST_END(ColonImportName, "colon_import_name"sv) -AST_LEAF(import_literal_inner) -AST_END(import_literal_inner, "import_literal_inner"sv) +AST_LEAF(ImportLiteralInner) +AST_END(ImportLiteralInner, "import_literal_inner"sv) AST_NODE(ImportLiteral) ast_ptr sep; - ast_sel_list inners; + ast_sel_list inners; AST_MEMBER(ImportLiteral, &sep, &inners) AST_END(ImportLiteral, "import_literal"sv) @@ -156,36 +156,36 @@ class Exp_t; AST_NODE(ImportFrom) ast_ptr sep; - ast_sel_list names; + ast_sel_list names; ast_ptr exp; AST_MEMBER(ImportFrom, &sep, &names, &exp) AST_END(ImportFrom, "import_from"sv) class MacroName_t; -AST_NODE(macro_name_pair) +AST_NODE(MacroNamePair) ast_ptr key; ast_ptr value; - AST_MEMBER(macro_name_pair, &key, &value) -AST_END(macro_name_pair, "macro_name_pair"sv) + AST_MEMBER(MacroNamePair, &key, &value) +AST_END(MacroNamePair, "macro_name_pair"sv) -AST_LEAF(import_all_macro) -AST_END(import_all_macro, "import_all_macro"sv) +AST_LEAF(ImportAllMacro) +AST_END(ImportAllMacro, "import_all_macro"sv) -class variable_pair_t; -class normal_pair_t; -class meta_variable_pair_t; -class meta_normal_pair_t; +class VariablePair_t; +class NormalPair_t; +class MetaVariablePair_t; +class MetaNormalPair_t; AST_NODE(ImportTabLit) ast_ptr sep; - ast_sel_list items; + ast_sel_list items; AST_MEMBER(ImportTabLit, &sep, &items) AST_END(ImportTabLit, "import_tab_lit"sv) AST_NODE(ImportAs) ast_ptr literal; - ast_sel target; + ast_sel target; AST_MEMBER(ImportAs, &literal, &target) AST_END(ImportAs, "import_as"sv) @@ -211,14 +211,14 @@ AST_END(ShortTabAppending, "short_table_appending"sv) class FnArgsDef_t; -AST_LEAF(fn_arrow_back) -AST_END(fn_arrow_back, "fn_arrow_back"sv) +AST_LEAF(FnArrowBack) +AST_END(FnArrowBack, "fn_arrow_back"sv) class ChainValue_t; AST_NODE(Backcall) ast_ptr argsDef; - ast_ptr arrow; + ast_ptr arrow; ast_ptr value; AST_MEMBER(Backcall, &argsDef, &arrow, &value) AST_END(Backcall, "backcall"sv) @@ -243,13 +243,13 @@ AST_NODE(Return) AST_MEMBER(Return, &valueList) AST_END(Return, "return"sv) -class existential_op_t; +class ExistentialOp_t; class Assign_t; class Block_t; class Statement_t; AST_NODE(With) - ast_ptr eop; + ast_ptr eop; ast_ptr valueList; ast_ptr assigns; ast_sel body; @@ -276,14 +276,14 @@ AST_NODE(Switch) AST_MEMBER(Switch, &target, &sep, &branches, &lastBranch) AST_END(Switch, "switch"sv) -AST_NODE(assignment) +AST_NODE(Assignment) ast_ptr expList; ast_ptr assign; - AST_MEMBER(assignment, &expList, &assign) -AST_END(assignment, "assignment"sv) + AST_MEMBER(Assignment, &expList, &assign) +AST_END(Assignment, "assignment"sv) AST_NODE(IfCond) - ast_sel condition; + ast_sel condition; AST_MEMBER(IfCond, &condition) AST_END(IfCond, "if_cond"sv) @@ -314,26 +314,26 @@ AST_NODE(Repeat) AST_MEMBER(Repeat, &body, &condition) AST_END(Repeat, "repeat"sv) -AST_NODE(for_step_value) +AST_NODE(ForStepValue) ast_ptr value; - AST_MEMBER(for_step_value, &value) -AST_END(for_step_value, "for_step_value"sv) + AST_MEMBER(ForStepValue, &value) +AST_END(ForStepValue, "for_step_value"sv) AST_NODE(For) ast_ptr varName; ast_ptr startValue; ast_ptr stopValue; - ast_ptr stepValue; + ast_ptr stepValue; ast_sel body; AST_MEMBER(For, &varName, &startValue, &stopValue, &stepValue, &body) AST_END(For, "for"sv) class AssignableNameList_t; -class star_exp_t; +class StarExp_t; AST_NODE(ForEach) ast_ptr nameList; - ast_sel loopValue; + ast_sel loopValue; ast_sel body; AST_MEMBER(ForEach, &nameList, &loopValue, &body) AST_END(ForEach, "for_each"sv) @@ -343,15 +343,15 @@ AST_NODE(Do) AST_MEMBER(Do, &body) AST_END(Do, "do"sv) -AST_NODE(catch_block) +AST_NODE(CatchBlock) ast_ptr err; ast_ptr body; - AST_MEMBER(catch_block, &err, &body) -AST_END(catch_block, "catch_block"sv) + AST_MEMBER(CatchBlock, &err, &body) +AST_END(CatchBlock, "catch_block"sv) AST_NODE(Try) ast_sel func; - ast_ptr catchBlock; + ast_ptr catchBlock; AST_MEMBER(Try, &func, &catchBlock) AST_END(Try, "try"sv) @@ -363,26 +363,26 @@ AST_NODE(Comprehension) AST_MEMBER(Comprehension, &value, &forLoop) AST_END(Comprehension, "comp"sv) -AST_NODE(comp_value) +AST_NODE(CompValue) ast_ptr value; - AST_MEMBER(comp_value, &value) -AST_END(comp_value, "comp_value"sv) + AST_MEMBER(CompValue, &value) +AST_END(CompValue, "comp_value"sv) AST_NODE(TblComprehension) ast_ptr key; - ast_ptr value; + ast_ptr value; ast_ptr forLoop; AST_MEMBER(TblComprehension, &key, &value, &forLoop) AST_END(TblComprehension, "tbl_comp"sv) -AST_NODE(star_exp) +AST_NODE(StarExp) ast_ptr value; - AST_MEMBER(star_exp, &value) -AST_END(star_exp, "star_exp"sv) + AST_MEMBER(StarExp, &value) +AST_END(StarExp, "star_exp"sv) AST_NODE(CompForEach) ast_ptr nameList; - ast_sel loopValue; + ast_sel loopValue; AST_MEMBER(CompForEach, &nameList, &loopValue) AST_END(CompForEach, "comp_for_each"sv) @@ -390,7 +390,7 @@ AST_NODE(CompFor) ast_ptr varName; ast_ptr startValue; ast_ptr stopValue; - ast_ptr stepValue; + ast_ptr stepValue; AST_MEMBER(CompFor, &varName, &startValue, &stopValue, &stepValue) AST_END(CompFor, "comp_for"sv) @@ -408,11 +408,11 @@ AST_NODE(Assign) AST_MEMBER(Assign, &sep, &values) AST_END(Assign, "assign"sv) -AST_LEAF(update_op) -AST_END(update_op, "update_op"sv) +AST_LEAF(UpdateOp) +AST_END(UpdateOp, "update_op"sv) AST_NODE(Update) - ast_ptr op; + ast_ptr op; ast_ptr value; AST_MEMBER(Update, &op, &value) AST_END(Update, "update"sv) @@ -420,28 +420,28 @@ AST_END(Update, "update"sv) AST_LEAF(BinaryOperator) AST_END(BinaryOperator, "binary_op"sv) -AST_LEAF(unary_operator) -AST_END(unary_operator, "unary_op"sv) +AST_LEAF(UnaryOperator) +AST_END(UnaryOperator, "unary_op"sv) class AssignableChain_t; AST_NODE(Assignable) - ast_sel item; + ast_sel item; AST_MEMBER(Assignable, &item) AST_END(Assignable, "assignable"sv) -class unary_exp_t; +class UnaryExp_t; -AST_NODE(exp_op_value) +AST_NODE(ExpOpValue) ast_ptr op; - ast_list pipeExprs; - AST_MEMBER(exp_op_value, &op, &pipeExprs) -AST_END(exp_op_value, "exp_op_value"sv) + ast_list pipeExprs; + AST_MEMBER(ExpOpValue, &op, &pipeExprs) +AST_END(ExpOpValue, "exp_op_value"sv) AST_NODE(Exp) ast_ptr sep; - ast_list pipeExprs; - ast_list opValues; + ast_list pipeExprs; + ast_list opValues; ast_ptr nilCoalesed; AST_MEMBER(Exp, &sep, &pipeExprs, &opValues, &nilCoalesed) AST_END(Exp, "exp"sv) @@ -450,82 +450,82 @@ class Parens_t; class MacroName_t; AST_NODE(Callable) - ast_sel item; + ast_sel item; AST_MEMBER(Callable, &item) AST_END(Callable, "callable"sv) -AST_NODE(variable_pair) +AST_NODE(VariablePair) ast_ptr name; - AST_MEMBER(variable_pair, &name) -AST_END(variable_pair, "variable_pair"sv) + AST_MEMBER(VariablePair, &name) +AST_END(VariablePair, "variable_pair"sv) -AST_NODE(variable_pair_def) - ast_ptr pair; +AST_NODE(VariablePairDef) + ast_ptr pair; ast_ptr defVal; - AST_MEMBER(variable_pair_def, &pair, &defVal) -AST_END(variable_pair_def, "variable_pair_def"sv) + AST_MEMBER(VariablePairDef, &pair, &defVal) +AST_END(VariablePairDef, "variable_pair_def"sv) class String_t; -AST_NODE(normal_pair) +AST_NODE(NormalPair) ast_sel key; ast_sel value; - AST_MEMBER(normal_pair, &key, &value) -AST_END(normal_pair, "normal_pair"sv) + AST_MEMBER(NormalPair, &key, &value) +AST_END(NormalPair, "normal_pair"sv) -AST_NODE(normal_pair_def) - ast_ptr pair; +AST_NODE(NormalPairDef) + ast_ptr pair; ast_ptr defVal; - AST_MEMBER(normal_pair_def, &pair, &defVal) -AST_END(normal_pair_def, "normal_pair_def"sv) + AST_MEMBER(NormalPairDef, &pair, &defVal) +AST_END(NormalPairDef, "normal_pair_def"sv) -AST_NODE(normal_def) +AST_NODE(NormalDef) ast_ptr item; ast_ptr sep; ast_ptr defVal; - AST_MEMBER(normal_def, &item, &sep, &defVal) -AST_END(normal_def, "normal_def") + AST_MEMBER(NormalDef, &item, &sep, &defVal) +AST_END(NormalDef, "normal_def") -AST_NODE(meta_variable_pair) +AST_NODE(MetaVariablePair) ast_ptr name; - AST_MEMBER(meta_variable_pair, &name) -AST_END(meta_variable_pair, "meta_variable_pair"sv) + AST_MEMBER(MetaVariablePair, &name) +AST_END(MetaVariablePair, "meta_variable_pair"sv) -AST_NODE(meta_variable_pair_def) - ast_ptr pair; +AST_NODE(MetaVariablePairDef) + ast_ptr pair; ast_ptr defVal; - AST_MEMBER(meta_variable_pair_def, &pair, &defVal) -AST_END(meta_variable_pair_def, "meta_variable_pair_def"sv) + AST_MEMBER(MetaVariablePairDef, &pair, &defVal) +AST_END(MetaVariablePairDef, "meta_variable_pair_def"sv) -AST_NODE(meta_normal_pair) +AST_NODE(MetaNormalPair) ast_sel key; ast_sel value; - AST_MEMBER(meta_normal_pair, &key, &value) -AST_END(meta_normal_pair, "meta_normal_pair"sv) + AST_MEMBER(MetaNormalPair, &key, &value) +AST_END(MetaNormalPair, "meta_normal_pair"sv) -AST_NODE(meta_normal_pair_def) - ast_ptr pair; +AST_NODE(MetaNormalPairDef) + ast_ptr pair; ast_ptr defVal; - AST_MEMBER(meta_normal_pair_def, &pair, &defVal) -AST_END(meta_normal_pair_def, "meta_normal_pair_def"sv) + AST_MEMBER(MetaNormalPairDef, &pair, &defVal) +AST_END(MetaNormalPairDef, "meta_normal_pair_def"sv) -AST_NODE(simple_table) +AST_NODE(SimpleTable) ast_ptr sep; - ast_sel_list pairs; - AST_MEMBER(simple_table, &sep, &pairs) -AST_END(simple_table, "simple_table"sv) + ast_sel_list pairs; + AST_MEMBER(SimpleTable, &sep, &pairs) +AST_END(SimpleTable, "simple_table"sv) -class const_value_t; +class ConstValue_t; class ClassDecl_t; -class unary_value_t; +class UnaryValue_t; class FunLit_t; AST_NODE(SimpleValue) ast_sel value; AST_MEMBER(SimpleValue, &value) @@ -550,17 +550,17 @@ AST_END(LuaString, "lua_string"sv) AST_LEAF(SingleString) AST_END(SingleString, "single_string"sv) -AST_LEAF(double_string_inner) -AST_END(double_string_inner, "double_string_inner"sv) +AST_LEAF(DoubleStringInner) +AST_END(DoubleStringInner, "double_string_inner"sv) -AST_NODE(double_string_content) - ast_sel content; - AST_MEMBER(double_string_content, &content) -AST_END(double_string_content, "double_string_content"sv) +AST_NODE(DoubleStringContent) + ast_sel content; + AST_MEMBER(DoubleStringContent, &content) +AST_END(DoubleStringContent, "double_string_content"sv) AST_NODE(DoubleString) ast_ptr sep; - ast_list segments; + ast_list segments; AST_MEMBER(DoubleString, &sep, &segments) AST_END(DoubleString, "double_string"sv) @@ -588,12 +588,12 @@ AST_NODE(ColonChainItem) AST_MEMBER(ColonChainItem, &name) AST_END(ColonChainItem, "colon_chain_item"sv) -class default_value_t; +class DefaultValue_t; AST_NODE(Slice) - ast_sel startValue; - ast_sel stopValue; - ast_sel stepValue; + ast_sel startValue; + ast_sel stopValue; + ast_sel stepValue; AST_MEMBER(Slice, &startValue, &stopValue, &stepValue) AST_END(Slice, "slice"sv) @@ -608,17 +608,17 @@ AST_NODE(Invoke) AST_MEMBER(Invoke, &sep, &args) AST_END(Invoke, "invoke"sv) -AST_LEAF(existential_op) -AST_END(existential_op, "existential_op"sv) +AST_LEAF(ExistentialOp) +AST_END(ExistentialOp, "existential_op"sv) -AST_LEAF(table_appending_op) -AST_END(table_appending_op, "table_appending_op"sv) +AST_LEAF(TableAppendingOp) +AST_END(TableAppendingOp, "table_appending_op"sv) class InvokeArgs_t; AST_NODE(ChainValue) ast_ptr sep; - ast_sel_list items; + ast_sel_list items; AST_MEMBER(ChainValue, &sep, &items) AST_END(ChainValue, "chain_value"sv) @@ -629,12 +629,12 @@ AST_NODE(AssignableChain) AST_END(AssignableChain, "assignable_chain"sv) AST_NODE(Value) - ast_sel item; + ast_sel item; AST_MEMBER(Value, &item) AST_END(Value, "value"sv) -AST_LEAF(default_value) -AST_END(default_value, "default_value"sv) +AST_LEAF(DefaultValue) +AST_END(DefaultValue, "default_value"sv) AST_NODE(SpreadExp) ast_ptr exp; @@ -646,36 +646,36 @@ class TableBlockIndent_t; AST_NODE(TableLit) ast_ptr sep; ast_sel_list values; + VariablePairDef_t, NormalPairDef_t, SpreadExp_t, NormalDef_t, + MetaVariablePairDef_t, MetaNormalPairDef_t, + VariablePair_t, NormalPair_t, Exp_t, TableBlockIndent_t, + MetaVariablePair_t, MetaNormalPair_t> values; AST_MEMBER(TableLit, &sep, &values) AST_END(TableLit, "table_lit"sv) AST_NODE(TableBlockIndent) ast_ptr sep; ast_sel_list values; + VariablePair_t, NormalPair_t, Exp_t, TableBlockIndent_t, + MetaVariablePair_t, MetaNormalPair_t> values; AST_MEMBER(TableBlockIndent, &sep, &values) AST_END(TableBlockIndent, "table_block_indent"sv) AST_NODE(TableBlock) ast_ptr sep; - ast_sel_list values; + ast_sel_list values; AST_MEMBER(TableBlock, &sep, &values) AST_END(TableBlock, "table_block"sv) -AST_NODE(class_member_list) +AST_NODE(ClassMemberList) ast_ptr sep; - ast_sel_list values; - AST_MEMBER(class_member_list, &sep, &values) -AST_END(class_member_list, "class_member_list"sv) + ast_sel_list values; + AST_MEMBER(ClassMemberList, &sep, &values) +AST_END(ClassMemberList, "class_member_list"sv) AST_NODE(ClassBlock) ast_ptr sep; - ast_sel_list contents; + ast_sel_list contents; AST_MEMBER(ClassBlock, &sep, &contents) AST_END(ClassBlock, "class_block"sv) @@ -687,35 +687,35 @@ AST_NODE(ClassDecl) AST_MEMBER(ClassDecl, &name, &extend, &mixes, &body) AST_END(ClassDecl, "class_decl"sv) -AST_NODE(global_values) +AST_NODE(GlobalValues) ast_ptr nameList; ast_sel valueList; - AST_MEMBER(global_values, &nameList, &valueList) -AST_END(global_values, "global_values"sv) + AST_MEMBER(GlobalValues, &nameList, &valueList) +AST_END(GlobalValues, "global_values"sv) -AST_LEAF(global_op) -AST_END(global_op, "global_op"sv) +AST_LEAF(GlobalOp) +AST_END(GlobalOp, "global_op"sv) AST_NODE(Global) - ast_sel item; + ast_sel item; AST_MEMBER(Global, &item) AST_END(Global, "global"sv) -AST_LEAF(export_default) -AST_END(export_default, "export_default"sv) +AST_LEAF(ExportDefault) +AST_END(ExportDefault, "export_default"sv) class Macro_t; AST_NODE(Export) - ast_ptr def; + ast_ptr def; ast_sel target; ast_ptr assign; AST_MEMBER(Export, &def, &target, &assign) AST_END(Export, "export"sv) AST_NODE(FnArgDef) - ast_sel name; - ast_ptr op; + ast_sel name; + ast_ptr op; ast_ptr defaultValue; AST_MEMBER(FnArgDef, &name, &op, &defaultValue) AST_END(FnArgDef, "fn_arg_def"sv) @@ -727,23 +727,23 @@ AST_NODE(FnArgDefList) AST_MEMBER(FnArgDefList, &sep, &definitions, &varArg) AST_END(FnArgDefList, "fn_arg_def_list"sv) -AST_NODE(outer_var_shadow) +AST_NODE(OuterVarShadow) ast_ptr varList; - AST_MEMBER(outer_var_shadow, &varList) -AST_END(outer_var_shadow, "outer_var_shadow"sv) + AST_MEMBER(OuterVarShadow, &varList) +AST_END(OuterVarShadow, "outer_var_shadow"sv) AST_NODE(FnArgsDef) ast_ptr defList; - ast_ptr shadowOption; + ast_ptr shadowOption; AST_MEMBER(FnArgsDef, &defList, &shadowOption) AST_END(FnArgsDef, "fn_args_def"sv) -AST_LEAF(fn_arrow) -AST_END(fn_arrow, "fn_arrow"sv) +AST_LEAF(FnArrow) +AST_END(FnArrow, "fn_arrow"sv) AST_NODE(FunLit) ast_ptr argsDef; - ast_ptr arrow; + ast_ptr arrow; ast_ptr body; AST_MEMBER(FunLit, &argsDef, &arrow, &body) AST_END(FunLit, "fun_lit"sv) @@ -787,20 +787,20 @@ AST_NODE(InvokeArgs) AST_MEMBER(InvokeArgs, &sep, &args) AST_END(InvokeArgs, "invoke_args"sv) -AST_LEAF(const_value) -AST_END(const_value, "const_value"sv) +AST_LEAF(ConstValue) +AST_END(ConstValue, "const_value"sv) -AST_NODE(unary_value) - ast_list ops; +AST_NODE(UnaryValue) + ast_list ops; ast_ptr value; - AST_MEMBER(unary_value, &ops, &value) -AST_END(unary_value, "unary_value"sv) + AST_MEMBER(UnaryValue, &ops, &value) +AST_END(UnaryValue, "unary_value"sv) -AST_NODE(unary_exp) - ast_list ops; +AST_NODE(UnaryExp) + ast_list ops; ast_list expos; - AST_MEMBER(unary_exp, &ops, &expos) -AST_END(unary_exp, "unary_exp"sv) + AST_MEMBER(UnaryExp, &ops, &expos) +AST_END(UnaryExp, "unary_exp"sv) AST_NODE(ExpListAssign) ast_ptr expList; @@ -808,34 +808,34 @@ AST_NODE(ExpListAssign) AST_MEMBER(ExpListAssign, &expList, &action) AST_END(ExpListAssign, "exp_list_assign"sv) -AST_NODE(if_line) +AST_NODE(IfLine) ast_ptr type; ast_ptr condition; - AST_MEMBER(if_line, &type, &condition) -AST_END(if_line, "if_line"sv) + AST_MEMBER(IfLine, &type, &condition) +AST_END(IfLine, "if_line"sv) -AST_NODE(while_line) +AST_NODE(WhileLine) ast_ptr type; ast_ptr condition; - AST_MEMBER(while_line, &type, &condition) -AST_END(while_line, "while_line"sv) + AST_MEMBER(WhileLine, &type, &condition) +AST_END(WhileLine, "while_line"sv) AST_LEAF(BreakLoop) AST_END(BreakLoop, "break_loop"sv) AST_NODE(PipeBody) ast_ptr sep; - ast_list values; + ast_list values; AST_MEMBER(PipeBody, &sep, &values) AST_END(PipeBody, "pipe_body"sv) -AST_NODE(statement_appendix) - ast_sel item; - AST_MEMBER(statement_appendix, &item) -AST_END(statement_appendix, "statement_appendix"sv) +AST_NODE(StatementAppendix) + ast_sel item; + AST_MEMBER(StatementAppendix, &item) +AST_END(StatementAppendix, "statement_appendix"sv) -AST_LEAF(statement_sep) -AST_END(statement_sep, "statement_sep"sv) +AST_LEAF(StatementSep) +AST_END(StatementSep, "statement_sep"sv) AST_LEAF(YueLineComment) AST_END(YueLineComment, "comment"sv) @@ -859,8 +859,8 @@ AST_NODE(Statement) BreakLoop_t, Label_t, Goto_t, ShortTabAppending_t, Backcall_t, LocalAttrib_t, PipeBody_t, ExpListAssign_t, ChainAssign_t > content; - ast_ptr appendix; - ast_ptr needSep; + ast_ptr appendix; + ast_ptr needSep; AST_MEMBER(Statement, &sep, &comments, &content, &appendix, &needSep) AST_END(Statement, "statement"sv) diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index b47da6c..6fd43d0 100644 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp @@ -141,15 +141,15 @@ public: case id(): if (auto importNode = stmt->content.as()) { if (auto importAs = importNode->content.as()) { - if (importAs->target.is()) { + if (importAs->target.is()) { break; } else if (auto tab = importAs->target.as()) { bool macroImportingOnly = true; for (auto item : tab->items.objects()) { if (!ast_is< MacroName_t, - macro_name_pair_t, - import_all_macro_t>(item)) { + MacroNamePair_t, + ImportAllMacro_t>(item)) { macroImportingOnly = false; } } @@ -653,7 +653,7 @@ private: return result; } - unary_exp_t* singleUnaryExpFrom(ast_node* item) const { + UnaryExp_t* singleUnaryExpFrom(ast_node* item) const { Exp_t* exp = nullptr; switch (item->getId()) { case id(): @@ -680,8 +680,8 @@ private: } break; } - case id(): { - auto unary = static_cast(item); + case id(): { + auto unary = static_cast(item); if (unary->expos.size() == 1) { return unary; } @@ -694,7 +694,7 @@ private: BREAK_IF(exp->nilCoalesed); BREAK_IF(!exp->opValues.empty()); BREAK_IF(exp->pipeExprs.size() != 1); - auto unary = static_cast(exp->pipeExprs.back()); + auto unary = static_cast(exp->pipeExprs.back()); BREAK_IF(unary->expos.size() != 1); return unary; BLOCK_END @@ -729,7 +729,7 @@ private: } ast_ptr newExp(Value_t* value, ast_node* x) { - auto unary = x->new_ptr(); + auto unary = x->new_ptr(); unary->expos.push_back(value); auto exp = x->new_ptr(); exp->pipeExprs.push_back(unary); @@ -737,11 +737,11 @@ private: } ast_ptr newExp(Value_t* left, BinaryOperator_t* op, Value_t* right, ast_node* x) { - auto lunary = x->new_ptr(); + auto lunary = x->new_ptr(); lunary->expos.push_back(left); - auto opValue = x->new_ptr(); + auto opValue = x->new_ptr(); { - auto runary = x->new_ptr(); + auto runary = x->new_ptr(); runary->expos.push_back(right); opValue->op.set(op); opValue->pipeExprs.push_back(runary); @@ -752,7 +752,7 @@ private: return exp; } - ast_ptr newExp(unary_exp_t* unary, ast_node* x) { + ast_ptr newExp(UnaryExp_t* unary, ast_node* x) { auto exp = x->new_ptr(); exp->pipeExprs.push_back(unary); return exp; @@ -842,7 +842,7 @@ private: return nullptr; } case id(): { - if (auto localValues = static_cast(stmt->content.get())->item.as()) { + if (auto localValues = static_cast(stmt->content.get())->item.as()) { if (auto expList = localValues->valueList.as()) { return static_cast(expList->exprs.back()); } @@ -850,7 +850,7 @@ private: return nullptr; } case id(): { - if (auto globalValues = static_cast(stmt->content.get())->item.as()) { + if (auto globalValues = static_cast(stmt->content.get())->item.as()) { if (auto expList = globalValues->valueList.as()) { return static_cast(expList->exprs.back()); } @@ -897,7 +897,7 @@ private: if (ast_is(chainValue->items.back())) { return ChainType::EndWithColon; } - if (ast_is(chainValue->items.back())) { + if (ast_is(chainValue->items.back())) { return ChainType::EndWithEOP; } if (auto dot = ast_cast(chainValue->items.back())) { @@ -913,7 +913,7 @@ private: } else if (auto meta = colonChain->name.as(); meta && !meta->item.is()) { return ChainType::MetaFieldInvocation; } - } else if (ast_is(item)) { + } else if (ast_is(item)) { return ChainType::HasEOP; } } @@ -928,8 +928,8 @@ private: BREAK_IF(!callable); ast_node* var = callable->item.as(); if (!var) { - if (auto self = callable->item.as()) { - var = self->name.as(); + if (auto self = callable->item.as()) { + var = self->name.as(); } } BREAK_IF(!var); @@ -949,7 +949,7 @@ private: BREAK_IF(!chainValue); BREAK_IF(chainValue->items.size() != 1); auto callable = ast_cast(chainValue->items.front()); - BREAK_IF(!callable || !(callable->item.is() || callable->getByPath())); + BREAK_IF(!callable || !(callable->item.is() || callable->getByPath())); str_list tmp; if (accessing) { transformCallable(callable, tmp); @@ -986,7 +986,7 @@ private: case id(): checkConst(_parser.toString(callable->item.get()), callable->item.get()); return true; - case id(): + case id(): return true; } } else @@ -997,7 +997,7 @@ private: } } else { if (std::find_if(chainItems.begin(), chainItems.end(), [](ast_node* node) { - return ast_is(node); + return ast_is(node); }) != chainItems.end()) { return false; @@ -1006,7 +1006,7 @@ private: switch (lastItem->getId()) { case id(): case id(): - case id(): + case id(): return true; } } @@ -1017,7 +1017,7 @@ private: if (auto value = singleValueFrom(exp)) { auto item = value->item.get(); switch (item->getId()) { - case id(): + case id(): return true; case id(): { auto simpleValue = static_cast(item); @@ -1167,8 +1167,8 @@ private: } else if (auto attrib = statement->content.as()) { auto appendix = statement->appendix.get(); switch (appendix->item->getId()) { - case id(): { - auto if_line = static_cast(appendix->item.get()); + case id(): { + auto if_line = static_cast(appendix->item.get()); auto ifNode = x->new_ptr(); ifNode->type.set(if_line->type); ifNode->nodes.push_back(if_line->condition); @@ -1214,7 +1214,7 @@ private: transformStatement(statement, out); return; } - case id(): { + case id(): { throw std::logic_error(_info.errorMessage("while-loop line decorator is not supported here"sv, appendix->item.get())); break; } @@ -1227,8 +1227,8 @@ private: } auto appendix = statement->appendix.get(); switch (appendix->item->getId()) { - case id(): { - auto if_line = static_cast(appendix->item.get()); + case id(): { + auto if_line = static_cast(appendix->item.get()); auto ifNode = x->new_ptr(); ifNode->type.set(if_line->type); ifNode->nodes.push_back(if_line->condition); @@ -1248,8 +1248,8 @@ private: statement->content.set(expListAssign); break; } - case id(): { - auto while_line = static_cast(appendix->item.get()); + case id(): { + auto while_line = static_cast(appendix->item.get()); auto whileNode = x->new_ptr(); whileNode->type.set(while_line->type); whileNode->condition.set(while_line->condition); @@ -1429,8 +1429,8 @@ private: std::string name; if (auto var = callable->item.as()) { name = _parser.toString(var); - } else if (auto self = callable->item.as()) { - if (self->name.is()) name = "self"sv; + } else if (auto self = callable->item.as()) { + if (self->name.is()) name = "self"sv; } BREAK_IF(name.empty()); switch (op) { @@ -1596,7 +1596,7 @@ private: BLOCK_START auto value = singleValueFrom(*it); BREAK_IF(!value); - if (value->item.is() || value->getByPath()) { + if (value->item.is() || value->getByPath()) { holdItem = true; break; } @@ -1606,7 +1606,7 @@ private: if (auto dot = ast_cast(chainValue->items.back())) { BREAK_IF(!dot->name.is()); holdItem = true; - } else if (ast_is(chainValue->items.back())) { + } else if (ast_is(chainValue->items.back())) { holdItem = true; } BLOCK_END @@ -1677,7 +1677,7 @@ private: transformAssignItem(*vit, args); _buf << indent() << globalVar("setmetatable"sv, x) << '(' << join(args, ", "sv) << ')' << nll(x); temp.push_back(clearBuf()); - } else if (ast_is(chainValue->items.back())) { + } else if (ast_is(chainValue->items.back())) { auto tmpChain = chainValue->new_ptr(); tmpChain->items.dup(chainValue->items); tmpChain->items.pop_back(); @@ -1940,7 +1940,7 @@ private: bool isNil = false; if (auto v1 = singleValueFrom(pair.defVal)) { if (auto v2 = v1->item.as()) { - if (auto v3 = v2->value.as()) { + if (auto v3 = v2->value.as()) { isNil = _parser.toString(v3) == "nil"sv; } } @@ -2095,7 +2095,7 @@ private: bool isNil = false; if (auto v1 = singleValueFrom(item.defVal)) { if (auto v2 = v1->item.as()) { - if (auto v3 = v2->value.as()) { + if (auto v3 = v2->value.as()) { isNil = _parser.toString(v3) == "nil"sv; } } @@ -2141,7 +2141,7 @@ private: std::list destructFromExp(ast_node* node, bool optional) { const node_container* tableItems = nullptr; - ast_ptr sep = optional ? node->new_ptr() : nullptr; + ast_ptr sep = optional ? node->new_ptr() : nullptr; switch (node->getId()) { case id(): { auto item = singleValueFrom(node)->item.get(); @@ -2150,7 +2150,7 @@ private: if (tbA) { tableItems = &tbA->values.objects(); } else { - auto tbB = ast_cast(item); + auto tbB = ast_cast(item); if (tbB) tableItems = &tbB->pairs.objects(); } break; @@ -2170,8 +2170,8 @@ private: tableItems = &table->values.objects(); break; } - case id(): { - auto table = ast_cast(node); + case id(): { + auto table = ast_cast(node); tableItems = &table->pairs.objects(); break; } @@ -2184,9 +2184,9 @@ private: for (auto pair : *tableItems) { switch (pair->getId()) { case id(): - case id(): { + case id(): { Exp_t* defVal = nullptr; - if (auto nd = ast_cast(pair)) { + if (auto nd = ast_cast(pair)) { pair = nd->item.get(); defVal = nd->defVal.get(); } @@ -2196,7 +2196,7 @@ private: } auto value = singleValueFrom(pair); auto item = value->item.get(); - if (ast_is(item) || item->getByPath()) { + if (ast_is(item) || item->getByPath()) { auto subPairs = destructFromExp(pair, optional); if (!subPairs.empty()) { if (defVal) { @@ -2223,14 +2223,14 @@ private: } break; } - case id(): - case id(): { + case id(): + case id(): { Exp_t* defVal = nullptr; - if (auto vpd = ast_cast(pair)) { + if (auto vpd = ast_cast(pair)) { pair = vpd->pair.get(); defVal = vpd->defVal.get(); } - auto vp = static_cast(pair); + auto vp = static_cast(pair); auto name = _parser.toString(vp->name); auto chain = toAst('.' + name, vp->name); pairs.push_back({toAst(name, vp).get(), @@ -2239,14 +2239,14 @@ private: defVal}); break; } - case id(): - case id(): { + case id(): + case id(): { Exp_t* defVal = nullptr; - if (auto npd = ast_cast(pair)) { + if (auto npd = ast_cast(pair)) { pair = npd->pair.get(); defVal = npd->defVal.get(); } - auto np = static_cast(pair); + auto np = static_cast(pair); ast_ptr keyIndex; if (np->key) { if (auto key = np->key->getByPath()) { @@ -2256,7 +2256,7 @@ private: } else { keyIndex = toAst('.' + keyNameStr, key).get(); } - } else if (auto key = np->key->getByPath()) { + } else if (auto key = np->key->getByPath()) { auto callable = np->new_ptr(); callable->item.set(key); auto chainValue = np->new_ptr(); @@ -2273,7 +2273,7 @@ private: if (auto exp = np->value.as()) { if (!isAssignable(exp)) throw std::logic_error(_info.errorMessage("can't do destructure value"sv, exp)); auto item = singleValueFrom(exp)->item.get(); - if (ast_is(item) || item->getByPath()) { + if (ast_is(item) || item->getByPath()) { auto subPairs = destructFromExp(exp, optional); if (!subPairs.empty()) { if (defVal) { @@ -2327,31 +2327,31 @@ private: } break; } - case id(): - case id(): { + case id(): + case id(): { Exp_t* defVal = nullptr; - if (auto mvpd = ast_cast(pair)) { + if (auto mvpd = ast_cast(pair)) { pair = mvpd->pair.get(); defVal = mvpd->defVal.get(); } - auto mp = static_cast(pair); + auto mp = static_cast(pair); auto name = _parser.toString(mp->name); checkMetamethod(name, mp->name); _buf << "__"sv << name << ':' << name; - auto newPairDef = toAst(clearBuf(), pair); + auto newPairDef = toAst(clearBuf(), pair); newPairDef->defVal.set(defVal); subMetaDestruct->values.push_back(newPairDef); break; } - case id(): - case id(): { + case id(): + case id(): { Exp_t* defVal = nullptr; - if (auto mnpd = ast_cast(pair)) { + if (auto mnpd = ast_cast(pair)) { pair = mnpd->pair.get(); defVal = mnpd->defVal.get(); } - auto mp = static_cast(pair); - auto newPair = pair->new_ptr(); + auto mp = static_cast(pair); + auto newPair = pair->new_ptr(); if (mp->key) { switch (mp->key->getId()) { case id(): { @@ -2370,7 +2370,7 @@ private: } } newPair->value.set(mp->value); - auto newPairDef = mp->new_ptr(); + auto newPairDef = mp->new_ptr(); newPairDef->pair.set(newPair); newPairDef->defVal.set(defVal); subMetaDestruct->values.push_back(newPairDef); @@ -2425,11 +2425,11 @@ private: auto expr = *i; auto value = singleValueFrom(expr); ast_node* destructNode = value->getByPath(); - if (destructNode || (destructNode = value->item.as())) { + if (destructNode || (destructNode = value->item.as())) { if (*j != nil) { if (auto ssVal = simpleSingleValueFrom(*j)) { switch (ssVal->value->getId()) { - case id(): + case id(): throw std::logic_error(_info.errorMessage("can not destructure a constant"sv, ssVal->value)); break; case id(): @@ -2449,28 +2449,28 @@ private: case id(): dlist = &static_cast(destructNode)->values.objects(); break; - case id(): - dlist = &static_cast(destructNode)->pairs.objects(); + case id(): + dlist = &static_cast(destructNode)->pairs.objects(); break; default: YUEE("AST node mismatch", destructNode); break; } for (auto item : *dlist) { switch (item->getId()) { - case id(): { - auto mvp = static_cast(item); + case id(): { + auto mvp = static_cast(item); auto mp = mvp->pair.get(); auto name = _parser.toString(mp->name); checkMetamethod(name, mp->name); _buf << "__"sv << name << ':' << name; - auto newPairDef = toAst(clearBuf(), item); + auto newPairDef = toAst(clearBuf(), item); newPairDef->defVal.set(mvp->defVal); subMetaDestruct->values.push_back(newPairDef); break; } - case id(): { - auto mnp = static_cast(item); + case id(): { + auto mnp = static_cast(item); auto mp = mnp->pair.get(); - auto newPair = item->new_ptr(); + auto newPair = item->new_ptr(); if (mp->key) { switch (mp->key->getId()) { case id(): { @@ -2492,24 +2492,24 @@ private: } } newPair->value.set(mp->value); - auto newPairDef = item->new_ptr(); + auto newPairDef = item->new_ptr(); newPairDef->pair.set(newPair); newPairDef->defVal.set(mnp->defVal); subMetaDestruct->values.push_back(newPairDef); break; } - case id(): { - auto mp = static_cast(item); + case id(): { + auto mp = static_cast(item); auto name = _parser.toString(mp->name); checkMetamethod(name, mp->name); _buf << "__"sv << name << ':' << name; - auto newPairDef = toAst(clearBuf(), item); + auto newPairDef = toAst(clearBuf(), item); subMetaDestruct->values.push_back(newPairDef); break; } - case id(): { - auto mp = static_cast(item); - auto newPair = item->new_ptr(); + case id(): { + auto mp = static_cast(item); + auto newPair = item->new_ptr(); if (mp->key) { switch (mp->key->getId()) { case id(): { @@ -2533,21 +2533,21 @@ private: } } newPair->value.set(mp->value); - auto newPairDef = item->new_ptr(); + auto newPairDef = item->new_ptr(); newPairDef->pair.set(newPair); subMetaDestruct->values.push_back(newPairDef); break; } - case id(): { - auto pair = static_cast(item); - auto newPairDef = item->new_ptr(); + case id(): { + auto pair = static_cast(item); + auto newPairDef = item->new_ptr(); newPairDef->pair.set(pair); subDestruct->values.push_back(newPairDef); break; } - case id(): { - auto pair = static_cast(item); - auto newPairDef = item->new_ptr(); + case id(): { + auto pair = static_cast(item); + auto newPairDef = item->new_ptr(); newPairDef->pair.set(pair); subDestruct->values.push_back(newPairDef); break; @@ -2636,7 +2636,7 @@ private: for (auto node : item.structure->items.objects()) { if (auto exp = ast_cast(node)) { if (auto value = simpleSingleValueFrom(node)) { - if (ast_is(value->value)) { + if (ast_is(value->value)) { continue; } } @@ -2700,8 +2700,8 @@ private: if (chain->items.size() == 2) { if (auto callable = ast_cast(chain->items.front())) { ast_node* var = callable->item.as(); - if (auto self = callable->item.as()) { - var = self->name.as(); + if (auto self = callable->item.as()) { + var = self->name.as(); } BREAK_IF(var && isLocal(_parser.toString(var))); } @@ -2834,7 +2834,7 @@ private: for (auto it = nodes.rbegin(); it != nodes.rend(); ++it) { ns.push_back(*it); if (auto cond = ast_cast(*it)) { - if (*it != nodes.front() && cond->condition.is()) { + if (*it != nodes.front() && cond->condition.is()) { auto x = *it; auto newIf = x->new_ptr(); newIf->type.set(toAst("if"sv, x)); @@ -2888,7 +2888,7 @@ private: default: YUEE("AST node mismatch", node); break; } } - auto asmt = ifCondPairs.front().first->condition.as(); + auto asmt = ifCondPairs.front().first->condition.as(); bool storingValue = false; ast_ptr extraAssignment; if (asmt) { @@ -3019,14 +3019,14 @@ private: void transform_pipe_exp(const node_container& values, str_list& out, ExpUsage usage, ExpList_t* assignList = nullptr) { if (values.size() == 1 && usage == ExpUsage::Closure) { - transform_unary_exp(static_cast(values.front()), out); + transform_unary_exp(static_cast(values.front()), out); } else { auto x = values.front(); - auto arg = newExp(static_cast(x), x); + auto arg = newExp(static_cast(x), x); auto begin = values.begin(); begin++; for (auto it = begin; it != values.end(); ++it) { - auto unary = static_cast(*it); + auto unary = static_cast(*it); auto value = static_cast(singleUnaryExpFrom(unary) ? unary->expos.back() : nullptr); if (values.back() == *it && !unary->ops.empty() && usage == ExpUsage::Common) { throw std::logic_error(_info.errorMessage("expression list is not supported here"sv, x)); @@ -3119,7 +3119,7 @@ private: str_list temp; transform_pipe_exp(exp->pipeExprs.objects(), temp, ExpUsage::Closure); for (auto _opValue : exp->opValues.objects()) { - auto opValue = static_cast(_opValue); + auto opValue = static_cast(_opValue); transformBinaryOperator(opValue->op, temp); transform_pipe_exp(opValue->pipeExprs.objects(), temp, ExpUsage::Closure); } @@ -3140,7 +3140,7 @@ private: transform_pipe_exp(exp->pipeExprs.objects(), temp, ExpUsage::Closure); auto last = exp->opValues.objects().back(); for (auto _opValue : exp->opValues.objects()) { - auto opValue = static_cast(_opValue); + auto opValue = static_cast(_opValue); transformBinaryOperator(opValue->op, temp); if (opValue == last) { left->pipeExprs.dup(opValue->pipeExprs); @@ -3251,7 +3251,7 @@ private: auto item = value->item.get(); switch (item->getId()) { case id(): transformSimpleValue(static_cast(item), out); break; - case id(): transform_simple_table(static_cast(item), out); break; + case id(): transform_simple_table(static_cast(item), out); break; case id(): transformChainValue(static_cast(item), out, ExpUsage::Closure); break; case id(): transformString(static_cast(item), out); break; default: YUEE("AST node mismatch", value); break; @@ -3270,8 +3270,8 @@ private: } break; } - case id(): { - transformSelfName(static_cast(item), out, invoke); + case id(): { + transformSelfName(static_cast(item), out, invoke); globalVar("self"sv, item); break; } @@ -3296,7 +3296,7 @@ private: void transformSimpleValue(SimpleValue_t* simpleValue, str_list& out) { auto value = simpleValue->value.get(); switch (value->getId()) { - case id(): transform_const_value(static_cast(value), out); break; + case id(): transform_const_value(static_cast(value), out); break; case id(): transformIf(static_cast(value), out, ExpUsage::Closure); break; case id(): transformSwitch(static_cast(value), out, ExpUsage::Closure); break; case id(): transformWithClosure(static_cast(value), out); break; @@ -3306,7 +3306,7 @@ private: case id(): transformWhileClosure(static_cast(value), out); break; case id(): transformDo(static_cast(value), out, ExpUsage::Closure); break; case id(): transformTry(static_cast(value), out, ExpUsage::Closure); break; - case id(): transform_unary_value(static_cast(value), out); break; + case id(): transform_unary_value(static_cast(value), out); break; case id(): transformTblComprehension(static_cast(value), out, ExpUsage::Closure); break; case id(): transformTableLit(static_cast(value), out); break; case id(): transformComprehension(static_cast(value), out, ExpUsage::Closure); break; @@ -3449,7 +3449,7 @@ private: auto funLit = x->new_ptr(); funLit->argsDef.set(backcall->argsDef); auto arrow = _parser.toString(backcall->arrow); - funLit->arrow.set(toAst(arrow == "<-"sv ? "->"sv : "=>"sv, x)); + funLit->arrow.set(toAst(arrow == "<-"sv ? "->"sv : "=>"sv, x)); funLit->body.set(body); auto simpleValue = x->new_ptr(); simpleValue->value.set(funLit); @@ -3502,8 +3502,8 @@ private: if (!local->collected) { local->collected = true; switch (local->item->getId()) { - case id(): { - auto flag = static_cast(local->item.get()); + case id(): { + auto flag = static_cast(local->item.get()); LocalMode newMode = _parser.toString(flag) == "*"sv ? LocalMode::Any : LocalMode::Capital; if (int(newMode) > int(mode)) { mode = newMode; @@ -3516,8 +3516,8 @@ private: } break; } - case id(): { - auto values = local->item.to(); + case id(): { + auto values = local->item.to(); for (auto name : values->nameList->names.objects()) { local->forceDecls.push_back(_parser.toString(name)); } @@ -3610,7 +3610,7 @@ private: auto x = last; auto expList = expListFrom(last); BREAK_IF(!expList); - BREAK_IF(last->appendix && !last->appendix->item.is()); + BREAK_IF(last->appendix && !last->appendix->item.is()); auto expListLow = x->new_ptr(); expListLow->exprs.dup(expList->exprs); auto returnNode = x->new_ptr(); @@ -3625,7 +3625,7 @@ private: BREAK_IF(expListLow->exprs.size() != 1); auto exp = static_cast(expListLow->exprs.back()); BREAK_IF(!exp->opValues.empty()); - auto chainValue = exp->getByPath(); + auto chainValue = exp->getByPath(); BREAK_IF(!chainValue); isMacro = isMacroChain(chainValue); BLOCK_END @@ -3835,7 +3835,7 @@ private: if (argsDef) { for (auto def_ : argsDef->definitions.objects()) { auto def = static_cast(def_); - if (def->name.is()) { + if (def->name.is()) { throw std::logic_error(_info.errorMessage("self name is not supported for macro function argument"sv, def->name)); } else { std::string defVal; @@ -4000,7 +4000,7 @@ private: } } - void transform_outer_var_shadow(outer_var_shadow_t* shadow) { + void transform_outer_var_shadow(OuterVarShadow_t* shadow) { markVarShadowed(); if (shadow->varList) { for (auto name : shadow->varList->names.objects()) { @@ -4025,7 +4025,7 @@ private: auto& arg = argItems.emplace_back(); switch (def->name->getId()) { case id(): arg.name = _parser.toString(def->name); break; - case id(): { + case id(): { assignSelf = true; if (def->op) { if (def->defaultValue) { @@ -4033,21 +4033,21 @@ private: } arg.checkExistence = true; } - auto selfName = static_cast(def->name.get()); + auto selfName = static_cast(def->name.get()); switch (selfName->name->getId()) { - case id(): { - auto clsName = static_cast(selfName->name.get()); + case id(): { + auto clsName = static_cast(selfName->name.get()); arg.name = _parser.toString(clsName->name); arg.assignSelf = _parser.toString(clsName); break; } - case id(): { - auto sfName = static_cast(selfName->name.get()); + case id(): { + auto sfName = static_cast(selfName->name.get()); arg.name = _parser.toString(sfName->name); arg.assignSelf = _parser.toString(sfName); break; } - case id(): + case id(): arg.name = "self"sv; if (def->op) throw std::logic_error(_info.errorMessage("can only check existence for assigning self field"sv, selfName->name)); break; @@ -4105,12 +4105,12 @@ private: out.push_back(join(temp)); } - void transformSelfName(SelfName_t* selfName, str_list& out, const ast_sel& invoke = {}) { + void transformSelfName(SelfItem_t* selfName, str_list& out, const ast_sel& invoke = {}) { auto x = selfName; auto name = selfName->name.get(); switch (name->getId()) { - case id(): { - auto clsName = static_cast(name); + case id(): { + auto clsName = static_cast(name); auto nameStr = _parser.toString(clsName->name); if (LuaKeywords.find(nameStr) != LuaKeywords.end()) { out.push_back("self.__class[\""s + nameStr + "\"]"s); @@ -4127,11 +4127,11 @@ private: } break; } - case id(): + case id(): out.push_back("self.__class"s); break; - case id(): { - auto sfName = static_cast(name); + case id(): { + auto sfName = static_cast(name); auto nameStr = _parser.toString(sfName->name); if (LuaKeywords.find(nameStr) != LuaKeywords.end()) { out.push_back("self[\""s + nameStr + "\"]"s); @@ -4148,7 +4148,7 @@ private: } break; } - case id(): + case id(): out.push_back("self"s); break; default: YUEE("AST node mismatch", name); break; @@ -4157,7 +4157,7 @@ private: bool transformChainEndWithEOP(const node_container& chainList, str_list& out, ExpUsage usage, ExpList_t* assignList) { auto x = chainList.front(); - if (ast_is(chainList.back())) { + if (ast_is(chainList.back())) { auto parens = x->new_ptr(); { auto chainValue = x->new_ptr(); @@ -4200,7 +4200,7 @@ private: } bool transformChainWithEOP(const node_container& chainList, str_list& out, ExpUsage usage, ExpList_t* assignList, bool optionalDestruct) { - auto opIt = std::find_if(chainList.begin(), chainList.end(), [](ast_node* node) { return ast_is(node); }); + auto opIt = std::find_if(chainList.begin(), chainList.end(), [](ast_node* node) { return ast_is(node); }); if (opIt != chainList.end()) { auto x = chainList.front(); str_list temp; @@ -4218,9 +4218,9 @@ private: BLOCK_START auto back = ast_cast(partOne->items.back()); BREAK_IF(!back); - auto selfName = ast_cast(back->item); + auto selfName = ast_cast(back->item); BREAK_IF(!selfName); - if (auto sname = ast_cast(selfName->name)) { + if (auto sname = ast_cast(selfName->name)) { auto colonItem = x->new_ptr(); colonItem->name.set(sname->name); partOne->items.pop_back(); @@ -4228,7 +4228,7 @@ private: partOne->items.push_back(colonItem); break; } - if (auto cname = ast_cast(selfName->name)) { + if (auto cname = ast_cast(selfName->name)) { auto colonItem = x->new_ptr(); colonItem->name.set(cname->name); partOne->items.pop_back(); @@ -4662,11 +4662,11 @@ private: auto followItem = next != chainList.end() ? *next : nullptr; if (current != chainList.begin()) { --current; - if (!ast_is(*current)) { + if (!ast_is(*current)) { ++current; } } - if (ast_is(followItem)) { + if (ast_is(followItem)) { ++next; followItem = next != chainList.end() ? *next : nullptr; --next; @@ -4707,8 +4707,8 @@ private: auto name = _parser.toString(colonItem->name); auto chainValue = x->new_ptr(); chainValue->items.push_back(toAst(callVar, x)); - if (ast_is(*current)) { - chainValue->items.push_back(x->new_ptr()); + if (ast_is(*current)) { + chainValue->items.push_back(x->new_ptr()); } chainValue->items.push_back(toAst('\"' + name + '\"', x)); if (auto invoke = ast_cast(followItem)) { @@ -4789,8 +4789,8 @@ private: temp.back() = (temp.back().front() == '[' ? "[ "s : "["s) + temp.back() + ']'; break; case id(): transformInvokeArgs(static_cast(item), temp); break; - case id(): - transform_table_appending_op(static_cast(item), temp); + case id(): + transform_table_appending_op(static_cast(item), temp); break; default: YUEE("AST node mismatch", item); break; } @@ -4925,7 +4925,7 @@ private: auto exp = static_cast(arg); BLOCK_START BREAK_IF(!exp->opValues.empty()); - auto chainValue = exp->getByPath(); + auto chainValue = exp->getByPath(); BREAK_IF(!chainValue); BREAK_IF(!isMacroChain(chainValue)); str = std::get<1>(expandMacroStr(chainValue)); @@ -5107,11 +5107,11 @@ private: for (auto stmt_ : block->statements.objects()) { auto stmt = static_cast(stmt_); if (auto global = stmt->content.as()) { - if (global->item.is()) { + if (global->item.is()) { throw std::logic_error(_info.errorMessage("can not insert global statement with wildcard operator from macro"sv, x)); } } else if (auto local = stmt->content.as()) { - if (local->item.is()) { + if (local->item.is()) { throw std::logic_error(_info.errorMessage("can not insert local statement with wildcard operator from macro"sv, x)); } } @@ -5214,7 +5214,7 @@ private: throw std::logic_error(_info.errorMessage("slice syntax not supported here"sv, slice)); } - void transform_table_appending_op(table_appending_op_t* op, str_list&) { + void transform_table_appending_op(TableAppendingOp_t* op, str_list&) { throw std::logic_error(_info.errorMessage("table appending syntax not supported here"sv, op)); } @@ -5233,7 +5233,7 @@ private: out.push_back('(' + join(temp, ", "sv) + ')'); } - void transform_unary_value(unary_value_t* unary_value, str_list& out) { + void transform_unary_value(UnaryValue_t* unary_value, str_list& out) { str_list temp; for (auto _op : unary_value->ops.objects()) { std::string op = _parser.toString(_op); @@ -5246,7 +5246,7 @@ private: out.push_back(join(temp)); } - void transform_unary_exp(unary_exp_t* unary_exp, str_list& out) { + void transform_unary_exp(UnaryExp_t* unary_exp, str_list& out) { if (unary_exp->ops.empty() && unary_exp->expos.size() == 1) { transformValue(static_cast(unary_exp->expos.back()), out); return; @@ -5341,29 +5341,29 @@ private: transformForEach(forEach, temp); break; } - case id(): - case id(): { - if (auto pair = ast_cast(item)) { + case id(): + case id(): { + if (auto pair = ast_cast(item)) { if (pair->defVal) { throw std::logic_error(_info.errorMessage("invalid default value here"sv, pair->defVal)); } item = pair->pair.get(); } - auto variablePair = static_cast(item); + auto variablePair = static_cast(item); auto nameStr = _parser.toString(variablePair->name); auto assignment = toAst(tableVar + '.' + nameStr + '=' + nameStr, item); transformAssignment(assignment, temp); break; } - case id(): - case id(): { - if (auto pair = ast_cast(item)) { + case id(): + case id(): { + if (auto pair = ast_cast(item)) { if (pair->defVal) { throw std::logic_error(_info.errorMessage("invalid default value here"sv, pair->defVal)); } item = pair->pair.get(); } - auto normalPair = static_cast(item); + auto normalPair = static_cast(item); auto assignment = toAst(tableVar + "=nil"s, item); auto chainValue = singleValueFrom(ast_to(assignment->expList->exprs.front()))->item.to(); auto key = normalPair->key.get(); @@ -5376,7 +5376,7 @@ private: dotItem->name.set(name); chainItem = dotItem.get(); } else { - auto selfName = keyName->name.to(); + auto selfName = keyName->name.to(); auto callable = x->new_ptr(); callable->item.set(selfName); auto chainValue = x->new_ptr(); @@ -5407,9 +5407,9 @@ private: break; } case id(): - case id(): { + case id(): { auto current = item; - if (auto pair = ast_cast(item)) { + if (auto pair = ast_cast(item)) { if (pair->defVal) { throw std::logic_error(_info.errorMessage("invalid default value here"sv, pair->defVal)); } @@ -5457,29 +5457,29 @@ private: transformAssignment(assignment, temp); break; } - case id(): - case id(): { - if (auto pair = ast_cast(item)) { + case id(): + case id(): { + if (auto pair = ast_cast(item)) { if (pair->defVal) { throw std::logic_error(_info.errorMessage("invalid default value here"sv, pair->defVal)); } item = pair->pair.get(); } - auto metaVarPair = static_cast(item); + auto metaVarPair = static_cast(item); auto nameStr = _parser.toString(metaVarPair->name); auto assignment = toAst(tableVar + ".<"s + nameStr + ">="s + nameStr, item); transformAssignment(assignment, temp); break; } - case id(): - case id(): { - if (auto pair = ast_cast(item)) { + case id(): + case id(): { + if (auto pair = ast_cast(item)) { if (pair->defVal) { throw std::logic_error(_info.errorMessage("invalid default value here"sv, pair->defVal)); } item = pair->pair.get(); } - auto metaNormalPair = static_cast(item); + auto metaNormalPair = static_cast(item); auto assignment = toAst(tableVar + "=nil"s, item); auto chainValue = singleValueFrom(ast_to(assignment->expList->exprs.front()))->item.to(); auto key = metaNormalPair->key.get(); @@ -5554,45 +5554,45 @@ private: auto x = values.front(); str_list temp; incIndentOffset(); - auto metatable = x->new_ptr(); + auto metatable = x->new_ptr(); ast_sel metatableItem; for (auto value : values) { auto item = value; switch (item->getId()) { - case id(): { - auto pair = static_cast(item); + case id(): { + auto pair = static_cast(item); if (pair->defVal) { throw std::logic_error(_info.errorMessage("invalid default value"sv, pair->defVal)); } item = pair->pair.get(); break; } - case id(): { - auto pair = static_cast(item); + case id(): { + auto pair = static_cast(item); if (pair->defVal) { throw std::logic_error(_info.errorMessage("invalid default value"sv, pair->defVal)); } item = pair->pair.get(); break; } - case id(): { - auto pair = static_cast(item); + case id(): { + auto pair = static_cast(item); if (pair->defVal) { throw std::logic_error(_info.errorMessage("invalid default value"sv, pair->defVal)); } item = pair->pair.get(); break; } - case id(): { - auto pair = static_cast(item); + case id(): { + auto pair = static_cast(item); if (pair->defVal) { throw std::logic_error(_info.errorMessage("invalid default value"sv, pair->defVal)); } item = pair->pair.get(); break; } - case id(): { - auto pair = static_cast(item); + case id(): { + auto pair = static_cast(item); if (pair->defVal) { throw std::logic_error(_info.errorMessage("invalid default value"sv, pair->defVal)); } @@ -5603,27 +5603,27 @@ private: bool isMetamethod = false; switch (item->getId()) { case id(): transformExp(static_cast(item), temp, ExpUsage::Closure); break; - case id(): transform_variable_pair(static_cast(item), temp); break; - case id(): transform_normal_pair(static_cast(item), temp, false); break; + case id(): transform_variable_pair(static_cast(item), temp); break; + case id(): transform_normal_pair(static_cast(item), temp, false); break; case id(): transformTableBlockIndent(static_cast(item), temp); break; case id(): transformTableBlock(static_cast(item), temp); break; - case id(): { + case id(): { isMetamethod = true; - auto mp = static_cast(item); + auto mp = static_cast(item); if (metatableItem) { throw std::logic_error(_info.errorMessage("too many metatable declarations"sv, mp->name)); } auto name = _parser.toString(mp->name); checkMetamethod(name, mp->name); _buf << "__"sv << name << ':' << name; - auto newPair = toAst(clearBuf(), item); + auto newPair = toAst(clearBuf(), item); metatable->pairs.push_back(newPair); break; } - case id(): { + case id(): { isMetamethod = true; - auto mp = static_cast(item); - auto newPair = item->new_ptr(); + auto mp = static_cast(item); + auto newPair = item->new_ptr(); if (mp->key) { if (metatableItem) { throw std::logic_error(_info.errorMessage("too many metatable declarations"sv, mp->key)); @@ -5864,8 +5864,8 @@ private: } } switch (loopTarget->getId()) { - case id(): { - auto star_exp = static_cast(loopTarget); + case id(): { + auto star_exp = static_cast(loopTarget); auto listVar = singleVariableFrom(star_exp->value, true); if (!isLocal(listVar)) listVar.clear(); auto indexVar = getUnusedName("_index_"sv); @@ -6011,7 +6011,7 @@ private: if (auto tableBlock = ast_cast(lastArg)) { lastTable = &tableBlock->values; } else if (auto value = singleValueFrom(lastArg)) { - if (auto simpleTable = ast_cast(value->item)) { + if (auto simpleTable = ast_cast(value->item)) { lastTable = &simpleTable->pairs; } } @@ -6020,7 +6020,7 @@ private: invokeArgs->args.pop_back(); while (!invokeArgs->args.empty()) { if (Value_t* value = singleValueFrom(invokeArgs->args.back())) { - if (auto tb = value->item.as()) { + if (auto tb = value->item.as()) { const auto& ps = tb->pairs.objects(); for (auto it = ps.rbegin(); it != ps.rend(); ++it) { lastTable->push_front(*it); @@ -6045,7 +6045,7 @@ private: out.push_back('(' + join(temp, ", "sv) + ')'); } - void transformForHead(Variable_t* var, Exp_t* startVal, Exp_t* stopVal, for_step_value_t* stepVal, str_list& out) { + void transformForHead(Variable_t* var, Exp_t* startVal, Exp_t* stopVal, ForStepValue_t* stepVal, str_list& out) { str_list temp; std::string varName = _parser.toString(var); transformExp(startVal, temp, ExpUsage::Closure); @@ -6421,7 +6421,7 @@ private: out.push_back(join(temp)); } - void transform_variable_pair(variable_pair_t* pair, str_list& out) { + void transform_variable_pair(VariablePair_t* pair, str_list& out) { auto name = _parser.toString(pair->name); if (_config.lintGlobalVariable && !isLocal(name)) { if (_globals.find(name) == _globals.end()) { @@ -6431,14 +6431,14 @@ private: out.push_back(name + " = "s + name); } - void transform_normal_pair(normal_pair_t* pair, str_list& out, bool assignClass) { + void transform_normal_pair(NormalPair_t* pair, str_list& out, bool assignClass) { auto key = pair->key.get(); str_list temp; switch (key->getId()) { case id(): { auto keyName = static_cast(key); transformKeyName(keyName, temp); - if (keyName->name.is() && !assignClass) { + if (keyName->name.is() && !assignClass) { temp.back() = '[' + temp.back() + ']'; } break; @@ -6481,8 +6481,8 @@ private: void transformKeyName(KeyName_t* keyName, str_list& out) { auto name = keyName->name.get(); switch (name->getId()) { - case id(): - transformSelfName(static_cast(name), out); + case id(): + transformSelfName(static_cast(name), out); break; case id(): { auto nameStr = _parser.toString(name); @@ -6513,10 +6513,10 @@ private: void transformDoubleString(DoubleString_t* doubleString, str_list& out) { str_list temp; for (auto _seg : doubleString->segments.objects()) { - auto seg = static_cast(_seg); + auto seg = static_cast(_seg); auto content = seg->content.get(); switch (content->getId()) { - case id(): { + case id(): { auto str = _parser.toString(content); Utils::replace(str, "\r\n"sv, "\n"); Utils::replace(str, "\n"sv, "\\n"sv); @@ -6593,7 +6593,7 @@ private: if (auto dotChain = ast_cast(chain->items.back())) { className = '\"' + _parser.toString(dotChain->name) + '\"'; } else if (auto index = ast_cast(chain->items.back())) { - if (auto name = index->getByPath()) { + if (auto name = index->getByPath()) { transformString(name, temp); className = std::move(temp.back()); temp.pop_back(); @@ -6679,8 +6679,8 @@ private: std::list members; for (auto content : classDecl->body->contents.objects()) { switch (content->getId()) { - case id(): { - size_t inc = transform_class_member_list(static_cast(content), members, classVar); + case id(): { + size_t inc = transform_class_member_list(static_cast(content), members, classVar); auto it = members.end(); for (size_t i = 0; i < inc; ++i, --it) ; @@ -6832,24 +6832,24 @@ private: out.push_back(join(temp)); } - size_t transform_class_member_list(class_member_list_t* class_member_list, std::list& out, const std::string& classVar) { + size_t transform_class_member_list(ClassMemberList_t* class_member_list, std::list& out, const std::string& classVar) { str_list temp; size_t count = 0; for (auto keyValue : class_member_list->values.objects()) { MemType type = MemType::Common; ast_ptr ref; switch (keyValue->getId()) { - case id(): { - auto mtPair = static_cast(keyValue); + case id(): { + auto mtPair = static_cast(keyValue); auto nameStr = _parser.toString(mtPair->name); checkMetamethod(nameStr, mtPair->name); - ref.set(toAst("__"s + nameStr + ':' + nameStr, keyValue)); + ref.set(toAst("__"s + nameStr + ':' + nameStr, keyValue)); keyValue = ref.get(); break; } - case id(): { - auto mtPair = static_cast(keyValue); - auto normal_pair = keyValue->new_ptr(); + case id(): { + auto mtPair = static_cast(keyValue); + auto normal_pair = keyValue->new_ptr(); if (auto name = mtPair->key.as()) { auto nameStr = _parser.toString(name); checkMetamethod(nameStr, name); @@ -6866,16 +6866,16 @@ private: } } BLOCK_START - auto normal_pair = ast_cast(keyValue); + auto normal_pair = ast_cast(keyValue); BREAK_IF(!normal_pair); auto keyName = normal_pair->key.as(); BREAK_IF(!keyName); std::string newSuperCall; - auto selfName = keyName->name.as(); - if (selfName) { + auto selfItem = keyName->name.as(); + if (selfItem) { type = MemType::Property; - auto name = ast_cast(selfName->name); - if (!name) throw std::logic_error(_info.errorMessage("invalid class poperty name"sv, selfName->name)); + auto name = ast_cast(selfItem->name); + if (!name) throw std::logic_error(_info.errorMessage("invalid class poperty name"sv, selfItem->name)); newSuperCall = classVar + ".__parent."s + _parser.toString(name->name); } else { auto x = keyName; @@ -6945,11 +6945,11 @@ private: decIndentOffset(); } switch (keyValue->getId()) { - case id(): - transform_variable_pair(static_cast(keyValue), temp); + case id(): + transform_variable_pair(static_cast(keyValue), temp); break; - case id(): - transform_normal_pair(static_cast(keyValue), temp, true); + case id(): + transform_normal_pair(static_cast(keyValue), temp, true); break; default: YUEE("AST node mismatch", keyValue); break; } @@ -6969,7 +6969,7 @@ private: switch (item->getId()) { case id(): transformAssignableChain(static_cast(item), out); break; case id(): transformVariable(static_cast(item), out); break; - case id(): transformSelfName(static_cast(item), out); break; + case id(): transformSelfName(static_cast(item), out); break; default: YUEE("AST node mismatch", item); break; } } @@ -7137,7 +7137,7 @@ private: out.push_back(join(temp)); } - void transform_const_value(const_value_t* const_value, str_list& out) { + void transform_const_value(ConstValue_t* const_value, str_list& out) { out.push_back(_parser.toString(const_value)); } @@ -7154,16 +7154,16 @@ private: transformClassDecl(classDecl, out, ExpUsage::Common); break; } - case id(): + case id(): if (_parser.toString(item) == "*"sv) { markVarsGlobal(GlobalMode::Any); } else { markVarsGlobal(GlobalMode::Capital); } break; - case id(): { + case id(): { markVarsGlobal(GlobalMode::Any); - auto values = global->item.to(); + auto values = global->item.to(); if (values->valueList) { auto expList = x->new_ptr(); for (auto name : values->nameList->names.objects()) { @@ -7209,7 +7209,7 @@ private: } for (auto _exp : expList->exprs.objects()) { auto exp = static_cast(_exp); - if (!variableFrom(exp) && !exp->getByPath() && !exp->getByPath()) { + if (!variableFrom(exp) && !exp->getByPath() && !exp->getByPath()) { throw std::logic_error(_info.errorMessage("left hand expressions must be variables in export statement"sv, x)); } } @@ -7253,7 +7253,7 @@ private: auto assignList = toAst(_info.moduleName + "[#"s + _info.moduleName + "+1]"s, x); assignment->expList.set(assignList); for (auto exp : expList->exprs.objects()) { - if (auto classDecl = exp->getByPath()) { + if (auto classDecl = exp->getByPath()) { if (classDecl->name && classDecl->name->item->getId() == id()) { transformClassDecl(classDecl, temp, ExpUsage::Common); auto name = _parser.toString(classDecl->name->item); @@ -7276,7 +7276,7 @@ private: } } - void transform_simple_table(simple_table_t* table, str_list& out) { + void transform_simple_table(SimpleTable_t* table, str_list& out) { transformTable(table->pairs.objects(), out); } @@ -7536,8 +7536,8 @@ private: expList->exprs.push_back(exp); break; } - case id(): { - auto var = static_cast(name)->name.get(); + case id(): { + auto var = static_cast(name)->name.get(); { auto nameNode = var->name.get(); auto callable = toAst(objVar, x); @@ -7597,9 +7597,9 @@ private: auto name = moduleNameFrom(import->literal); import->target.set(toAst(name, x)); } - if (ast_is(import->target)) { + if (ast_is(import->target)) { x = import->target.get(); - bool importAllMacro = import->target.is(); + bool importAllMacro = import->target.is(); std::list> macroPairs; auto newTab = x->new_ptr(); if (auto tabLit = import->target.as()) { @@ -7607,8 +7607,8 @@ private: switch (item->getId()) { #ifdef YUE_NO_MACRO case id(): - case id(): - case id(): { + case id(): + case id(): { throw std::logic_error(_info.errorMessage("macro feature not supported"sv, item)); break; } @@ -7619,20 +7619,20 @@ private: macroPairs.emplace_back(name, name); break; } - case id(): { - auto pair = static_cast(item); + case id(): { + auto pair = static_cast(item); macroPairs.emplace_back(_parser.toString(pair->key->name), _parser.toString(pair->value->name)); break; } - case id(): + case id(): if (importAllMacro) throw std::logic_error(_info.errorMessage("import all macro symbol duplicated"sv, item)); importAllMacro = true; break; #endif // YUE_NO_MACRO - case id(): - case id(): - case id(): - case id(): + case id(): + case id(): + case id(): + case id(): case id(): newTab->items.push_back(item); break; @@ -7734,32 +7734,32 @@ private: auto tableLit = x->new_ptr(); for (auto pair : tabLit->items.objects()) { switch (pair->getId()) { - case id(): { - auto pairDef = pair->new_ptr(); + case id(): { + auto pairDef = pair->new_ptr(); pairDef->pair.set(pair); tableLit->values.push_back(pairDef); break; } - case id(): { - auto pairDef = pair->new_ptr(); + case id(): { + auto pairDef = pair->new_ptr(); pairDef->pair.set(pair); tableLit->values.push_back(pairDef); break; } case id(): { - auto pairDef = pair->new_ptr(); + auto pairDef = pair->new_ptr(); pairDef->item.set(pair); tableLit->values.push_back(pairDef); break; } - case id(): { - auto pairDef = pair->new_ptr(); + case id(): { + auto pairDef = pair->new_ptr(); pairDef->pair.set(pair); tableLit->values.push_back(pairDef); break; } - case id(): { - auto pairDef = pair->new_ptr(); + case id(): { + auto pairDef = pair->new_ptr(); pairDef->pair.set(pair); tableLit->values.push_back(pairDef); break; @@ -7935,7 +7935,7 @@ private: for (auto branch_ : branches) { auto branch = static_cast(branch_); if (auto value = singleValueFrom(branch->valueList); - value && (value->item.is() || value->getByPath())) { + value && (value->item.is() || value->getByPath())) { if (!firstBranch) { temp.push_back(indent() + "else"s + nll(branch)); pushScope(); @@ -8070,8 +8070,8 @@ private: transformLocalDef(local, temp); } switch (local->item->getId()) { - case id(): { - auto values = static_cast(local->item.get()); + case id(): { + auto values = static_cast(local->item.get()); if (values->valueList) { auto x = local; auto expList = x->new_ptr(); @@ -8097,7 +8097,7 @@ private: } break; } - case id(): break; + case id(): break; default: YUEE("AST node mismatch", local->item); break; } out.push_back(join(temp)); @@ -8130,7 +8130,7 @@ private: auto item = *i; auto value = item->new_ptr(); switch (item->getId()) { - case id(): + case id(): value->item.set(item); break; case id(): { @@ -8157,9 +8157,9 @@ private: } if (getLuaTarget(x) >= 504) { std::string attrib; - if (localAttrib->attrib.is()) { + if (localAttrib->attrib.is()) { attrib = " "s; - } else if (localAttrib->attrib.is()) { + } else if (localAttrib->attrib.is()) { attrib = " "s; } else { YUEE("AST node mismatch", localAttrib->attrib); @@ -8169,7 +8169,7 @@ private: var.append(attrib); } } else { - if (localAttrib->attrib.is()) { + if (localAttrib->attrib.is()) { throw std::logic_error(_info.errorMessage("close attribute is not available when not targeting Lua version 5.4 or higher"sv, x)); } for (auto& var : vars) { @@ -8264,7 +8264,7 @@ private: str_list temp; bool constVal = false; if (auto simpleVal = simpleSingleValueFrom(value)) { - constVal = ast_is(simpleVal->value); + constVal = ast_is(simpleVal->value); } bool localVal = false; if (auto var = singleVariableFrom(value, false); isLocal(var)) { diff --git a/src/yuescript/yue_parser.cpp b/src/yuescript/yue_parser.cpp index 48308a6..e78b331 100644 --- a/src/yuescript/yue_parser.cpp +++ b/src/yuescript/yue_parser.cpp @@ -33,23 +33,23 @@ std::unordered_set Keywords = { // clang-format off YueParser::YueParser() { plain_space = *set(" \t"); - Break = nl(-expr('\r') >> '\n'); - Any = Break | any(); - Stop = Break | eof(); - Indent = plain_space; - Comment = "--" >> *(not_(set("\r\n")) >> Any) >> and_(Stop); + line_break = nl(-expr('\r') >> '\n'); + any_char = line_break | any(); + stop = line_break | eof(); + indent = plain_space; + comment = "--" >> *(not_(set("\r\n")) >> any_char) >> and_(stop); multi_line_open = "--[["; multi_line_close = "]]"; - multi_line_content = *(not_(multi_line_close) >> Any); - MultiLineComment = multi_line_open >> multi_line_content >> multi_line_close; - EscapeNewLine = '\\' >> *(set(" \t") | MultiLineComment) >> -Comment >> Break; - space_one = set(" \t") | and_(set("-\\")) >> (MultiLineComment | EscapeNewLine); - Space = -(and_(set(" \t-\\")) >> *space_one >> -Comment); - SpaceBreak = Space >> Break; - White = Space >> *(Break >> Space); - EmptyLine = SpaceBreak; - AlphaNum = sel({range('a', 'z'), range('A', 'Z'), range('0', '9'), '_'}); - Name = sel({range('a', 'z'), range('A', 'Z'), '_'}) >> *AlphaNum; + multi_line_content = *(not_(multi_line_close) >> any_char); + multi_line_comment = multi_line_open >> multi_line_content >> multi_line_close; + escape_new_line = '\\' >> *(set(" \t") | multi_line_comment) >> -comment >> line_break; + space_one = set(" \t") | and_(set("-\\")) >> (multi_line_comment | escape_new_line); + space = -(and_(set(" \t-\\")) >> *space_one >> -comment); + space_break = space >> line_break; + white = space >> *(line_break >> space); + empty_line = space_break; + alpha_num = sel({range('a', 'z'), range('A', 'Z'), range('0', '9'), '_'}); + Name = sel({range('a', 'z'), range('A', 'Z'), '_'}) >> *alpha_num; num_expo = set("eE") >> -set("+-") >> num_char; num_expo_hex = set("pP") >> -set("+-") >> num_char; lj_num = -set("uU") >> set("lL") >> set("lL"); @@ -76,7 +76,7 @@ YueParser::YueParser() { seq({'.', +num_char, -num_expo}) }); - Cut = false_(); + cut = false_(); Seperator = true_(); empty_block_error = pl::user(true_(), [](const item_t& item) { @@ -84,15 +84,52 @@ YueParser::YueParser() { return false; }); - #define ensure(patt, finally) ((patt) >> (finally) | (finally) >> Cut) - #define key(str) (str >> not_(AlphaNum)) - #define disable_do(patt) (DisableDo >> ((patt) >> EnableDo | EnableDo >> Cut)) - #define disable_chain(patt) (DisableChain >> ((patt) >> EnableChain | EnableChain >> Cut)) - #define disable_do_chain_arg_table_block(patt) (DisableDoChainArgTableBlock >> ((patt) >> EnableDoChainArgTableBlock | EnableDoChainArgTableBlock >> Cut)) - #define disable_arg_table_block(patt) (DisableArgTableBlock >> ((patt) >> EnableArgTableBlock | EnableArgTableBlock >> Cut)) - #define body_with(str) (sel({key(str) >> Space >> (InBlock | Statement), InBlock, empty_block_error})) - #define opt_body_with(str) (key(str) >> Space >> (InBlock | Statement) | InBlock) - #define body (sel({InBlock, Statement, empty_block_error})) + #define ensure(patt, finally) ((patt) >> (finally) | (finally) >> cut) + + #define key(str) (str >> not_(alpha_num)) + + #define disable_do_rule(patt) ( \ + disable_do >> ( \ + (patt) >> enable_do | \ + enable_do >> cut \ + ) \ + ) + + #define disable_chain_rule(patt) ( \ + disable_chain >> ( \ + (patt) >> enable_chain | \ + enable_chain >> cut \ + ) \ + ) + + #define disable_do_chain_arg_table_block_rule(patt) ( \ + disable_do_chain_arg_table_block >> ( \ + (patt) >> enable_do_chain_arg_table_block | \ + enable_do_chain_arg_table_block >> cut \ + ) \ + ) + + #define disable_arg_table_block_rule(patt) ( \ + disable_arg_table_block >> ( \ + (patt) >> enable_arg_table_block | \ + enable_arg_table_block >> cut \ + ) \ + ) + + #define body_with(str) ( \ + sel({ \ + key(str) >> space >> (in_block | Statement), \ + in_block, \ + empty_block_error \ + }) \ + ) + + #define opt_body_with(str) ( \ + key(str) >> space >> (in_block | Statement) | \ + in_block \ + ) + + #define body (sel({in_block, Statement, empty_block_error})) Variable = pl::user(Name, [](const item_t& item) { State* st = reinterpret_cast(item.user_data); @@ -124,16 +161,16 @@ YueParser::YueParser() { return it != LuaKeywords.end(); }); - self = '@'; - self_name = '@' >> Name; - self_class = "@@"; - self_class_name = "@@" >> Name; + Self = '@'; + SelfName = '@' >> Name; + SelfClass = "@@"; + SelfClassName = "@@" >> Name; - SelfName = sel({self_class_name, self_class, self_name, self}); - KeyName = SelfName | Name; + SelfItem = sel({SelfClassName, SelfClass, SelfName, Self}); + KeyName = SelfItem | Name; VarArg = "..."; - check_indent = pl::user(Indent, [](const item_t& item) { + check_indent = pl::user(indent, [](const item_t& item) { int indent = 0; for (input_it i = item.begin->m_it; i != item.end->m_it; ++i) { switch (*i) { @@ -144,9 +181,9 @@ YueParser::YueParser() { State* st = reinterpret_cast(item.user_data); return st->indents.top() == indent; }); - CheckIndent = and_(check_indent); + check_indent_match = and_(check_indent); - advance = pl::user(Indent, [](const item_t& item) { + advance = pl::user(indent, [](const item_t& item) { int indent = 0; for (input_it i = item.begin->m_it; i != item.end->m_it; ++i) { switch (*i) { @@ -162,9 +199,9 @@ YueParser::YueParser() { } return false; }); - Advance = and_(advance); + advance_match = and_(advance); - push_indent = pl::user(Indent, [](const item_t& item) { + push_indent = pl::user(indent, [](const item_t& item) { int indent = 0; for (input_it i = item.begin->m_it; i != item.end->m_it; ++i) { switch (*i) { @@ -176,152 +213,152 @@ YueParser::YueParser() { st->indents.push(indent); return true; }); - PushIndent = and_(push_indent); + push_indent_match = and_(push_indent); - PreventIndent = pl::user(true_(), [](const item_t& item) { + prevent_indent = pl::user(true_(), [](const item_t& item) { State* st = reinterpret_cast(item.user_data); st->indents.push(-1); return true; }); - PopIndent = pl::user(true_(), [](const item_t& item) { + pop_indent = pl::user(true_(), [](const item_t& item) { State* st = reinterpret_cast(item.user_data); st->indents.pop(); return true; }); - InBlock = +SpaceBreak >> Advance >> ensure(Block, PopIndent); + in_block = +space_break >> advance_match >> ensure(Block, pop_indent); - local_flag = sel({'*', '^'}); - local_values = NameList >> -(Space >> '=' >> Space >> (TableBlock | ExpListLow)); - Local = key("local") >> Space >> (local_flag | local_values); + LocalFlag = sel({'*', '^'}); + LocalValues = NameList >> -(space >> '=' >> space >> (TableBlock | ExpListLow)); + Local = key("local") >> space >> (LocalFlag | LocalValues); - const_attrib = key("const"); - close_attrib = key("close"); - local_const_item = sel({Variable, simple_table, TableLit}); + ConstAttrib = key("const"); + CloseAttrib = key("close"); + local_const_item = sel({Variable, SimpleTable, TableLit}); LocalAttrib = ( - const_attrib >> Seperator >> Space >> local_const_item >> *(Space >> ',' >> Space >> local_const_item) | - close_attrib >> Seperator >> Space >> Variable >> *(Space >> ',' >> Space >> Variable) - ) >> Space >> Assign; + ConstAttrib >> Seperator >> space >> local_const_item >> *(space >> ',' >> space >> local_const_item) | + CloseAttrib >> Seperator >> space >> Variable >> *(space >> ',' >> space >> Variable) + ) >> space >> Assign; - colon_import_name = '\\' >> Space >> Variable; - ImportName = colon_import_name | Variable; - ImportNameList = Seperator >> *SpaceBreak >> Space >> ImportName >> *((+SpaceBreak | Space >> ',' >> *SpaceBreak) >> Space >> ImportName); - ImportFrom = ImportNameList >> *SpaceBreak >> Space >> key("from") >> Space >> Exp; + ColonImportName = '\\' >> space >> Variable; + import_name = ColonImportName | Variable; + import_name_list = Seperator >> *space_break >> space >> import_name >> *((+space_break | space >> ',' >> *space_break) >> space >> import_name); + ImportFrom = import_name_list >> *space_break >> space >> key("from") >> space >> Exp; - import_literal_inner = sel({range('a', 'z'), range('A', 'Z'), set("_-")}) >> *(AlphaNum | '-'); - import_literal_chain = Seperator >> import_literal_inner >> *('.' >> import_literal_inner); + ImportLiteralInner = sel({range('a', 'z'), range('A', 'Z'), set("_-")}) >> *(alpha_num | '-'); + import_literal_chain = Seperator >> ImportLiteralInner >> *('.' >> ImportLiteralInner); ImportLiteral = sel({ '\'' >> import_literal_chain >> '\'', '"' >> import_literal_chain >> '"' }); - macro_name_pair = MacroName >> ':' >> Space >> MacroName; - import_all_macro = '$'; - ImportTabItem = sel({ - variable_pair, - normal_pair, + MacroNamePair = MacroName >> ':' >> space >> MacroName; + ImportAllMacro = '$'; + import_tab_item = sel({ + VariablePair, + NormalPair, ':' >> MacroName, - macro_name_pair, - import_all_macro, - meta_variable_pair, - meta_normal_pair, + MacroNamePair, + ImportAllMacro, + MetaVariablePair, + MetaNormalPair, Exp }); - ImportTabList = ImportTabItem >> *(Space >> ',' >> Space >> ImportTabItem); - ImportTabLine = ( - PushIndent >> (Space >> ImportTabList >> PopIndent | PopIndent) - ) | Space; - import_tab_lines = SpaceBreak >> ImportTabLine >> *(-(Space >> ',') >> SpaceBreak >> ImportTabLine) >> -(Space >> ','); + import_tab_list = import_tab_item >> *(space >> ',' >> space >> import_tab_item); + import_tab_line = ( + push_indent_match >> (space >> import_tab_list >> pop_indent | pop_indent) + ) | space; + import_tab_lines = space_break >> import_tab_line >> *(-(space >> ',') >> space_break >> import_tab_line) >> -(space >> ','); ImportTabLit = seq({ '{', Seperator, - -(Space >> ImportTabList), - -(Space >> ','), + -(space >> import_tab_list), + -(space >> ','), -import_tab_lines, - White, + white, '}' }) | seq({ - Seperator, KeyValue, *(Space >> ',' >> Space >> KeyValue) + Seperator, key_value, *(space >> ',' >> space >> key_value) }); - ImportAs = ImportLiteral >> -(Space >> key("as") >> Space >> sel({ImportTabLit, Variable, import_all_macro})); + ImportAs = ImportLiteral >> -(space >> key("as") >> space >> sel({ImportTabLit, Variable, ImportAllMacro})); - Import = key("import") >> Space >> (ImportAs | ImportFrom); + Import = key("import") >> space >> (ImportAs | ImportFrom); Label = "::" >> LabelName >> "::"; - Goto = key("goto") >> Space >> LabelName; + Goto = key("goto") >> space >> LabelName; - ShortTabAppending = "[]" >> Space >> Assign; + ShortTabAppending = "[]" >> space >> Assign; - BreakLoop = sel({"break", "continue"}) >> not_(AlphaNum); + BreakLoop = sel({"break", "continue"}) >> not_(alpha_num); - Return = key("return") >> -(Space >> (TableBlock | ExpListLow)); + Return = key("return") >> -(space >> (TableBlock | ExpListLow)); - WithExp = ExpList >> -(Space >> Assign); + with_exp = ExpList >> -(space >> Assign); - With = key("with") >> -existential_op >> Space >> disable_do_chain_arg_table_block(WithExp) >> Space >> body_with("do"); - SwitchCase = key("when") >> disable_chain(disable_arg_table_block(SwitchList)) >> Space >> body_with("then"); - SwitchElse = key("else") >> Space >> body; + With = key("with") >> -ExistentialOp >> space >> disable_do_chain_arg_table_block_rule(with_exp) >> space >> body_with("do"); + SwitchCase = key("when") >> disable_chain_rule(disable_arg_table_block_rule(SwitchList)) >> space >> body_with("then"); + switch_else = key("else") >> space >> body; - SwitchBlock = - *(Break >> *EmptyLine >> CheckIndent >> Space >> SwitchCase) >> - -(Break >> *EmptyLine >> CheckIndent >> Space >> SwitchElse); + switch_block = + *(line_break >> *empty_line >> check_indent_match >> space >> SwitchCase) >> + -(line_break >> *empty_line >> check_indent_match >> space >> switch_else); - exp_not_tab = not_(simple_table | TableLit) >> Space >> Exp; + exp_not_tab = not_(SimpleTable | TableLit) >> space >> Exp; SwitchList = Seperator >> ( - and_(simple_table | TableLit) >> Space >> Exp | - exp_not_tab >> *(Space >> ',' >> exp_not_tab) + and_(SimpleTable | TableLit) >> space >> Exp | + exp_not_tab >> *(space >> ',' >> exp_not_tab) ); - Switch = key("switch") >> Space >> Exp >> - Space >> Seperator >> ( - SwitchCase >> Space >> ( - Break >> *EmptyLine >> CheckIndent >> Space >> SwitchCase >> SwitchBlock | - *(Space >> SwitchCase) >> -(Space >> SwitchElse) + Switch = key("switch") >> space >> Exp >> + space >> Seperator >> ( + SwitchCase >> space >> ( + line_break >> *empty_line >> check_indent_match >> space >> SwitchCase >> switch_block | + *(space >> SwitchCase) >> -(space >> switch_else) ) | - SpaceBreak >> *EmptyLine >> Advance >> Space >> SwitchCase >> SwitchBlock >> PopIndent - ) >> SwitchBlock; + space_break >> *empty_line >> advance_match >> space >> SwitchCase >> switch_block >> pop_indent + ) >> switch_block; - assignment = ExpList >> Space >> Assign; - IfCond = disable_chain(disable_arg_table_block(assignment | Exp)); - IfElseIf = -(Break >> *EmptyLine >> CheckIndent) >> Space >> key("elseif") >> Space >> IfCond >> Space >> body_with("then"); - IfElse = -(Break >> *EmptyLine >> CheckIndent) >> Space >> key("else") >> Space >> body; - IfType = sel({"if", "unless"}) >> not_(AlphaNum); - If = seq({IfType, Space, IfCond, Space, opt_body_with("then"), *IfElseIf, -IfElse}); + Assignment = ExpList >> space >> Assign; + IfCond = disable_chain_rule(disable_arg_table_block_rule(Assignment | Exp)); + if_else_if = -(line_break >> *empty_line >> check_indent_match) >> space >> key("elseif") >> space >> IfCond >> space >> body_with("then"); + if_else = -(line_break >> *empty_line >> check_indent_match) >> space >> key("else") >> space >> body; + IfType = sel({"if", "unless"}) >> not_(alpha_num); + If = seq({IfType, space, IfCond, space, opt_body_with("then"), *if_else_if, -if_else}); - WhileType = sel({"while", "until"}) >> not_(AlphaNum); - While = WhileType >> Space >> disable_do_chain_arg_table_block(Exp) >> Space >> opt_body_with("do"); - Repeat = seq({key("repeat"), Space, Body, Break, *EmptyLine, CheckIndent, Space, key("until"), Space, Exp}); + WhileType = sel({"while", "until"}) >> not_(alpha_num); + While = WhileType >> space >> disable_do_chain_arg_table_block_rule(Exp) >> space >> opt_body_with("do"); + Repeat = seq({key("repeat"), space, Body, line_break, *empty_line, check_indent_match, space, key("until"), space, Exp}); - for_step_value = ',' >> Space >> Exp; - for_args = Variable >> Space >> '=' >> Space >> Exp >> Space >> ',' >> Space >> Exp >> Space >> -for_step_value; + ForStepValue = ',' >> space >> Exp; + for_args = Variable >> space >> '=' >> space >> Exp >> space >> ',' >> space >> Exp >> space >> -ForStepValue; - For = key("for") >> Space >> disable_do_chain_arg_table_block(for_args) >> Space >> opt_body_with("do"); + For = key("for") >> space >> disable_do_chain_arg_table_block_rule(for_args) >> space >> opt_body_with("do"); - for_in = star_exp | ExpList; + for_in = StarExp | ExpList; - ForEach = key("for") >> Space >> AssignableNameList >> Space >> key("in") >> Space >> - disable_do_chain_arg_table_block(for_in) >> Space >> opt_body_with("do"); + ForEach = key("for") >> space >> AssignableNameList >> space >> key("in") >> space >> + disable_do_chain_arg_table_block_rule(for_in) >> space >> opt_body_with("do"); Do = pl::user(key("do"), [](const item_t& item) { State* st = reinterpret_cast(item.user_data); return st->noDoStack.empty() || !st->noDoStack.top(); - }) >> Space >> Body; + }) >> space >> Body; - DisableDo = pl::user(true_(), [](const item_t& item) { + disable_do = pl::user(true_(), [](const item_t& item) { State* st = reinterpret_cast(item.user_data); st->noDoStack.push(true); return true; }); - EnableDo = pl::user(true_(), [](const item_t& item) { + enable_do = pl::user(true_(), [](const item_t& item) { State* st = reinterpret_cast(item.user_data); st->noDoStack.pop(); return true; }); - DisableDoChainArgTableBlock = pl::user(true_(), [](const item_t& item) { + disable_do_chain_arg_table_block = pl::user(true_(), [](const item_t& item) { State* st = reinterpret_cast(item.user_data); st->noDoStack.push(true); st->noChainBlockStack.push(true); @@ -329,7 +366,7 @@ YueParser::YueParser() { return true; }); - EnableDoChainArgTableBlock = pl::user(true_(), [](const item_t& item) { + enable_do_chain_arg_table_block = pl::user(true_(), [](const item_t& item) { State* st = reinterpret_cast(item.user_data); st->noDoStack.pop(); st->noChainBlockStack.pop(); @@ -337,110 +374,111 @@ YueParser::YueParser() { return true; }); - DisableArgTableBlock = pl::user(true_(), [](const item_t& item) { + disable_arg_table_block = pl::user(true_(), [](const item_t& item) { State* st = reinterpret_cast(item.user_data); st->noTableBlockStack.push(true); return true; }); - EnableArgTableBlock = pl::user(true_(), [](const item_t& item) { + enable_arg_table_block = pl::user(true_(), [](const item_t& item) { State* st = reinterpret_cast(item.user_data); st->noTableBlockStack.pop(); return true; }); - catch_block = Break >> *EmptyLine >> CheckIndent >> Space >> key("catch") >> Space >> Variable >> Space >> InBlock; - Try = key("try") >> Space >> (InBlock | Exp) >> -catch_block; + CatchBlock = line_break >> *empty_line >> check_indent_match >> space >> key("catch") >> space >> Variable >> space >> in_block; + Try = key("try") >> space >> (in_block | Exp) >> -CatchBlock; - Comprehension = '[' >> not_('[') >> Space >> Exp >> Space >> CompInner >> Space >> ']'; - comp_value = ',' >> Space >> Exp; - TblComprehension = '{' >> Space >> Exp >> Space >> -(comp_value >> Space) >> CompInner >> Space >> '}'; + Comprehension = '[' >> not_('[') >> space >> Exp >> space >> CompInner >> space >> ']'; + CompValue = ',' >> space >> Exp; + TblComprehension = '{' >> space >> Exp >> space >> -(CompValue >> space) >> CompInner >> space >> '}'; - CompInner = Seperator >> (CompForEach | CompFor) >> *(Space >> CompClause); - star_exp = '*' >> Space >> Exp; - CompForEach = key("for") >> Space >> AssignableNameList >> Space >> key("in") >> Space >> (star_exp | Exp); - CompFor = key("for") >> Space >> Variable >> Space >> '=' >> Space >> Exp >> Space >> ',' >> Space >> Exp >> -for_step_value; - CompClause = sel({CompFor, CompForEach, key("when") >> Space >> Exp}); + CompInner = Seperator >> (CompForEach | CompFor) >> *(space >> comp_clause); + StarExp = '*' >> space >> Exp; + CompForEach = key("for") >> space >> AssignableNameList >> space >> key("in") >> space >> (StarExp | Exp); + CompFor = key("for") >> space >> Variable >> space >> '=' >> space >> Exp >> space >> ',' >> space >> Exp >> -ForStepValue; + comp_clause = sel({CompFor, CompForEach, key("when") >> space >> Exp}); - Assign = '=' >> Space >> Seperator >> sel({ + Assign = '=' >> space >> Seperator >> sel({ With, If, Switch, TableBlock, - Exp >> *(Space >> set(",;") >> Space >> Exp) + Exp >> *(space >> set(",;") >> space >> Exp) }); - update_op = sel({ + UpdateOp = sel({ "..", "//", "or", "and", ">>", "<<", "??", set("+-*/%&|") }); - Update = update_op >> '=' >> Space >> Exp; + Update = UpdateOp >> '=' >> space >> Exp; - Assignable = sel({AssignableChain, Variable, SelfName}); + Assignable = sel({AssignableChain, Variable, SelfItem}); - unary_value = +(unary_operator >> Space) >> Value; + UnaryValue = +(UnaryOperator >> space) >> Value; - ExponentialOperator = '^'; - expo_value = seq({ExponentialOperator, *SpaceBreak, Space, Value}); - expo_exp = Value >> *(Space >> expo_value); + exponential_operator = '^'; + expo_value = seq({exponential_operator, *space_break, space, Value}); + expo_exp = Value >> *(space >> expo_value); - unary_operator = sel({ + UnaryOperator = sel({ '-' >> not_(set(">=") | space_one), '#', '~' >> not_('=' | space_one), - "not" >> not_(AlphaNum) + "not" >> not_(alpha_num) }); - unary_exp = *(unary_operator >> Space) >> expo_exp; + UnaryExp = *(UnaryOperator >> space) >> expo_exp; - PipeOperator = "|>"; - pipe_value = seq({PipeOperator, *SpaceBreak, Space, unary_exp}); - pipe_exp = unary_exp >> *(Space >> pipe_value); + pipe_operator = "|>"; + pipe_value = seq({pipe_operator, *space_break, space, UnaryExp}); + pipe_exp = UnaryExp >> *(space >> pipe_value); BinaryOperator = sel({ - "or" >> not_(AlphaNum), - "and" >> not_(AlphaNum), + "or" >> not_(alpha_num), + "and" >> not_(alpha_num), "<=", ">=", "~=", "!=", "==", "..", "<<", ">>", "//", set("+-*/%><|&~") }); - exp_op_value = seq({BinaryOperator, *SpaceBreak, Space, pipe_exp}); - Exp = seq({Seperator, pipe_exp, *(Space >> exp_op_value), -(Space >> "??" >> Space >> Exp)}); + ExpOpValue = seq({BinaryOperator, *space_break, space, pipe_exp}); + Exp = seq({Seperator, pipe_exp, *(space >> ExpOpValue), -(space >> "??" >> space >> Exp)}); - DisableChain = pl::user(true_(), [](const item_t& item) { + disable_chain = pl::user(true_(), [](const item_t& item) { State* st = reinterpret_cast(item.user_data); st->noChainBlockStack.push(true); return true; }); - EnableChain = pl::user(true_(), [](const item_t& item) { + enable_chain = pl::user(true_(), [](const item_t& item) { State* st = reinterpret_cast(item.user_data); st->noChainBlockStack.pop(); return true; }); - chain_line = seq({CheckIndent, Space, chain_dot_chain | ColonChain, -InvokeArgs}); + chain_line = seq({check_indent_match, space, chain_dot_chain | colon_chain, -InvokeArgs}); chain_block = pl::user(true_(), [](const item_t& item) { State* st = reinterpret_cast(item.user_data); return st->noChainBlockStack.empty() || !st->noChainBlockStack.top(); - }) >> +SpaceBreak >> Advance >> ensure( - chain_line >> *(+SpaceBreak >> chain_line), PopIndent); + }) >> +space_break >> advance_match >> ensure( + chain_line >> *(+space_break >> chain_line), pop_indent); ChainValue = seq({ Seperator, - Chain, - -existential_op, + chain, + -ExistentialOp, -(InvokeArgs | chain_block), - -table_appending_op + -TableAppendingOp }); - simple_table = seq({Seperator, KeyValue, *(Space >> ',' >> Space >> KeyValue)}); - Value = sel({SimpleValue, simple_table, ChainValue, String}); + SimpleTable = seq({Seperator, key_value, *(space >> ',' >> space >> key_value)}); + Value = sel({SimpleValue, SimpleTable, ChainValue, String}); - single_string_inner = '\\' >> set("'\\") | not_('\'') >> Any; + single_string_inner = '\\' >> set("'\\") | not_('\'') >> any_char; SingleString = '\'' >> *single_string_inner >> '\''; - interp = "#{" >> Space >> Exp >> Space >> '}'; - double_string_plain = '\\' >> set("\"\\") | not_('"') >> Any; - double_string_inner = +(not_(interp) >> double_string_plain); - double_string_content = double_string_inner | interp; - DoubleString = '"' >> Seperator >> *double_string_content >> '"'; + + interp = "#{" >> space >> Exp >> space >> '}'; + double_string_plain = '\\' >> set("\"\\") | not_('"') >> any_char; + DoubleStringInner = +(not_(interp) >> double_string_plain); + DoubleStringContent = DoubleStringInner | interp; + DoubleString = '"' >> Seperator >> *DoubleStringContent >> '"'; String = sel({DoubleString, SingleString, LuaString}); lua_string_open = '[' >> *expr('=') >> '['; @@ -459,143 +497,143 @@ YueParser::YueParser() { return st->stringOpen == count; }); - LuaStringContent = *(not_(LuaStringClose) >> Any); + LuaStringContent = *(not_(LuaStringClose) >> any_char); - LuaString = LuaStringOpen >> -Break >> LuaStringContent >> LuaStringClose; + LuaString = LuaStringOpen >> -line_break >> LuaStringContent >> LuaStringClose; - Parens = seq({'(', *SpaceBreak, Space, Exp, *SpaceBreak, Space, ')'}); - Callable = sel({Variable, SelfName, MacroName, VarArg, Parens}); - FnArgsExpList = Space >> Exp >> Space >> *seq({Break | ',', White, Exp}); + Parens = seq({'(', *space_break, space, Exp, *space_break, space, ')'}); + Callable = sel({Variable, SelfItem, MacroName, VarArg, Parens}); + fn_args_exp_list = space >> Exp >> space >> *seq({line_break | ',', white, Exp}); - FnArgs = sel({ - seq({'(', *SpaceBreak, -FnArgsExpList, *SpaceBreak, Space, ')'}), - seq({Space, '!', not_('=')}) + fn_args = sel({ + seq({'(', *space_break, -fn_args_exp_list, *space_break, space, ')'}), + seq({space, '!', not_('=')}) }); - meta_index = sel({Name, Index, String}); - Metatable = '<' >> Space >> '>'; - Metamethod = '<' >> Space >> meta_index >> Space >> '>'; + meta_index = sel({Name, index, String}); + Metatable = '<' >> space >> '>'; + Metamethod = '<' >> space >> meta_index >> space >> '>'; - existential_op = '?' >> not_('?'); - table_appending_op = "[]"; + ExistentialOp = '?' >> not_('?'); + TableAppendingOp = "[]"; chain_call = seq({ Callable, - -existential_op, - -ChainItems + -ExistentialOp, + -chain_items }) | seq({ String, - ChainItems + chain_items }); - chain_index_chain = seq({Index, -existential_op, -ChainItems}); - chain_dot_chain = seq({DotChainItem, -existential_op, -ChainItems}); + chain_index_chain = seq({index, -ExistentialOp, -chain_items}); + chain_dot_chain = seq({DotChainItem, -ExistentialOp, -chain_items}); - Chain = sel({chain_call, chain_dot_chain, ColonChain, chain_index_chain}); + chain = sel({chain_call, chain_dot_chain, colon_chain, chain_index_chain}); chain_call_list = seq({ Callable, - -existential_op, - ChainItems + -ExistentialOp, + chain_items }) | seq({ String, - ChainItems + chain_items }); - ChainList = sel({chain_call_list, chain_dot_chain, ColonChain, chain_index_chain}); + chain_list = sel({chain_call_list, chain_dot_chain, colon_chain, chain_index_chain}); - AssignableChain = Seperator >> ChainList; + AssignableChain = Seperator >> chain_list; - chain_with_colon = +ChainItem >> -ColonChain; - ChainItems = chain_with_colon | ColonChain; + chain_with_colon = +chain_item >> -colon_chain; + chain_items = chain_with_colon | colon_chain; - Index = seq({'[', not_('['), Space, Exp, Space, ']'}); - ChainItem = sel({ - Invoke >> -existential_op, - DotChainItem >> -existential_op, + index = seq({'[', not_('['), space, Exp, space, ']'}); + chain_item = sel({ + Invoke >> -ExistentialOp, + DotChainItem >> -ExistentialOp, Slice, - Index >> -existential_op + index >> -ExistentialOp }); DotChainItem = '.' >> sel({Name, Metatable, Metamethod}); ColonChainItem = sel({'\\', "::"}) >> sel({LuaKeyword, Name, Metamethod}); - invoke_chain = Invoke >> -existential_op >> -ChainItems; - ColonChain = ColonChainItem >> -existential_op >> -invoke_chain; + invoke_chain = Invoke >> -ExistentialOp >> -chain_items; + colon_chain = ColonChainItem >> -ExistentialOp >> -invoke_chain; - default_value = true_(); + DefaultValue = true_(); Slice = seq({ '[', not_('['), - Space, Exp | default_value, - Space, ',', - Space, Exp | default_value, - Space, ',' >> Space >> Exp | default_value, - Space, ']' + space, Exp | DefaultValue, + space, ',', + space, Exp | DefaultValue, + space, ',' >> space >> Exp | DefaultValue, + space, ']' }); Invoke = Seperator >> sel({ - FnArgs, + fn_args, SingleString, DoubleString, and_('[') >> LuaString, and_('{') >> TableLit }); - SpreadExp = "..." >> Space >> Exp; + SpreadExp = "..." >> space >> Exp; - TableValue = sel({ - variable_pair_def, - normal_pair_def, - meta_variable_pair_def, - meta_normal_pair_def, + table_value = sel({ + VariablePairDef, + NormalPairDef, + MetaVariablePairDef, + MetaNormalPairDef, SpreadExp, - normal_def + NormalDef }); - table_lit_lines = SpaceBreak >> TableLitLine >> *(-(Space >> ',') >> SpaceBreak >> TableLitLine) >> -(Space >> ','); + table_lit_lines = space_break >> table_lit_line >> *(-(space >> ',') >> space_break >> table_lit_line) >> -(space >> ','); TableLit = seq({ - Space, '{', Seperator, - -(Space >> TableValueList), - -(Space >> ','), + space, '{', Seperator, + -(space >> table_value_list), + -(space >> ','), -table_lit_lines, - White, '}' + white, '}' }); - TableValueList = TableValue >> *(Space >> ',' >> Space >> TableValue); + table_value_list = table_value >> *(space >> ',' >> space >> table_value); - TableLitLine = ( - PushIndent >> (Space >> TableValueList >> PopIndent | PopIndent) + table_lit_line = ( + push_indent_match >> (space >> table_value_list >> pop_indent | pop_indent) ) | ( - Space + space ); - TableBlockInner = Seperator >> KeyValueLine >> *(+SpaceBreak >> KeyValueLine); - TableBlock = +SpaceBreak >> Advance >> ensure(TableBlockInner, PopIndent); - TableBlockIndent = '*' >> Seperator >> disable_arg_table_block( - Space >> KeyValueList >> -(Space >> ',') >> - -(+SpaceBreak >> Advance >> Space >> ensure(KeyValueList >> -(Space >> ',') >> *(+SpaceBreak >> KeyValueLine), PopIndent))); + table_block_inner = Seperator >> key_value_line >> *(+space_break >> key_value_line); + TableBlock = +space_break >> advance_match >> ensure(table_block_inner, pop_indent); + TableBlockIndent = '*' >> Seperator >> disable_arg_table_block_rule( + space >> key_value_list >> -(space >> ',') >> + -(+space_break >> advance_match >> space >> ensure(key_value_list >> -(space >> ',') >> *(+space_break >> key_value_line), pop_indent))); - class_member_list = Seperator >> KeyValue >> *(Space >> ',' >> Space >> KeyValue); - ClassLine = CheckIndent >> Space >> (class_member_list | Statement) >> -(Space >> ','); - ClassBlock = seq({+SpaceBreak, Advance, Seperator, ClassLine, *(+SpaceBreak >> ClassLine), PopIndent}); + ClassMemberList = Seperator >> key_value >> *(space >> ',' >> space >> key_value); + class_line = check_indent_match >> space >> (ClassMemberList | Statement) >> -(space >> ','); + ClassBlock = seq({+space_break, advance_match, Seperator, class_line, *(+space_break >> class_line), pop_indent}); ClassDecl = seq({ key("class"), not_(':'), - disable_arg_table_block(seq({ - -(Space >> Assignable), - -seq({Space, key("extends"), PreventIndent, Space, ensure(Exp, PopIndent)}), - -seq({Space, key("using"), PreventIndent, Space, ensure(ExpList, PopIndent)}) + disable_arg_table_block_rule(seq({ + -(space >> Assignable), + -seq({space, key("extends"), prevent_indent, space, ensure(Exp, pop_indent)}), + -seq({space, key("using"), prevent_indent, space, ensure(ExpList, pop_indent)}) })), -ClassBlock }); - global_values = NameList >> -(Space >> '=' >> Space >> (TableBlock | ExpListLow)); - global_op = sel({'*', '^'}); - Global = key("global") >> Space >> sel({ClassDecl, global_op, global_values}); + GlobalValues = NameList >> -(space >> '=' >> space >> (TableBlock | ExpListLow)); + GlobalOp = sel({'*', '^'}); + Global = key("global") >> space >> sel({ClassDecl, GlobalOp, GlobalValues}); - export_default = key("default"); + ExportDefault = key("default"); Export = pl::user(key("export"), [](const item_t& item) { State* st = reinterpret_cast(item.user_data); st->exportCount++; return true; - }) >> (pl::user(Space >> export_default >> Space >> Exp, [](const item_t& item) { + }) >> (pl::user(space >> ExportDefault >> space >> Exp, [](const item_t& item) { State* st = reinterpret_cast(item.user_data); if (st->exportDefault) { throw ParserError("export default has already been declared", *item.begin, *item.end); @@ -606,99 +644,99 @@ YueParser::YueParser() { st->exportDefault = true; return true; }) - | (not_(Space >> export_default) >> pl::user(true_(), [](const item_t& item) { + | (not_(space >> ExportDefault) >> pl::user(true_(), [](const item_t& item) { State* st = reinterpret_cast(item.user_data); if (st->exportDefault && st->exportCount > 1) { throw ParserError("can not export any more items when 'export default' is declared", *item.begin, *item.end); } return true; - }) >> Space >> ExpList >> -(Space >> Assign)) - | Space >> pl::user(Macro, [](const item_t& item) { + }) >> space >> ExpList >> -(space >> Assign)) + | space >> pl::user(Macro, [](const item_t& item) { State* st = reinterpret_cast(item.user_data); st->exportMacro = true; return true; - })) >> not_(Space >> statement_appendix); + })) >> not_(space >> StatementAppendix); - variable_pair = ':' >> Variable; + VariablePair = ':' >> Variable; - normal_pair = seq({ + NormalPair = seq({ sel({ KeyName, - seq({'[', not_('['), Space, Exp, Space, ']'}), + seq({'[', not_('['), space, Exp, space, ']'}), String }), - ':', not_(':'), Space, - sel({Exp, TableBlock, +SpaceBreak >> Space >> Exp}) + ':', not_(':'), space, + sel({Exp, TableBlock, +space_break >> space >> Exp}) }); - meta_variable_pair = ":<" >> Space >> Variable >> Space >> '>'; + MetaVariablePair = ":<" >> space >> Variable >> space >> '>'; - meta_normal_pair = '<' >> Space >> -meta_index >> Space >> ">:" >> Space >> - sel({Exp, TableBlock, +(SpaceBreak) >> Space >> Exp}); + MetaNormalPair = '<' >> space >> -meta_index >> space >> ">:" >> space >> + sel({Exp, TableBlock, +space_break >> space >> Exp}); - destruct_def = -seq({Space, '=', Space, Exp}); - variable_pair_def = variable_pair >> destruct_def; - normal_pair_def = normal_pair >> destruct_def; - meta_variable_pair_def = meta_variable_pair >> destruct_def; - meta_normal_pair_def = meta_normal_pair >> destruct_def; - normal_def = Exp >> Seperator >> destruct_def; + destruct_def = -seq({space, '=', space, Exp}); + VariablePairDef = VariablePair >> destruct_def; + NormalPairDef = NormalPair >> destruct_def; + MetaVariablePairDef = MetaVariablePair >> destruct_def; + MetaNormalPairDef = MetaNormalPair >> destruct_def; + NormalDef = Exp >> Seperator >> destruct_def; - KeyValue = sel({ - variable_pair, - normal_pair, - meta_variable_pair, - meta_normal_pair + key_value = sel({ + VariablePair, + NormalPair, + MetaVariablePair, + MetaNormalPair }); - KeyValueList = KeyValue >> *(Space >> ',' >> Space >> KeyValue); - KeyValueLine = CheckIndent >> Space >> sel({ - KeyValueList >> -(Space >> ','), + key_value_list = key_value >> *(space >> ',' >> space >> key_value); + key_value_line = check_indent_match >> space >> sel({ + key_value_list >> -(space >> ','), TableBlockIndent, - '*' >> Space >> sel({SpreadExp, Exp, TableBlock}) + '*' >> space >> sel({SpreadExp, Exp, TableBlock}) }); - FnArgDef = (Variable | SelfName >> -existential_op) >> -(Space >> '=' >> Space >> Exp); + FnArgDef = (Variable | SelfItem >> -ExistentialOp) >> -(space >> '=' >> space >> Exp); FnArgDefList = Seperator >> ( seq({ FnArgDef, - *seq({Space, ',' | Break, White, FnArgDef}), - -seq({Space, ',' | Break, White, VarArg}) + *seq({space, ',' | line_break, white, FnArgDef}), + -seq({space, ',' | line_break, white, VarArg}) }) | VarArg ); - outer_var_shadow = key("using") >> Space >> (NameList | key("nil")); + OuterVarShadow = key("using") >> space >> (NameList | key("nil")); - FnArgsDef = seq({'(', White, -FnArgDefList, -(Space >> outer_var_shadow), White, ')'}); - fn_arrow = sel({"->", "=>"}); - FunLit = seq({-FnArgsDef, Space, fn_arrow, -(Space >> Body)}); + FnArgsDef = seq({'(', white, -FnArgDefList, -(space >> OuterVarShadow), white, ')'}); + FnArrow = sel({"->", "=>"}); + FunLit = seq({-FnArgsDef, space, FnArrow, -(space >> Body)}); MacroName = '$' >> Name; - macro_args_def = '(' >> White >> -FnArgDefList >> White >> ')'; - MacroLit = -(macro_args_def >> Space) >> "->" >> Space >> Body; - Macro = key("macro") >> Space >> Name >> Space >> '=' >> Space >> MacroLit; - MacroInPlace = '$' >> Space >> "->" >> Space >> Body; + macro_args_def = '(' >> white >> -FnArgDefList >> white >> ')'; + MacroLit = -(macro_args_def >> space) >> "->" >> space >> Body; + Macro = key("macro") >> space >> Name >> space >> '=' >> space >> MacroLit; + MacroInPlace = '$' >> space >> "->" >> space >> Body; - NameList = Seperator >> Variable >> *(Space >> ',' >> Space >> Variable); + NameList = Seperator >> Variable >> *(space >> ',' >> space >> Variable); NameOrDestructure = Variable | TableLit; - AssignableNameList = Seperator >> NameOrDestructure >> *(Space >> ',' >> Space >> NameOrDestructure); + AssignableNameList = Seperator >> NameOrDestructure >> *(space >> ',' >> space >> NameOrDestructure); - fn_arrow_back = '<' >> set("-="); - Backcall = seq({-(FnArgsDef >> Space), fn_arrow_back, Space, ChainValue}); + FnArrowBack = '<' >> set("-="); + Backcall = seq({-(FnArgsDef >> space), FnArrowBack, space, ChainValue}); PipeBody = seq({ Seperator, - PipeOperator, - Space, - unary_exp, - *seq({+SpaceBreak, CheckIndent, Space, PipeOperator, Space, unary_exp}) + pipe_operator, + space, + UnaryExp, + *seq({+space_break, check_indent_match, space, pipe_operator, space, UnaryExp}) }); - ExpList = Seperator >> Exp >> *(Space >> ',' >> Space >> Exp); - ExpListLow = Seperator >> Exp >> *(Space >> set(",;") >> Space >> Exp); + ExpList = Seperator >> Exp >> *(space >> ',' >> space >> Exp); + ExpListLow = Seperator >> Exp >> *(space >> set(",;") >> space >> Exp); - ArgLine = CheckIndent >> Space >> Exp >> *(Space >> ',' >> Space >> Exp); - ArgBlock = ArgLine >> *(Space >> ',' >> SpaceBreak >> ArgLine) >> PopIndent; + arg_line = check_indent_match >> space >> Exp >> *(space >> ',' >> space >> Exp); + arg_block = arg_line >> *(space >> ',' >> space_break >> arg_line) >> pop_indent; arg_table_block = pl::user(true_(), [](const item_t& item) { State* st = reinterpret_cast(item.user_data); @@ -708,38 +746,38 @@ YueParser::YueParser() { invoke_args_with_table = ',' >> ( TableBlock | - SpaceBreak >> Advance >> ArgBlock >> -arg_table_block + space_break >> advance_match >> arg_block >> -arg_table_block ) | arg_table_block; - leading_spaces_error = pl::user(+space_one >> '(' >> Space >> Exp >> +(Space >> ',' >> Space >> Exp) >> Space >> ')', [](const item_t& item) { + leading_spaces_error = pl::user(+space_one >> '(' >> space >> Exp >> +(space >> ',' >> space >> Exp) >> space >> ')', [](const item_t& item) { throw ParserError("write invoke arguments in parentheses without leading spaces or just leading spaces without parentheses", *item.begin, *item.end); return false; }); InvokeArgs = - not_(set("-~")) >> Space >> Seperator >> + not_(set("-~")) >> space >> Seperator >> sel({ - Exp >> *(Space >> ',' >> Space >> Exp) >> -(Space >> invoke_args_with_table), + Exp >> *(space >> ',' >> space >> Exp) >> -(space >> invoke_args_with_table), arg_table_block, leading_spaces_error }); - const_value = sel({"nil", "true", "false"}) >> not_(AlphaNum); + ConstValue = sel({"nil", "true", "false"}) >> not_(alpha_num); SimpleValue = sel({ - TableLit, const_value, If, Switch, Try, With, + TableLit, ConstValue, If, Switch, Try, With, ClassDecl, ForEach, For, While, Do, - unary_value, TblComprehension, Comprehension, + UnaryValue, TblComprehension, Comprehension, FunLit, Num }); - ExpListAssign = ExpList >> -(Space >> (Update | Assign)) >> not_(Space >> '='); + ExpListAssign = ExpList >> -(space >> (Update | Assign)) >> not_(space >> '='); - if_line = IfType >> Space >> IfCond; - while_line = WhileType >> Space >> Exp; + IfLine = IfType >> space >> IfCond; + WhileLine = WhileType >> space >> Exp; - YueLineComment = *(not_(set("\r\n")) >> Any); - yue_line_comment = "--" >> YueLineComment >> and_(Stop); + YueLineComment = *(not_(set("\r\n")) >> any_char); + yue_line_comment = "--" >> YueLineComment >> and_(stop); YueMultilineComment = multi_line_content; yue_multiline_comment = multi_line_open >> YueMultilineComment >> multi_line_close; yue_comment = check_indent >> sel({ @@ -749,13 +787,13 @@ YueParser::YueParser() { -yue_line_comment }), yue_line_comment - }) >> and_(Break); + }) >> and_(line_break); - ChainAssign = Seperator >> Exp >> +(Space >> '=' >> Space >> Exp >> Space >> and_('=')) >> Space >> Assign; + ChainAssign = Seperator >> Exp >> +(space >> '=' >> space >> Exp >> space >> and_('=')) >> space >> Assign; - statement_appendix = sel({if_line, while_line, CompInner}) >> Space; - statement_sep = and_(seq({ - *SpaceBreak, CheckIndent, Space, + StatementAppendix = sel({IfLine, WhileLine, CompInner}) >> space; + StatementSep = and_(seq({ + *space_break, check_indent_match, space, sel({ set("($'\""), "[[", @@ -766,46 +804,46 @@ YueParser::YueParser() { Seperator, -seq({ yue_comment, - *(Break >> yue_comment), - Break, - CheckIndent + *(line_break >> yue_comment), + line_break, + check_indent_match }), - Space, + space, sel({ Import, While, Repeat, For, ForEach, Return, Local, Global, Export, Macro, MacroInPlace, BreakLoop, Label, Goto, ShortTabAppending, LocalAttrib, Backcall, PipeBody, ExpListAssign, ChainAssign, - statement_appendix >> empty_block_error + StatementAppendix >> empty_block_error }), - Space, - -statement_appendix, - -statement_sep + space, + -StatementAppendix, + -StatementSep }); - Body = InBlock | Statement; + Body = in_block | Statement; empty_line_break = sel({ - check_indent >> (MultiLineComment >> Space | Comment), - advance >> ensure(MultiLineComment >> Space | Comment, PopIndent), + check_indent >> (multi_line_comment >> space | comment), + advance >> ensure(multi_line_comment >> space | comment, pop_indent), plain_space - }) >> and_(Break); + }) >> and_(line_break); - indentation_error = pl::user(not_(PipeOperator | eof()), [](const item_t& item) { + indentation_error = pl::user(not_(pipe_operator | eof()), [](const item_t& item) { throw ParserError("unexpected indent", *item.begin, *item.end); return false; }); - Line = sel({ - CheckIndent >> Statement, + line = sel({ + check_indent_match >> Statement, empty_line_break, - Advance >> ensure(Space >> (indentation_error | Statement), PopIndent) + advance_match >> ensure(space >> (indentation_error | Statement), pop_indent) }); - Block = seq({Seperator, Line, *(+Break >> Line)}); + Block = seq({Seperator, line, *(+line_break >> line)}); - Shebang = "#!" >> *(not_(Stop) >> Any); - BlockEnd = seq({Block, White, Stop}); - File = seq({-Shebang, -Block, White, Stop}); + shebang = "#!" >> *(not_(stop) >> any_char); + BlockEnd = seq({Block, white, stop}); + File = seq({-shebang, -Block, white, stop}); } // clang-format on diff --git a/src/yuescript/yue_parser.h b/src/yuescript/yue_parser.h index 9323422..e98b711 100644 --- a/src/yuescript/yue_parser.h +++ b/src/yuescript/yue_parser.h @@ -112,7 +112,7 @@ private: template inline rule& getRule(identity) { assert(false); - return Cut; + return cut; } rule empty_block_error; @@ -126,94 +126,94 @@ private: rule num_expo_hex; rule lj_num; rule plain_space; - rule Break; - rule Any; - rule White; - rule Stop; - rule Comment; + rule line_break; + rule any_char; + rule white; + rule stop; + rule comment; rule multi_line_open; rule multi_line_close; rule multi_line_content; - rule MultiLineComment; - rule Indent; - rule EscapeNewLine; + rule multi_line_comment; + rule indent; + rule escape_new_line; rule space_one; - rule Space; - rule SpaceBreak; - rule EmptyLine; - rule AlphaNum; - rule Cut; + rule space; + rule space_break; + rule empty_line; + rule alpha_num; + rule cut; + rule check_indent_match; rule check_indent; - rule CheckIndent; + rule advance_match; rule advance; - rule Advance; + rule push_indent_match; rule push_indent; - rule PushIndent; - rule PreventIndent; - rule PopIndent; - rule InBlock; - rule ImportName; - rule ImportNameList; + rule prevent_indent; + rule pop_indent; + rule in_block; + rule import_name; + rule import_name_list; rule import_literal_chain; - rule ImportTabItem; - rule ImportTabList; - rule ImportTabLine; + rule import_tab_item; + rule import_tab_list; + rule import_tab_line; rule import_tab_lines; - rule WithExp; - rule DisableDo; - rule EnableDo; - rule DisableChain; - rule EnableChain; - rule DisableDoChainArgTableBlock; - rule EnableDoChainArgTableBlock; - rule DisableArgTableBlock; - rule EnableArgTableBlock; - rule SwitchElse; - rule SwitchBlock; - rule IfElseIf; - rule IfElse; + rule with_exp; + rule disable_do; + rule enable_do; + rule disable_chain; + rule enable_chain; + rule disable_do_chain_arg_table_block; + rule enable_do_chain_arg_table_block; + rule disable_arg_table_block; + rule enable_arg_table_block; + rule switch_else; + rule switch_block; + rule if_else_if; + rule if_else; rule for_args; rule for_in; - rule CompClause; - rule Chain; - rule ChainList; - rule KeyValue; + rule comp_clause; + rule chain; + rule chain_list; + rule key_value; rule single_string_inner; rule interp; rule double_string_plain; rule lua_string_open; rule lua_string_close; - rule FnArgsExpList; - rule FnArgs; + rule fn_args_exp_list; + rule fn_args; rule destruct_def; rule macro_args_def; rule chain_call; rule chain_call_list; rule chain_index_chain; - rule ChainItems; + rule chain_items; rule chain_dot_chain; - rule ColonChain; + rule colon_chain; rule chain_with_colon; - rule ChainItem; + rule chain_item; rule chain_line; rule chain_block; rule meta_index; - rule Index; + rule index; rule invoke_chain; - rule TableValue; + rule table_value; rule table_lit_lines; - rule TableLitLine; - rule TableValueList; - rule TableBlockInner; - rule ClassLine; - rule KeyValueLine; - rule KeyValueList; - rule ArgLine; - rule ArgBlock; + rule table_lit_line; + rule table_value_list; + rule table_block_inner; + rule class_line; + rule key_value_line; + rule key_value_list; + rule arg_line; + rule arg_block; rule invoke_args_with_table; rule arg_table_block; - rule PipeOperator; - rule ExponentialOperator; + rule pipe_operator; + rule exponential_operator; rule pipe_value; rule pipe_exp; rule expo_value; @@ -224,42 +224,42 @@ private: rule yue_comment; rule yue_line_comment; rule yue_multiline_comment; - rule Line; - rule Shebang; + rule line; + rule shebang; AST_RULE(Num) AST_RULE(Name) AST_RULE(Variable) AST_RULE(LabelName) AST_RULE(LuaKeyword) - AST_RULE(self) - AST_RULE(self_name) - AST_RULE(self_class) - AST_RULE(self_class_name) + AST_RULE(Self) AST_RULE(SelfName) + AST_RULE(SelfClass) + AST_RULE(SelfClassName) + AST_RULE(SelfItem) AST_RULE(KeyName) AST_RULE(VarArg) AST_RULE(Seperator) AST_RULE(NameList) - AST_RULE(local_flag) - AST_RULE(local_values) + AST_RULE(LocalFlag) + AST_RULE(LocalValues) AST_RULE(Local) - AST_RULE(const_attrib) - AST_RULE(close_attrib) + AST_RULE(ConstAttrib) + AST_RULE(CloseAttrib) AST_RULE(LocalAttrib); - AST_RULE(colon_import_name) - AST_RULE(import_literal_inner) + AST_RULE(ColonImportName) + AST_RULE(ImportLiteralInner) AST_RULE(ImportLiteral) AST_RULE(ImportFrom) - AST_RULE(macro_name_pair) - AST_RULE(import_all_macro) + AST_RULE(MacroNamePair) + AST_RULE(ImportAllMacro) AST_RULE(ImportTabLit) AST_RULE(ImportAs) AST_RULE(Import) AST_RULE(Label) AST_RULE(Goto) AST_RULE(ShortTabAppending) - AST_RULE(fn_arrow_back) + AST_RULE(FnArrowBack) AST_RULE(Backcall) AST_RULE(PipeBody) AST_RULE(ExpListLow) @@ -269,38 +269,38 @@ private: AST_RULE(SwitchList) AST_RULE(SwitchCase) AST_RULE(Switch) - AST_RULE(assignment) + AST_RULE(Assignment) AST_RULE(IfCond) AST_RULE(IfType) AST_RULE(If) AST_RULE(WhileType) AST_RULE(While) AST_RULE(Repeat) - AST_RULE(for_step_value) + AST_RULE(ForStepValue) AST_RULE(For) AST_RULE(ForEach) AST_RULE(Do) - AST_RULE(catch_block) + AST_RULE(CatchBlock) AST_RULE(Try) AST_RULE(Comprehension) - AST_RULE(comp_value) + AST_RULE(CompValue) AST_RULE(TblComprehension) - AST_RULE(star_exp) + AST_RULE(StarExp) AST_RULE(CompForEach) AST_RULE(CompFor) AST_RULE(CompInner) AST_RULE(Assign) - AST_RULE(update_op) + AST_RULE(UpdateOp) AST_RULE(Update) AST_RULE(BinaryOperator) - AST_RULE(unary_operator) + AST_RULE(UnaryOperator) AST_RULE(Assignable) AST_RULE(AssignableChain) - AST_RULE(exp_op_value) + AST_RULE(ExpOpValue) AST_RULE(Exp) AST_RULE(Callable) AST_RULE(ChainValue) - AST_RULE(simple_table) + AST_RULE(SimpleTable) AST_RULE(SimpleValue) AST_RULE(Value) AST_RULE(LuaStringOpen); @@ -308,8 +308,8 @@ private: AST_RULE(LuaStringClose); AST_RULE(LuaString) AST_RULE(SingleString) - AST_RULE(double_string_inner) - AST_RULE(double_string_content) + AST_RULE(DoubleStringInner) + AST_RULE(DoubleStringContent) AST_RULE(DoubleString) AST_RULE(String) AST_RULE(Parens) @@ -317,37 +317,37 @@ private: AST_RULE(ColonChainItem) AST_RULE(Metatable) AST_RULE(Metamethod) - AST_RULE(default_value) + AST_RULE(DefaultValue) AST_RULE(Slice) AST_RULE(Invoke) - AST_RULE(existential_op) - AST_RULE(table_appending_op) + AST_RULE(ExistentialOp) + AST_RULE(TableAppendingOp) AST_RULE(SpreadExp) AST_RULE(TableLit) AST_RULE(TableBlock) AST_RULE(TableBlockIndent) - AST_RULE(class_member_list) + AST_RULE(ClassMemberList) AST_RULE(ClassBlock) AST_RULE(ClassDecl) - AST_RULE(global_values) - AST_RULE(global_op) + AST_RULE(GlobalValues) + AST_RULE(GlobalOp) AST_RULE(Global) - AST_RULE(export_default) + AST_RULE(ExportDefault) AST_RULE(Export) - AST_RULE(variable_pair) - AST_RULE(normal_pair) - AST_RULE(meta_variable_pair) - AST_RULE(meta_normal_pair) - AST_RULE(variable_pair_def) - AST_RULE(normal_pair_def) - AST_RULE(normal_def) - AST_RULE(meta_variable_pair_def) - AST_RULE(meta_normal_pair_def) + AST_RULE(VariablePair) + AST_RULE(NormalPair) + AST_RULE(MetaVariablePair) + AST_RULE(MetaNormalPair) + AST_RULE(VariablePairDef) + AST_RULE(NormalPairDef) + AST_RULE(NormalDef) + AST_RULE(MetaVariablePairDef) + AST_RULE(MetaNormalPairDef) AST_RULE(FnArgDef) AST_RULE(FnArgDefList) - AST_RULE(outer_var_shadow) + AST_RULE(OuterVarShadow) AST_RULE(FnArgsDef) - AST_RULE(fn_arrow) + AST_RULE(FnArrow) AST_RULE(FunLit) AST_RULE(MacroName) AST_RULE(MacroLit) @@ -356,15 +356,15 @@ private: AST_RULE(NameOrDestructure) AST_RULE(AssignableNameList) AST_RULE(InvokeArgs) - AST_RULE(const_value) - AST_RULE(unary_value) - AST_RULE(unary_exp) + AST_RULE(ConstValue) + AST_RULE(UnaryValue) + AST_RULE(UnaryExp) AST_RULE(ExpListAssign) - AST_RULE(if_line) - AST_RULE(while_line) + AST_RULE(IfLine) + AST_RULE(WhileLine) AST_RULE(BreakLoop) - AST_RULE(statement_appendix) - AST_RULE(statement_sep) + AST_RULE(StatementAppendix) + AST_RULE(StatementSep) AST_RULE(Statement) AST_RULE(YueLineComment) AST_RULE(YueMultilineComment) -- cgit v1.2.3-55-g6feb