diff options
| author | Li Jin <dragon-fly@qq.com> | 2024-08-09 02:55:56 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2024-08-09 02:55:56 +0800 |
| commit | b6c86d19d74ac90a2450cf979a92187e691ea5fa (patch) | |
| tree | 6073623a0cca27aa64c68f0c554116e7475e0531 | |
| parent | 94edfbc8c7d62d700dfb59334a0ed3beedd49493 (diff) | |
| download | yuescript-b6c86d19d74ac90a2450cf979a92187e691ea5fa.tar.gz yuescript-b6c86d19d74ac90a2450cf979a92187e691ea5fa.tar.bz2 yuescript-b6c86d19d74ac90a2450cf979a92187e691ea5fa.zip | |
add yue.is_ast().
| -rw-r--r-- | spec/inputs/macro.yue | 8 | ||||
| -rw-r--r-- | spec/outputs/macro.lua | 6 | ||||
| -rw-r--r-- | src/yuescript/yue_ast.h | 322 | ||||
| -rw-r--r-- | src/yuescript/yue_compiler.cpp | 48 | ||||
| -rw-r--r-- | src/yuescript/yue_parser.cpp | 27 | ||||
| -rw-r--r-- | src/yuescript/yue_parser.h | 21 | ||||
| -rw-r--r-- | src/yuescript/yuescript.cpp | 26 |
7 files changed, 269 insertions, 189 deletions
diff --git a/spec/inputs/macro.yue b/spec/inputs/macro.yue index a2e1046..3d4fb10 100644 --- a/spec/inputs/macro.yue +++ b/spec/inputs/macro.yue | |||
| @@ -38,6 +38,14 @@ print $WindowFlag( | |||
| 38 | NoScrollbar | 38 | NoScrollbar |
| 39 | ) | 39 | ) |
| 40 | 40 | ||
| 41 | macro NumAndStr = (num, str) -> | ||
| 42 | import "yue" | ||
| 43 | unless yue.is_ast("Num", "123") | ||
| 44 | error "unmatched tokens got" | ||
| 45 | "[#{num}, #{str}]" | ||
| 46 | |||
| 47 | print $NumAndStr 123, 'xyz' | ||
| 48 | |||
| 41 | $asserts item == nil | 49 | $asserts item == nil |
| 42 | 50 | ||
| 43 | $myconfig false | 51 | $myconfig false |
diff --git a/spec/outputs/macro.lua b/spec/outputs/macro.lua index 953c260..4492827 100644 --- a/spec/outputs/macro.lua +++ b/spec/outputs/macro.lua | |||
| @@ -7,6 +7,10 @@ print({ | |||
| 7 | "NoMove", | 7 | "NoMove", |
| 8 | "NoScrollbar" | 8 | "NoScrollbar" |
| 9 | }) | 9 | }) |
| 10 | print({ | ||
| 11 | 123, | ||
| 12 | 'xyz' | ||
| 13 | }) | ||
| 10 | do | 14 | do |
| 11 | assert(item == nil) | 15 | assert(item == nil) |
| 12 | end | 16 | end |
| @@ -294,7 +298,7 @@ print((setmetatable({ | |||
| 294 | return 998 | 298 | return 998 |
| 295 | end | 299 | end |
| 296 | })) | 300 | })) |
| 297 | print("current line: " .. tostring(301)) | 301 | print("current line: " .. tostring(309)) |
| 298 | do | 302 | do |
| 299 | -- TODO | 303 | -- TODO |
| 300 | end | 304 | end |
diff --git a/src/yuescript/yue_ast.h b/src/yuescript/yue_ast.h index b287202..7bf17fe 100644 --- a/src/yuescript/yue_ast.h +++ b/src/yuescript/yue_ast.h | |||
| @@ -12,13 +12,17 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI | |||
| 12 | 12 | ||
| 13 | namespace parserlib { | 13 | namespace parserlib { |
| 14 | 14 | ||
| 15 | template <class T> | ||
| 16 | std::string_view ast_name() { } | ||
| 17 | |||
| 15 | #define AST_LEAF(type) \ | 18 | #define AST_LEAF(type) \ |
| 16 | COUNTER_INC; \ | 19 | COUNTER_INC; \ |
| 17 | namespace yue { \ | 20 | namespace yue { \ |
| 18 | class type##_t : public ast_node { \ | 21 | class type##_t : public ast_node { \ |
| 19 | public: \ | 22 | public: \ |
| 20 | virtual int get_id() const override { return COUNTER_READ; } \ | 23 | virtual int get_id() const override { return COUNTER_READ; } \ |
| 21 | virtual std::string to_string(void*) const override; | 24 | virtual std::string to_string(void*) const override; \ |
| 25 | virtual const std::string_view get_name() const override { return #type ""sv; } | ||
| 22 | 26 | ||
| 23 | #define AST_NODE(type) \ | 27 | #define AST_NODE(type) \ |
| 24 | COUNTER_INC; \ | 28 | COUNTER_INC; \ |
| @@ -26,20 +30,22 @@ namespace parserlib { | |||
| 26 | class type##_t : public ast_container { \ | 30 | class type##_t : public ast_container { \ |
| 27 | public: \ | 31 | public: \ |
| 28 | virtual int get_id() const override { return COUNTER_READ; } \ | 32 | virtual int get_id() const override { return COUNTER_READ; } \ |
| 29 | virtual std::string to_string(void*) const override; | 33 | virtual std::string to_string(void*) const override; \ |
| 34 | virtual const std::string_view get_name() const override { return #type ""sv; } | ||
| 30 | 35 | ||
| 31 | #define AST_MEMBER(type, ...) \ | 36 | #define AST_MEMBER(type, ...) \ |
| 32 | type##_t() { \ | 37 | type##_t() { \ |
| 33 | add_members({__VA_ARGS__}); \ | 38 | add_members({__VA_ARGS__}); \ |
| 34 | } | 39 | } |
| 35 | 40 | ||
| 36 | #define AST_END(type, name) \ | 41 | #define AST_END(type) \ |
| 37 | virtual const std::string_view get_name() const override { return name; } \ | ||
| 38 | } \ | 42 | } \ |
| 39 | ; \ | 43 | ; \ |
| 40 | } \ | 44 | } \ |
| 41 | template <> \ | 45 | template <> \ |
| 42 | constexpr int id<yue::type##_t>() { return COUNTER_READ; } | 46 | constexpr int id<yue::type##_t>() { return COUNTER_READ; } \ |
| 47 | template <> \ | ||
| 48 | constexpr std::string_view ast_name<yue::type##_t>() { return #type ""sv; } | ||
| 43 | 49 | ||
| 44 | // clang-format off | 50 | // clang-format off |
| 45 | 51 | ||
| @@ -85,75 +91,75 @@ class Value_t; | |||
| 85 | } // namespace yue | 91 | } // namespace yue |
| 86 | 92 | ||
| 87 | AST_LEAF(Num) | 93 | AST_LEAF(Num) |
| 88 | AST_END(Num, "num"sv) | 94 | AST_END(Num) |
| 89 | 95 | ||
| 90 | AST_LEAF(Name) | 96 | AST_LEAF(Name) |
| 91 | AST_END(Name, "name"sv) | 97 | AST_END(Name) |
| 92 | 98 | ||
| 93 | AST_LEAF(UnicodeName) | 99 | AST_LEAF(UnicodeName) |
| 94 | AST_END(UnicodeName, "unicode_name"sv) | 100 | AST_END(UnicodeName) |
| 95 | 101 | ||
| 96 | AST_NODE(Variable) | 102 | AST_NODE(Variable) |
| 97 | ast_sel<true, Name_t, UnicodeName_t> name; | 103 | ast_sel<true, Name_t, UnicodeName_t> name; |
| 98 | AST_MEMBER(Variable, &name) | 104 | AST_MEMBER(Variable, &name) |
| 99 | AST_END(Variable, "variable"sv) | 105 | AST_END(Variable) |
| 100 | 106 | ||
| 101 | AST_NODE(LabelName) | 107 | AST_NODE(LabelName) |
| 102 | ast_ptr<true, UnicodeName_t> name; | 108 | ast_ptr<true, UnicodeName_t> name; |
| 103 | AST_MEMBER(LabelName, &name) | 109 | AST_MEMBER(LabelName, &name) |
| 104 | AST_END(LabelName, "label_name"sv) | 110 | AST_END(LabelName) |
| 105 | 111 | ||
| 106 | AST_NODE(LuaKeyword) | 112 | AST_NODE(LuaKeyword) |
| 107 | ast_ptr<true, Name_t> name; | 113 | ast_ptr<true, Name_t> name; |
| 108 | AST_MEMBER(LuaKeyword, &name) | 114 | AST_MEMBER(LuaKeyword, &name) |
| 109 | AST_END(LuaKeyword, "lua_keyword"sv) | 115 | AST_END(LuaKeyword) |
| 110 | 116 | ||
| 111 | AST_LEAF(Self) | 117 | AST_LEAF(Self) |
| 112 | AST_END(Self, "self"sv) | 118 | AST_END(Self) |
| 113 | 119 | ||
| 114 | AST_NODE(SelfName) | 120 | AST_NODE(SelfName) |
| 115 | ast_sel<true, Name_t, UnicodeName_t> name; | 121 | ast_sel<true, Name_t, UnicodeName_t> name; |
| 116 | AST_MEMBER(SelfName, &name) | 122 | AST_MEMBER(SelfName, &name) |
| 117 | AST_END(SelfName, "self_name"sv) | 123 | AST_END(SelfName) |
| 118 | 124 | ||
| 119 | AST_LEAF(SelfClass) | 125 | AST_LEAF(SelfClass) |
| 120 | AST_END(SelfClass, "self_class"sv) | 126 | AST_END(SelfClass) |
| 121 | 127 | ||
| 122 | AST_NODE(SelfClassName) | 128 | AST_NODE(SelfClassName) |
| 123 | ast_sel<true, Name_t, UnicodeName_t> name; | 129 | ast_sel<true, Name_t, UnicodeName_t> name; |
| 124 | AST_MEMBER(SelfClassName, &name) | 130 | AST_MEMBER(SelfClassName, &name) |
| 125 | AST_END(SelfClassName, "self_class_name"sv) | 131 | AST_END(SelfClassName) |
| 126 | 132 | ||
| 127 | AST_NODE(SelfItem) | 133 | AST_NODE(SelfItem) |
| 128 | ast_sel<true, SelfClassName_t, SelfClass_t, SelfName_t, Self_t> name; | 134 | ast_sel<true, SelfClassName_t, SelfClass_t, SelfName_t, Self_t> name; |
| 129 | AST_MEMBER(SelfItem, &name) | 135 | AST_MEMBER(SelfItem, &name) |
| 130 | AST_END(SelfItem, "self_item"sv) | 136 | AST_END(SelfItem) |
| 131 | 137 | ||
| 132 | AST_NODE(KeyName) | 138 | AST_NODE(KeyName) |
| 133 | ast_sel<true, SelfItem_t, Name_t, UnicodeName_t> name; | 139 | ast_sel<true, SelfItem_t, Name_t, UnicodeName_t> name; |
| 134 | AST_MEMBER(KeyName, &name) | 140 | AST_MEMBER(KeyName, &name) |
| 135 | AST_END(KeyName, "key_name"sv) | 141 | AST_END(KeyName) |
| 136 | 142 | ||
| 137 | AST_LEAF(VarArg) | 143 | AST_LEAF(VarArg) |
| 138 | AST_END(VarArg, "var_arg"sv) | 144 | AST_END(VarArg) |
| 139 | 145 | ||
| 140 | AST_LEAF(LocalFlag) | 146 | AST_LEAF(LocalFlag) |
| 141 | AST_END(LocalFlag, "local_flag"sv) | 147 | AST_END(LocalFlag) |
| 142 | 148 | ||
| 143 | AST_LEAF(Seperator) | 149 | AST_LEAF(Seperator) |
| 144 | AST_END(Seperator, "seperator"sv) | 150 | AST_END(Seperator) |
| 145 | 151 | ||
| 146 | AST_NODE(NameList) | 152 | AST_NODE(NameList) |
| 147 | ast_ptr<true, Seperator_t> sep; | 153 | ast_ptr<true, Seperator_t> sep; |
| 148 | ast_list<true, Variable_t> names; | 154 | ast_list<true, Variable_t> names; |
| 149 | AST_MEMBER(NameList, &sep, &names) | 155 | AST_MEMBER(NameList, &sep, &names) |
| 150 | AST_END(NameList, "name_list"sv) | 156 | AST_END(NameList) |
| 151 | 157 | ||
| 152 | AST_NODE(LocalValues) | 158 | AST_NODE(LocalValues) |
| 153 | ast_ptr<true, NameList_t> nameList; | 159 | ast_ptr<true, NameList_t> nameList; |
| 154 | ast_sel<false, TableBlock_t, ExpListLow_t> valueList; | 160 | ast_sel<false, TableBlock_t, ExpListLow_t> valueList; |
| 155 | AST_MEMBER(LocalValues, &nameList, &valueList) | 161 | AST_MEMBER(LocalValues, &nameList, &valueList) |
| 156 | AST_END(LocalValues, "local_values"sv) | 162 | AST_END(LocalValues) |
| 157 | 163 | ||
| 158 | AST_NODE(Local) | 164 | AST_NODE(Local) |
| 159 | ast_sel<true, LocalFlag_t, LocalValues_t> item; | 165 | ast_sel<true, LocalFlag_t, LocalValues_t> item; |
| @@ -162,13 +168,13 @@ AST_NODE(Local) | |||
| 162 | bool collected = false; | 168 | bool collected = false; |
| 163 | bool defined = false; | 169 | bool defined = false; |
| 164 | AST_MEMBER(Local, &item) | 170 | AST_MEMBER(Local, &item) |
| 165 | AST_END(Local, "local"sv) | 171 | AST_END(Local) |
| 166 | 172 | ||
| 167 | AST_LEAF(ConstAttrib) | 173 | AST_LEAF(ConstAttrib) |
| 168 | AST_END(ConstAttrib, "const"sv) | 174 | AST_END(ConstAttrib) |
| 169 | 175 | ||
| 170 | AST_LEAF(CloseAttrib) | 176 | AST_LEAF(CloseAttrib) |
| 171 | AST_END(CloseAttrib, "close"sv) | 177 | AST_END(CloseAttrib) |
| 172 | 178 | ||
| 173 | AST_NODE(LocalAttrib) | 179 | AST_NODE(LocalAttrib) |
| 174 | ast_sel<true, ConstAttrib_t, CloseAttrib_t> attrib; | 180 | ast_sel<true, ConstAttrib_t, CloseAttrib_t> attrib; |
| @@ -176,104 +182,104 @@ AST_NODE(LocalAttrib) | |||
| 176 | ast_sel_list<true, Variable_t, SimpleTable_t, TableLit_t, Comprehension_t> leftList; | 182 | ast_sel_list<true, Variable_t, SimpleTable_t, TableLit_t, Comprehension_t> leftList; |
| 177 | ast_ptr<true, Assign_t> assign; | 183 | ast_ptr<true, Assign_t> assign; |
| 178 | AST_MEMBER(LocalAttrib, &attrib, &sep, &leftList, &assign) | 184 | AST_MEMBER(LocalAttrib, &attrib, &sep, &leftList, &assign) |
| 179 | AST_END(LocalAttrib, "local_attrib"sv) | 185 | AST_END(LocalAttrib) |
| 180 | 186 | ||
| 181 | AST_NODE(ColonImportName) | 187 | AST_NODE(ColonImportName) |
| 182 | ast_ptr<true, Variable_t> name; | 188 | ast_ptr<true, Variable_t> name; |
| 183 | AST_MEMBER(ColonImportName, &name) | 189 | AST_MEMBER(ColonImportName, &name) |
| 184 | AST_END(ColonImportName, "colon_import_name"sv) | 190 | AST_END(ColonImportName) |
| 185 | 191 | ||
| 186 | AST_LEAF(ImportLiteralInner) | 192 | AST_LEAF(ImportLiteralInner) |
| 187 | AST_END(ImportLiteralInner, "import_literal_inner"sv) | 193 | AST_END(ImportLiteralInner) |
| 188 | 194 | ||
| 189 | AST_NODE(ImportLiteral) | 195 | AST_NODE(ImportLiteral) |
| 190 | ast_ptr<true, Seperator_t> sep; | 196 | ast_ptr<true, Seperator_t> sep; |
| 191 | ast_sel_list<true, ImportLiteralInner_t> inners; | 197 | ast_sel_list<true, ImportLiteralInner_t> inners; |
| 192 | AST_MEMBER(ImportLiteral, &sep, &inners) | 198 | AST_MEMBER(ImportLiteral, &sep, &inners) |
| 193 | AST_END(ImportLiteral, "import_literal"sv) | 199 | AST_END(ImportLiteral) |
| 194 | 200 | ||
| 195 | AST_NODE(ImportFrom) | 201 | AST_NODE(ImportFrom) |
| 196 | ast_ptr<true, Seperator_t> sep; | 202 | ast_ptr<true, Seperator_t> sep; |
| 197 | ast_sel_list<true, ColonImportName_t, Variable_t> names; | 203 | ast_sel_list<true, ColonImportName_t, Variable_t> names; |
| 198 | ast_sel<true, ImportLiteral_t, Exp_t> item; | 204 | ast_sel<true, ImportLiteral_t, Exp_t> item; |
| 199 | AST_MEMBER(ImportFrom, &sep, &names, &item) | 205 | AST_MEMBER(ImportFrom, &sep, &names, &item) |
| 200 | AST_END(ImportFrom, "import_from"sv) | 206 | AST_END(ImportFrom) |
| 201 | 207 | ||
| 202 | AST_NODE(FromImport) | 208 | AST_NODE(FromImport) |
| 203 | ast_sel<true, ImportLiteral_t, Exp_t> item; | 209 | ast_sel<true, ImportLiteral_t, Exp_t> item; |
| 204 | ast_ptr<true, Seperator_t> sep; | 210 | ast_ptr<true, Seperator_t> sep; |
| 205 | ast_sel_list<true, ColonImportName_t, Variable_t> names; | 211 | ast_sel_list<true, ColonImportName_t, Variable_t> names; |
| 206 | AST_MEMBER(FromImport, &item, &sep, &names) | 212 | AST_MEMBER(FromImport, &item, &sep, &names) |
| 207 | AST_END(FromImport, "from_import"sv) | 213 | AST_END(FromImport) |
| 208 | 214 | ||
| 209 | AST_NODE(MacroNamePair) | 215 | AST_NODE(MacroNamePair) |
| 210 | ast_ptr<true, MacroName_t> key; | 216 | ast_ptr<true, MacroName_t> key; |
| 211 | ast_ptr<true, MacroName_t> value; | 217 | ast_ptr<true, MacroName_t> value; |
| 212 | AST_MEMBER(MacroNamePair, &key, &value) | 218 | AST_MEMBER(MacroNamePair, &key, &value) |
| 213 | AST_END(MacroNamePair, "macro_name_pair"sv) | 219 | AST_END(MacroNamePair) |
| 214 | 220 | ||
| 215 | AST_LEAF(ImportAllMacro) | 221 | AST_LEAF(ImportAllMacro) |
| 216 | AST_END(ImportAllMacro, "import_all_macro"sv) | 222 | AST_END(ImportAllMacro) |
| 217 | 223 | ||
| 218 | AST_NODE(ImportTabLit) | 224 | AST_NODE(ImportTabLit) |
| 219 | ast_ptr<true, Seperator_t> sep; | 225 | ast_ptr<true, Seperator_t> sep; |
| 220 | ast_sel_list<false, VariablePair_t, NormalPair_t, MacroName_t, MacroNamePair_t, ImportAllMacro_t, Exp_t, MetaVariablePair_t, MetaNormalPair_t> items; | 226 | ast_sel_list<false, VariablePair_t, NormalPair_t, MacroName_t, MacroNamePair_t, ImportAllMacro_t, Exp_t, MetaVariablePair_t, MetaNormalPair_t> items; |
| 221 | AST_MEMBER(ImportTabLit, &sep, &items) | 227 | AST_MEMBER(ImportTabLit, &sep, &items) |
| 222 | AST_END(ImportTabLit, "import_tab_lit"sv) | 228 | AST_END(ImportTabLit) |
| 223 | 229 | ||
| 224 | AST_NODE(ImportAs) | 230 | AST_NODE(ImportAs) |
| 225 | ast_ptr<true, ImportLiteral_t> literal; | 231 | ast_ptr<true, ImportLiteral_t> literal; |
| 226 | ast_sel<false, Variable_t, ImportTabLit_t, ImportAllMacro_t> target; | 232 | ast_sel<false, Variable_t, ImportTabLit_t, ImportAllMacro_t> target; |
| 227 | AST_MEMBER(ImportAs, &literal, &target) | 233 | AST_MEMBER(ImportAs, &literal, &target) |
| 228 | AST_END(ImportAs, "import_as"sv) | 234 | AST_END(ImportAs) |
| 229 | 235 | ||
| 230 | AST_NODE(Import) | 236 | AST_NODE(Import) |
| 231 | ast_sel<true, ImportAs_t, ImportFrom_t, FromImport_t> content; | 237 | ast_sel<true, ImportAs_t, ImportFrom_t, FromImport_t> content; |
| 232 | AST_MEMBER(Import, &content) | 238 | AST_MEMBER(Import, &content) |
| 233 | AST_END(Import, "import"sv) | 239 | AST_END(Import) |
| 234 | 240 | ||
| 235 | AST_NODE(Label) | 241 | AST_NODE(Label) |
| 236 | ast_ptr<true, LabelName_t> label; | 242 | ast_ptr<true, LabelName_t> label; |
| 237 | AST_MEMBER(Label, &label) | 243 | AST_MEMBER(Label, &label) |
| 238 | AST_END(Label, "label"sv) | 244 | AST_END(Label) |
| 239 | 245 | ||
| 240 | AST_NODE(Goto) | 246 | AST_NODE(Goto) |
| 241 | ast_ptr<true, LabelName_t> label; | 247 | ast_ptr<true, LabelName_t> label; |
| 242 | AST_MEMBER(Goto, &label) | 248 | AST_MEMBER(Goto, &label) |
| 243 | AST_END(Goto, "goto"sv) | 249 | AST_END(Goto) |
| 244 | 250 | ||
| 245 | AST_NODE(ShortTabAppending) | 251 | AST_NODE(ShortTabAppending) |
| 246 | ast_ptr<true, Assign_t> assign; | 252 | ast_ptr<true, Assign_t> assign; |
| 247 | AST_MEMBER(ShortTabAppending, &assign) | 253 | AST_MEMBER(ShortTabAppending, &assign) |
| 248 | AST_END(ShortTabAppending, "short_table_appending"sv) | 254 | AST_END(ShortTabAppending) |
| 249 | 255 | ||
| 250 | AST_LEAF(FnArrowBack) | 256 | AST_LEAF(FnArrowBack) |
| 251 | AST_END(FnArrowBack, "fn_arrow_back"sv) | 257 | AST_END(FnArrowBack) |
| 252 | 258 | ||
| 253 | AST_NODE(Backcall) | 259 | AST_NODE(Backcall) |
| 254 | ast_ptr<false, FnArgsDef_t> argsDef; | 260 | ast_ptr<false, FnArgsDef_t> argsDef; |
| 255 | ast_ptr<true, FnArrowBack_t> arrow; | 261 | ast_ptr<true, FnArrowBack_t> arrow; |
| 256 | ast_ptr<true, ChainValue_t> value; | 262 | ast_ptr<true, ChainValue_t> value; |
| 257 | AST_MEMBER(Backcall, &argsDef, &arrow, &value) | 263 | AST_MEMBER(Backcall, &argsDef, &arrow, &value) |
| 258 | AST_END(Backcall, "backcall"sv) | 264 | AST_END(Backcall) |
| 259 | 265 | ||
| 260 | AST_NODE(ExpListLow) | 266 | AST_NODE(ExpListLow) |
| 261 | ast_ptr<true, Seperator_t> sep; | 267 | ast_ptr<true, Seperator_t> sep; |
| 262 | ast_list<true, Exp_t> exprs; | 268 | ast_list<true, Exp_t> exprs; |
| 263 | AST_MEMBER(ExpListLow, &sep, &exprs) | 269 | AST_MEMBER(ExpListLow, &sep, &exprs) |
| 264 | AST_END(ExpListLow, "exp_list_low"sv) | 270 | AST_END(ExpListLow) |
| 265 | 271 | ||
| 266 | AST_NODE(ExpList) | 272 | AST_NODE(ExpList) |
| 267 | ast_ptr<true, Seperator_t> sep; | 273 | ast_ptr<true, Seperator_t> sep; |
| 268 | ast_list<true, Exp_t> exprs; | 274 | ast_list<true, Exp_t> exprs; |
| 269 | AST_MEMBER(ExpList, &sep, &exprs) | 275 | AST_MEMBER(ExpList, &sep, &exprs) |
| 270 | AST_END(ExpList, "exp_list"sv) | 276 | AST_END(ExpList) |
| 271 | 277 | ||
| 272 | AST_NODE(Return) | 278 | AST_NODE(Return) |
| 273 | bool allowBlockMacroReturn = false; | 279 | bool allowBlockMacroReturn = false; |
| 274 | ast_sel<false, TableBlock_t, ExpListLow_t> valueList; | 280 | ast_sel<false, TableBlock_t, ExpListLow_t> valueList; |
| 275 | AST_MEMBER(Return, &valueList) | 281 | AST_MEMBER(Return, &valueList) |
| 276 | AST_END(Return, "return"sv) | 282 | AST_END(Return) |
| 277 | 283 | ||
| 278 | AST_NODE(With) | 284 | AST_NODE(With) |
| 279 | ast_ptr<false, ExistentialOp_t> eop; | 285 | ast_ptr<false, ExistentialOp_t> eop; |
| @@ -281,19 +287,19 @@ AST_NODE(With) | |||
| 281 | ast_ptr<false, Assign_t> assigns; | 287 | ast_ptr<false, Assign_t> assigns; |
| 282 | ast_sel<true, Block_t, Statement_t> body; | 288 | ast_sel<true, Block_t, Statement_t> body; |
| 283 | AST_MEMBER(With, &eop, &valueList, &assigns, &body) | 289 | AST_MEMBER(With, &eop, &valueList, &assigns, &body) |
| 284 | AST_END(With, "with"sv) | 290 | AST_END(With) |
| 285 | 291 | ||
| 286 | AST_NODE(SwitchList) | 292 | AST_NODE(SwitchList) |
| 287 | ast_ptr<true, Seperator_t> sep; | 293 | ast_ptr<true, Seperator_t> sep; |
| 288 | ast_list<true, Exp_t> exprs; | 294 | ast_list<true, Exp_t> exprs; |
| 289 | AST_MEMBER(SwitchList, &sep, &exprs) | 295 | AST_MEMBER(SwitchList, &sep, &exprs) |
| 290 | AST_END(SwitchList, "switch_list"sv) | 296 | AST_END(SwitchList) |
| 291 | 297 | ||
| 292 | AST_NODE(SwitchCase) | 298 | AST_NODE(SwitchCase) |
| 293 | ast_ptr<true, SwitchList_t> condition; | 299 | ast_ptr<true, SwitchList_t> condition; |
| 294 | ast_sel<true, Block_t, Statement_t> body; | 300 | ast_sel<true, Block_t, Statement_t> body; |
| 295 | AST_MEMBER(SwitchCase, &condition, &body) | 301 | AST_MEMBER(SwitchCase, &condition, &body) |
| 296 | AST_END(SwitchCase, "switch_case"sv) | 302 | AST_END(SwitchCase) |
| 297 | 303 | ||
| 298 | AST_NODE(Switch) | 304 | AST_NODE(Switch) |
| 299 | ast_ptr<true, Exp_t> target; | 305 | ast_ptr<true, Exp_t> target; |
| @@ -301,49 +307,49 @@ AST_NODE(Switch) | |||
| 301 | ast_list<true, SwitchCase_t> branches; | 307 | ast_list<true, SwitchCase_t> branches; |
| 302 | ast_sel<false, Block_t, Statement_t> lastBranch; | 308 | ast_sel<false, Block_t, Statement_t> lastBranch; |
| 303 | AST_MEMBER(Switch, &target, &sep, &branches, &lastBranch) | 309 | AST_MEMBER(Switch, &target, &sep, &branches, &lastBranch) |
| 304 | AST_END(Switch, "switch"sv) | 310 | AST_END(Switch) |
| 305 | 311 | ||
| 306 | AST_NODE(Assignment) | 312 | AST_NODE(Assignment) |
| 307 | ast_ptr<false, ExpList_t> expList; | 313 | ast_ptr<false, ExpList_t> expList; |
| 308 | ast_ptr<true, Assign_t> assign; | 314 | ast_ptr<true, Assign_t> assign; |
| 309 | AST_MEMBER(Assignment, &expList, &assign) | 315 | AST_MEMBER(Assignment, &expList, &assign) |
| 310 | AST_END(Assignment, "assignment"sv) | 316 | AST_END(Assignment) |
| 311 | 317 | ||
| 312 | AST_NODE(IfCond) | 318 | AST_NODE(IfCond) |
| 313 | ast_ptr<true, Exp_t> condition; | 319 | ast_ptr<true, Exp_t> condition; |
| 314 | ast_ptr<false, Assignment_t> assignment; | 320 | ast_ptr<false, Assignment_t> assignment; |
| 315 | AST_MEMBER(IfCond, &condition, &assignment) | 321 | AST_MEMBER(IfCond, &condition, &assignment) |
| 316 | AST_END(IfCond, "if_cond"sv) | 322 | AST_END(IfCond) |
| 317 | 323 | ||
| 318 | AST_LEAF(IfType) | 324 | AST_LEAF(IfType) |
| 319 | AST_END(IfType, "if_type"sv) | 325 | AST_END(IfType) |
| 320 | 326 | ||
| 321 | AST_NODE(If) | 327 | AST_NODE(If) |
| 322 | ast_ptr<true, IfType_t> type; | 328 | ast_ptr<true, IfType_t> type; |
| 323 | ast_sel_list<true, IfCond_t, Block_t, Statement_t> nodes; | 329 | ast_sel_list<true, IfCond_t, Block_t, Statement_t> nodes; |
| 324 | AST_MEMBER(If, &type, &nodes) | 330 | AST_MEMBER(If, &type, &nodes) |
| 325 | AST_END(If, "if"sv) | 331 | AST_END(If) |
| 326 | 332 | ||
| 327 | AST_LEAF(WhileType) | 333 | AST_LEAF(WhileType) |
| 328 | AST_END(WhileType, "while_type"sv) | 334 | AST_END(WhileType) |
| 329 | 335 | ||
| 330 | AST_NODE(While) | 336 | AST_NODE(While) |
| 331 | ast_ptr<true, WhileType_t> type; | 337 | ast_ptr<true, WhileType_t> type; |
| 332 | ast_ptr<true, Exp_t> condition; | 338 | ast_ptr<true, Exp_t> condition; |
| 333 | ast_sel<true, Block_t, Statement_t> body; | 339 | ast_sel<true, Block_t, Statement_t> body; |
| 334 | AST_MEMBER(While, &type, &condition, &body) | 340 | AST_MEMBER(While, &type, &condition, &body) |
| 335 | AST_END(While, "while"sv) | 341 | AST_END(While) |
| 336 | 342 | ||
| 337 | AST_NODE(Repeat) | 343 | AST_NODE(Repeat) |
| 338 | ast_ptr<true, Body_t> body; | 344 | ast_ptr<true, Body_t> body; |
| 339 | ast_ptr<true, Exp_t> condition; | 345 | ast_ptr<true, Exp_t> condition; |
| 340 | AST_MEMBER(Repeat, &body, &condition) | 346 | AST_MEMBER(Repeat, &body, &condition) |
| 341 | AST_END(Repeat, "repeat"sv) | 347 | AST_END(Repeat) |
| 342 | 348 | ||
| 343 | AST_NODE(ForStepValue) | 349 | AST_NODE(ForStepValue) |
| 344 | ast_ptr<true, Exp_t> value; | 350 | ast_ptr<true, Exp_t> value; |
| 345 | AST_MEMBER(ForStepValue, &value) | 351 | AST_MEMBER(ForStepValue, &value) |
| 346 | AST_END(ForStepValue, "for_step_value"sv) | 352 | AST_END(ForStepValue) |
| 347 | 353 | ||
| 348 | AST_NODE(For) | 354 | AST_NODE(For) |
| 349 | ast_ptr<true, Variable_t> varName; | 355 | ast_ptr<true, Variable_t> varName; |
| @@ -352,61 +358,61 @@ AST_NODE(For) | |||
| 352 | ast_ptr<false, ForStepValue_t> stepValue; | 358 | ast_ptr<false, ForStepValue_t> stepValue; |
| 353 | ast_sel<true, Block_t, Statement_t> body; | 359 | ast_sel<true, Block_t, Statement_t> body; |
| 354 | AST_MEMBER(For, &varName, &startValue, &stopValue, &stepValue, &body) | 360 | AST_MEMBER(For, &varName, &startValue, &stopValue, &stepValue, &body) |
| 355 | AST_END(For, "for"sv) | 361 | AST_END(For) |
| 356 | 362 | ||
| 357 | AST_NODE(ForEach) | 363 | AST_NODE(ForEach) |
| 358 | ast_ptr<true, AssignableNameList_t> nameList; | 364 | ast_ptr<true, AssignableNameList_t> nameList; |
| 359 | ast_sel<true, StarExp_t, ExpList_t> loopValue; | 365 | ast_sel<true, StarExp_t, ExpList_t> loopValue; |
| 360 | ast_sel<true, Block_t, Statement_t> body; | 366 | ast_sel<true, Block_t, Statement_t> body; |
| 361 | AST_MEMBER(ForEach, &nameList, &loopValue, &body) | 367 | AST_MEMBER(ForEach, &nameList, &loopValue, &body) |
| 362 | AST_END(ForEach, "for_each"sv) | 368 | AST_END(ForEach) |
| 363 | 369 | ||
| 364 | AST_NODE(Do) | 370 | AST_NODE(Do) |
| 365 | ast_ptr<true, Body_t> body; | 371 | ast_ptr<true, Body_t> body; |
| 366 | AST_MEMBER(Do, &body) | 372 | AST_MEMBER(Do, &body) |
| 367 | AST_END(Do, "do"sv) | 373 | AST_END(Do) |
| 368 | 374 | ||
| 369 | AST_NODE(CatchBlock) | 375 | AST_NODE(CatchBlock) |
| 370 | ast_ptr<true, Variable_t> err; | 376 | ast_ptr<true, Variable_t> err; |
| 371 | ast_ptr<true, Block_t> block; | 377 | ast_ptr<true, Block_t> block; |
| 372 | AST_MEMBER(CatchBlock, &err, &block) | 378 | AST_MEMBER(CatchBlock, &err, &block) |
| 373 | AST_END(CatchBlock, "catch_block"sv) | 379 | AST_END(CatchBlock) |
| 374 | 380 | ||
| 375 | AST_NODE(Try) | 381 | AST_NODE(Try) |
| 376 | ast_sel<true, Block_t, Exp_t> func; | 382 | ast_sel<true, Block_t, Exp_t> func; |
| 377 | ast_ptr<false, CatchBlock_t> catchBlock; | 383 | ast_ptr<false, CatchBlock_t> catchBlock; |
| 378 | AST_MEMBER(Try, &func, &catchBlock) | 384 | AST_MEMBER(Try, &func, &catchBlock) |
| 379 | AST_END(Try, "try"sv) | 385 | AST_END(Try) |
| 380 | 386 | ||
| 381 | AST_NODE(Comprehension) | 387 | AST_NODE(Comprehension) |
| 382 | ast_ptr<true, Seperator_t> sep; | 388 | ast_ptr<true, Seperator_t> sep; |
| 383 | ast_sel_list<false, NormalDef_t, SpreadListExp_t, CompInner_t, | 389 | ast_sel_list<false, NormalDef_t, SpreadListExp_t, CompInner_t, |
| 384 | /*non-syntax-rule*/ Statement_t> items; | 390 | /*non-syntax-rule*/ Statement_t> items; |
| 385 | AST_MEMBER(Comprehension, &sep, &items) | 391 | AST_MEMBER(Comprehension, &sep, &items) |
| 386 | AST_END(Comprehension, "comp"sv) | 392 | AST_END(Comprehension) |
| 387 | 393 | ||
| 388 | AST_NODE(CompValue) | 394 | AST_NODE(CompValue) |
| 389 | ast_ptr<true, Exp_t> value; | 395 | ast_ptr<true, Exp_t> value; |
| 390 | AST_MEMBER(CompValue, &value) | 396 | AST_MEMBER(CompValue, &value) |
| 391 | AST_END(CompValue, "comp_value"sv) | 397 | AST_END(CompValue) |
| 392 | 398 | ||
| 393 | AST_NODE(TblComprehension) | 399 | AST_NODE(TblComprehension) |
| 394 | ast_ptr<true, Exp_t> key; | 400 | ast_ptr<true, Exp_t> key; |
| 395 | ast_ptr<false, CompValue_t> value; | 401 | ast_ptr<false, CompValue_t> value; |
| 396 | ast_ptr<true, CompInner_t> forLoop; | 402 | ast_ptr<true, CompInner_t> forLoop; |
| 397 | AST_MEMBER(TblComprehension, &key, &value, &forLoop) | 403 | AST_MEMBER(TblComprehension, &key, &value, &forLoop) |
| 398 | AST_END(TblComprehension, "tbl_comp"sv) | 404 | AST_END(TblComprehension) |
| 399 | 405 | ||
| 400 | AST_NODE(StarExp) | 406 | AST_NODE(StarExp) |
| 401 | ast_ptr<true, Exp_t> value; | 407 | ast_ptr<true, Exp_t> value; |
| 402 | AST_MEMBER(StarExp, &value) | 408 | AST_MEMBER(StarExp, &value) |
| 403 | AST_END(StarExp, "star_exp"sv) | 409 | AST_END(StarExp) |
| 404 | 410 | ||
| 405 | AST_NODE(CompForEach) | 411 | AST_NODE(CompForEach) |
| 406 | ast_ptr<true, AssignableNameList_t> nameList; | 412 | ast_ptr<true, AssignableNameList_t> nameList; |
| 407 | ast_sel<true, StarExp_t, Exp_t> loopValue; | 413 | ast_sel<true, StarExp_t, Exp_t> loopValue; |
| 408 | AST_MEMBER(CompForEach, &nameList, &loopValue) | 414 | AST_MEMBER(CompForEach, &nameList, &loopValue) |
| 409 | AST_END(CompForEach, "comp_for_each"sv) | 415 | AST_END(CompForEach) |
| 410 | 416 | ||
| 411 | AST_NODE(CompFor) | 417 | AST_NODE(CompFor) |
| 412 | ast_ptr<true, Variable_t> varName; | 418 | ast_ptr<true, Variable_t> varName; |
| @@ -414,54 +420,54 @@ AST_NODE(CompFor) | |||
| 414 | ast_ptr<true, Exp_t> stopValue; | 420 | ast_ptr<true, Exp_t> stopValue; |
| 415 | ast_ptr<false, ForStepValue_t> stepValue; | 421 | ast_ptr<false, ForStepValue_t> stepValue; |
| 416 | AST_MEMBER(CompFor, &varName, &startValue, &stopValue, &stepValue) | 422 | AST_MEMBER(CompFor, &varName, &startValue, &stopValue, &stepValue) |
| 417 | AST_END(CompFor, "comp_for"sv) | 423 | AST_END(CompFor) |
| 418 | 424 | ||
| 419 | AST_NODE(CompInner) | 425 | AST_NODE(CompInner) |
| 420 | ast_ptr<true, Seperator_t> sep; | 426 | ast_ptr<true, Seperator_t> sep; |
| 421 | ast_sel_list<true, CompFor_t, CompForEach_t, Exp_t> items; | 427 | ast_sel_list<true, CompFor_t, CompForEach_t, Exp_t> items; |
| 422 | AST_MEMBER(CompInner, &sep, &items) | 428 | AST_MEMBER(CompInner, &sep, &items) |
| 423 | AST_END(CompInner, "comp_inner"sv) | 429 | AST_END(CompInner) |
| 424 | 430 | ||
| 425 | AST_NODE(Assign) | 431 | AST_NODE(Assign) |
| 426 | ast_ptr<true, Seperator_t> sep; | 432 | ast_ptr<true, Seperator_t> sep; |
| 427 | ast_sel_list<true, With_t, If_t, Switch_t, TableBlock_t, Exp_t> values; | 433 | ast_sel_list<true, With_t, If_t, Switch_t, TableBlock_t, Exp_t> values; |
| 428 | AST_MEMBER(Assign, &sep, &values) | 434 | AST_MEMBER(Assign, &sep, &values) |
| 429 | AST_END(Assign, "assign"sv) | 435 | AST_END(Assign) |
| 430 | 436 | ||
| 431 | AST_LEAF(UpdateOp) | 437 | AST_LEAF(UpdateOp) |
| 432 | AST_END(UpdateOp, "update_op"sv) | 438 | AST_END(UpdateOp) |
| 433 | 439 | ||
| 434 | AST_NODE(Update) | 440 | AST_NODE(Update) |
| 435 | ast_ptr<true, UpdateOp_t> op; | 441 | ast_ptr<true, UpdateOp_t> op; |
| 436 | ast_ptr<true, Exp_t> value; | 442 | ast_ptr<true, Exp_t> value; |
| 437 | AST_MEMBER(Update, &op, &value) | 443 | AST_MEMBER(Update, &op, &value) |
| 438 | AST_END(Update, "update"sv) | 444 | AST_END(Update) |
| 439 | 445 | ||
| 440 | AST_LEAF(BinaryOperator) | 446 | AST_LEAF(BinaryOperator) |
| 441 | AST_END(BinaryOperator, "binary_op"sv) | 447 | AST_END(BinaryOperator) |
| 442 | 448 | ||
| 443 | AST_LEAF(UnaryOperator) | 449 | AST_LEAF(UnaryOperator) |
| 444 | AST_END(UnaryOperator, "unary_op"sv) | 450 | AST_END(UnaryOperator) |
| 445 | 451 | ||
| 446 | AST_LEAF(NotIn) | 452 | AST_LEAF(NotIn) |
| 447 | AST_END(NotIn, "not_in"sv) | 453 | AST_END(NotIn) |
| 448 | 454 | ||
| 449 | AST_NODE(In) | 455 | AST_NODE(In) |
| 450 | ast_ptr<false, NotIn_t> not_; | 456 | ast_ptr<false, NotIn_t> not_; |
| 451 | ast_ptr<true, Value_t> value; | 457 | ast_ptr<true, Value_t> value; |
| 452 | AST_MEMBER(In, ¬_, &value) | 458 | AST_MEMBER(In, ¬_, &value) |
| 453 | AST_END(In, "in"sv) | 459 | AST_END(In) |
| 454 | 460 | ||
| 455 | AST_NODE(Assignable) | 461 | AST_NODE(Assignable) |
| 456 | ast_sel<true, AssignableChain_t, Variable_t, SelfItem_t> item; | 462 | ast_sel<true, AssignableChain_t, Variable_t, SelfItem_t> item; |
| 457 | AST_MEMBER(Assignable, &item) | 463 | AST_MEMBER(Assignable, &item) |
| 458 | AST_END(Assignable, "assignable"sv) | 464 | AST_END(Assignable) |
| 459 | 465 | ||
| 460 | AST_NODE(ExpOpValue) | 466 | AST_NODE(ExpOpValue) |
| 461 | ast_ptr<true, BinaryOperator_t> op; | 467 | ast_ptr<true, BinaryOperator_t> op; |
| 462 | ast_list<true, UnaryExp_t> pipeExprs; | 468 | ast_list<true, UnaryExp_t> pipeExprs; |
| 463 | AST_MEMBER(ExpOpValue, &op, &pipeExprs) | 469 | AST_MEMBER(ExpOpValue, &op, &pipeExprs) |
| 464 | AST_END(ExpOpValue, "exp_op_value"sv) | 470 | AST_END(ExpOpValue) |
| 465 | 471 | ||
| 466 | AST_NODE(Exp) | 472 | AST_NODE(Exp) |
| 467 | ast_ptr<true, Seperator_t> sep; | 473 | ast_ptr<true, Seperator_t> sep; |
| @@ -469,71 +475,71 @@ AST_NODE(Exp) | |||
| 469 | ast_list<false, ExpOpValue_t> opValues; | 475 | ast_list<false, ExpOpValue_t> opValues; |
| 470 | ast_ptr<false, Exp_t> nilCoalesed; | 476 | ast_ptr<false, Exp_t> nilCoalesed; |
| 471 | AST_MEMBER(Exp, &sep, &pipeExprs, &opValues, &nilCoalesed) | 477 | AST_MEMBER(Exp, &sep, &pipeExprs, &opValues, &nilCoalesed) |
| 472 | AST_END(Exp, "exp"sv) | 478 | AST_END(Exp) |
| 473 | 479 | ||
| 474 | AST_NODE(Callable) | 480 | AST_NODE(Callable) |
| 475 | ast_sel<true, Variable_t, SelfItem_t, Parens_t, MacroName_t> item; | 481 | ast_sel<true, Variable_t, SelfItem_t, Parens_t, MacroName_t> item; |
| 476 | AST_MEMBER(Callable, &item) | 482 | AST_MEMBER(Callable, &item) |
| 477 | AST_END(Callable, "callable"sv) | 483 | AST_END(Callable) |
| 478 | 484 | ||
| 479 | AST_NODE(VariablePair) | 485 | AST_NODE(VariablePair) |
| 480 | ast_ptr<true, Variable_t> name; | 486 | ast_ptr<true, Variable_t> name; |
| 481 | AST_MEMBER(VariablePair, &name) | 487 | AST_MEMBER(VariablePair, &name) |
| 482 | AST_END(VariablePair, "variable_pair"sv) | 488 | AST_END(VariablePair) |
| 483 | 489 | ||
| 484 | AST_NODE(VariablePairDef) | 490 | AST_NODE(VariablePairDef) |
| 485 | ast_ptr<true, VariablePair_t> pair; | 491 | ast_ptr<true, VariablePair_t> pair; |
| 486 | ast_ptr<false, Exp_t> defVal; | 492 | ast_ptr<false, Exp_t> defVal; |
| 487 | AST_MEMBER(VariablePairDef, &pair, &defVal) | 493 | AST_MEMBER(VariablePairDef, &pair, &defVal) |
| 488 | AST_END(VariablePairDef, "variable_pair_def"sv) | 494 | AST_END(VariablePairDef) |
| 489 | 495 | ||
| 490 | AST_NODE(NormalPair) | 496 | AST_NODE(NormalPair) |
| 491 | ast_sel<true, KeyName_t, Exp_t, String_t> key; | 497 | ast_sel<true, KeyName_t, Exp_t, String_t> key; |
| 492 | ast_sel<true, Exp_t, TableBlock_t> value; | 498 | ast_sel<true, Exp_t, TableBlock_t> value; |
| 493 | AST_MEMBER(NormalPair, &key, &value) | 499 | AST_MEMBER(NormalPair, &key, &value) |
| 494 | AST_END(NormalPair, "normal_pair"sv) | 500 | AST_END(NormalPair) |
| 495 | 501 | ||
| 496 | AST_NODE(NormalPairDef) | 502 | AST_NODE(NormalPairDef) |
| 497 | ast_ptr<true, NormalPair_t> pair; | 503 | ast_ptr<true, NormalPair_t> pair; |
| 498 | ast_ptr<false, Exp_t> defVal; | 504 | ast_ptr<false, Exp_t> defVal; |
| 499 | AST_MEMBER(NormalPairDef, &pair, &defVal) | 505 | AST_MEMBER(NormalPairDef, &pair, &defVal) |
| 500 | AST_END(NormalPairDef, "normal_pair_def"sv) | 506 | AST_END(NormalPairDef) |
| 501 | 507 | ||
| 502 | AST_NODE(NormalDef) | 508 | AST_NODE(NormalDef) |
| 503 | ast_ptr<true, Exp_t> item; | 509 | ast_ptr<true, Exp_t> item; |
| 504 | ast_ptr<true, Seperator_t> sep; | 510 | ast_ptr<true, Seperator_t> sep; |
| 505 | ast_ptr<false, Exp_t> defVal; | 511 | ast_ptr<false, Exp_t> defVal; |
| 506 | AST_MEMBER(NormalDef, &item, &sep, &defVal) | 512 | AST_MEMBER(NormalDef, &item, &sep, &defVal) |
| 507 | AST_END(NormalDef, "normal_def") | 513 | AST_END(NormalDef) |
| 508 | 514 | ||
| 509 | AST_NODE(MetaVariablePair) | 515 | AST_NODE(MetaVariablePair) |
| 510 | ast_ptr<true, Variable_t> name; | 516 | ast_ptr<true, Variable_t> name; |
| 511 | AST_MEMBER(MetaVariablePair, &name) | 517 | AST_MEMBER(MetaVariablePair, &name) |
| 512 | AST_END(MetaVariablePair, "meta_variable_pair"sv) | 518 | AST_END(MetaVariablePair) |
| 513 | 519 | ||
| 514 | AST_NODE(MetaVariablePairDef) | 520 | AST_NODE(MetaVariablePairDef) |
| 515 | ast_ptr<true, MetaVariablePair_t> pair; | 521 | ast_ptr<true, MetaVariablePair_t> pair; |
| 516 | ast_ptr<false, Exp_t> defVal; | 522 | ast_ptr<false, Exp_t> defVal; |
| 517 | AST_MEMBER(MetaVariablePairDef, &pair, &defVal) | 523 | AST_MEMBER(MetaVariablePairDef, &pair, &defVal) |
| 518 | AST_END(MetaVariablePairDef, "meta_variable_pair_def"sv) | 524 | AST_END(MetaVariablePairDef) |
| 519 | 525 | ||
| 520 | AST_NODE(MetaNormalPair) | 526 | AST_NODE(MetaNormalPair) |
| 521 | ast_sel<false, Name_t, Exp_t, String_t> key; | 527 | ast_sel<false, Name_t, Exp_t, String_t> key; |
| 522 | ast_sel<true, Exp_t, TableBlock_t> value; | 528 | ast_sel<true, Exp_t, TableBlock_t> value; |
| 523 | AST_MEMBER(MetaNormalPair, &key, &value) | 529 | AST_MEMBER(MetaNormalPair, &key, &value) |
| 524 | AST_END(MetaNormalPair, "meta_normal_pair"sv) | 530 | AST_END(MetaNormalPair) |
| 525 | 531 | ||
| 526 | AST_NODE(MetaNormalPairDef) | 532 | AST_NODE(MetaNormalPairDef) |
| 527 | ast_ptr<true, MetaNormalPair_t> pair; | 533 | ast_ptr<true, MetaNormalPair_t> pair; |
| 528 | ast_ptr<false, Exp_t> defVal; | 534 | ast_ptr<false, Exp_t> defVal; |
| 529 | AST_MEMBER(MetaNormalPairDef, &pair, &defVal) | 535 | AST_MEMBER(MetaNormalPairDef, &pair, &defVal) |
| 530 | AST_END(MetaNormalPairDef, "meta_normal_pair_def"sv) | 536 | AST_END(MetaNormalPairDef) |
| 531 | 537 | ||
| 532 | AST_NODE(SimpleTable) | 538 | AST_NODE(SimpleTable) |
| 533 | ast_ptr<true, Seperator_t> sep; | 539 | ast_ptr<true, Seperator_t> sep; |
| 534 | ast_sel_list<true, VariablePair_t, NormalPair_t, MetaVariablePair_t, MetaNormalPair_t> pairs; | 540 | ast_sel_list<true, VariablePair_t, NormalPair_t, MetaVariablePair_t, MetaNormalPair_t> pairs; |
| 535 | AST_MEMBER(SimpleTable, &sep, &pairs) | 541 | AST_MEMBER(SimpleTable, &sep, &pairs) |
| 536 | AST_END(SimpleTable, "simple_table"sv) | 542 | AST_END(SimpleTable) |
| 537 | 543 | ||
| 538 | AST_NODE(SimpleValue) | 544 | AST_NODE(SimpleValue) |
| 539 | ast_sel<true, | 545 | ast_sel<true, |
| @@ -544,118 +550,118 @@ AST_NODE(SimpleValue) | |||
| 544 | TblComprehension_t, Comprehension_t, | 550 | TblComprehension_t, Comprehension_t, |
| 545 | FunLit_t, Num_t, VarArg_t> value; | 551 | FunLit_t, Num_t, VarArg_t> value; |
| 546 | AST_MEMBER(SimpleValue, &value) | 552 | AST_MEMBER(SimpleValue, &value) |
| 547 | AST_END(SimpleValue, "simple_value"sv) | 553 | AST_END(SimpleValue) |
| 548 | 554 | ||
| 549 | AST_LEAF(LuaStringOpen) | 555 | AST_LEAF(LuaStringOpen) |
| 550 | AST_END(LuaStringOpen, "lua_string_open"sv) | 556 | AST_END(LuaStringOpen) |
| 551 | 557 | ||
| 552 | AST_LEAF(LuaStringContent) | 558 | AST_LEAF(LuaStringContent) |
| 553 | AST_END(LuaStringContent, "lua_string_content"sv) | 559 | AST_END(LuaStringContent) |
| 554 | 560 | ||
| 555 | AST_LEAF(LuaStringClose) | 561 | AST_LEAF(LuaStringClose) |
| 556 | AST_END(LuaStringClose, "lua_string_close"sv) | 562 | AST_END(LuaStringClose) |
| 557 | 563 | ||
| 558 | AST_NODE(LuaString) | 564 | AST_NODE(LuaString) |
| 559 | ast_ptr<true, LuaStringOpen_t> open; | 565 | ast_ptr<true, LuaStringOpen_t> open; |
| 560 | ast_ptr<true, LuaStringContent_t> content; | 566 | ast_ptr<true, LuaStringContent_t> content; |
| 561 | ast_ptr<true, LuaStringClose_t> close; | 567 | ast_ptr<true, LuaStringClose_t> close; |
| 562 | AST_MEMBER(LuaString, &open, &content, &close) | 568 | AST_MEMBER(LuaString, &open, &content, &close) |
| 563 | AST_END(LuaString, "lua_string"sv) | 569 | AST_END(LuaString) |
| 564 | 570 | ||
| 565 | AST_LEAF(SingleString) | 571 | AST_LEAF(SingleString) |
| 566 | AST_END(SingleString, "single_string"sv) | 572 | AST_END(SingleString) |
| 567 | 573 | ||
| 568 | AST_LEAF(DoubleStringInner) | 574 | AST_LEAF(DoubleStringInner) |
| 569 | AST_END(DoubleStringInner, "double_string_inner"sv) | 575 | AST_END(DoubleStringInner) |
| 570 | 576 | ||
| 571 | AST_NODE(DoubleStringContent) | 577 | AST_NODE(DoubleStringContent) |
| 572 | ast_sel<true, DoubleStringInner_t, Exp_t> content; | 578 | ast_sel<true, DoubleStringInner_t, Exp_t> content; |
| 573 | AST_MEMBER(DoubleStringContent, &content) | 579 | AST_MEMBER(DoubleStringContent, &content) |
| 574 | AST_END(DoubleStringContent, "double_string_content"sv) | 580 | AST_END(DoubleStringContent) |
| 575 | 581 | ||
| 576 | AST_NODE(DoubleString) | 582 | AST_NODE(DoubleString) |
| 577 | ast_ptr<true, Seperator_t> sep; | 583 | ast_ptr<true, Seperator_t> sep; |
| 578 | ast_list<false, DoubleStringContent_t> segments; | 584 | ast_list<false, DoubleStringContent_t> segments; |
| 579 | AST_MEMBER(DoubleString, &sep, &segments) | 585 | AST_MEMBER(DoubleString, &sep, &segments) |
| 580 | AST_END(DoubleString, "double_string"sv) | 586 | AST_END(DoubleString) |
| 581 | 587 | ||
| 582 | AST_NODE(String) | 588 | AST_NODE(String) |
| 583 | ast_sel<true, DoubleString_t, SingleString_t, LuaString_t> str; | 589 | ast_sel<true, DoubleString_t, SingleString_t, LuaString_t> str; |
| 584 | AST_MEMBER(String, &str) | 590 | AST_MEMBER(String, &str) |
| 585 | AST_END(String, "string"sv) | 591 | AST_END(String) |
| 586 | 592 | ||
| 587 | AST_LEAF(Metatable) | 593 | AST_LEAF(Metatable) |
| 588 | AST_END(Metatable, "metatable"sv) | 594 | AST_END(Metatable) |
| 589 | 595 | ||
| 590 | AST_NODE(Metamethod) | 596 | AST_NODE(Metamethod) |
| 591 | ast_sel<true, Name_t, Exp_t, String_t> item; | 597 | ast_sel<true, Name_t, Exp_t, String_t> item; |
| 592 | AST_MEMBER(Metamethod, &item) | 598 | AST_MEMBER(Metamethod, &item) |
| 593 | AST_END(Metamethod, "metamethod"sv) | 599 | AST_END(Metamethod) |
| 594 | 600 | ||
| 595 | AST_NODE(DotChainItem) | 601 | AST_NODE(DotChainItem) |
| 596 | ast_sel<true, Name_t, Metatable_t, Metamethod_t, UnicodeName_t> name; | 602 | ast_sel<true, Name_t, Metatable_t, Metamethod_t, UnicodeName_t> name; |
| 597 | AST_MEMBER(DotChainItem, &name) | 603 | AST_MEMBER(DotChainItem, &name) |
| 598 | AST_END(DotChainItem, "dot_chain_item"sv) | 604 | AST_END(DotChainItem) |
| 599 | 605 | ||
| 600 | AST_NODE(ColonChainItem) | 606 | AST_NODE(ColonChainItem) |
| 601 | ast_sel<true, Name_t, LuaKeyword_t, Metamethod_t, UnicodeName_t> name; | 607 | ast_sel<true, Name_t, LuaKeyword_t, Metamethod_t, UnicodeName_t> name; |
| 602 | bool switchToDot = false; | 608 | bool switchToDot = false; |
| 603 | AST_MEMBER(ColonChainItem, &name) | 609 | AST_MEMBER(ColonChainItem, &name) |
| 604 | AST_END(ColonChainItem, "colon_chain_item"sv) | 610 | AST_END(ColonChainItem) |
| 605 | 611 | ||
| 606 | AST_NODE(Slice) | 612 | AST_NODE(Slice) |
| 607 | ast_sel<true, Exp_t, DefaultValue_t> startValue; | 613 | ast_sel<true, Exp_t, DefaultValue_t> startValue; |
| 608 | ast_sel<true, Exp_t, DefaultValue_t> stopValue; | 614 | ast_sel<true, Exp_t, DefaultValue_t> stopValue; |
| 609 | ast_sel<true, Exp_t, DefaultValue_t> stepValue; | 615 | ast_sel<true, Exp_t, DefaultValue_t> stepValue; |
| 610 | AST_MEMBER(Slice, &startValue, &stopValue, &stepValue) | 616 | AST_MEMBER(Slice, &startValue, &stopValue, &stepValue) |
| 611 | AST_END(Slice, "slice"sv) | 617 | AST_END(Slice) |
| 612 | 618 | ||
| 613 | AST_NODE(Parens) | 619 | AST_NODE(Parens) |
| 614 | ast_ptr<true, Exp_t> expr; | 620 | ast_ptr<true, Exp_t> expr; |
| 615 | AST_MEMBER(Parens, &expr) | 621 | AST_MEMBER(Parens, &expr) |
| 616 | AST_END(Parens, "parens"sv) | 622 | AST_END(Parens) |
| 617 | 623 | ||
| 618 | AST_NODE(Invoke) | 624 | AST_NODE(Invoke) |
| 619 | ast_ptr<true, Seperator_t> sep; | 625 | ast_ptr<true, Seperator_t> sep; |
| 620 | ast_sel_list<false, Exp_t, SingleString_t, DoubleString_t, LuaString_t, TableLit_t> args; | 626 | ast_sel_list<false, Exp_t, SingleString_t, DoubleString_t, LuaString_t, TableLit_t> args; |
| 621 | AST_MEMBER(Invoke, &sep, &args) | 627 | AST_MEMBER(Invoke, &sep, &args) |
| 622 | AST_END(Invoke, "invoke"sv) | 628 | AST_END(Invoke) |
| 623 | 629 | ||
| 624 | AST_LEAF(ExistentialOp) | 630 | AST_LEAF(ExistentialOp) |
| 625 | AST_END(ExistentialOp, "existential_op"sv) | 631 | AST_END(ExistentialOp) |
| 626 | 632 | ||
| 627 | AST_LEAF(TableAppendingOp) | 633 | AST_LEAF(TableAppendingOp) |
| 628 | AST_END(TableAppendingOp, "table_appending_op"sv) | 634 | AST_END(TableAppendingOp) |
| 629 | 635 | ||
| 630 | AST_NODE(ChainValue) | 636 | AST_NODE(ChainValue) |
| 631 | ast_ptr<true, Seperator_t> sep; | 637 | ast_ptr<true, Seperator_t> sep; |
| 632 | ast_sel_list<true, Callable_t, Invoke_t, DotChainItem_t, ColonChainItem_t, Slice_t, Exp_t, String_t, InvokeArgs_t, ExistentialOp_t, TableAppendingOp_t> items; | 638 | ast_sel_list<true, Callable_t, Invoke_t, DotChainItem_t, ColonChainItem_t, Slice_t, Exp_t, String_t, InvokeArgs_t, ExistentialOp_t, TableAppendingOp_t> items; |
| 633 | AST_MEMBER(ChainValue, &sep, &items) | 639 | AST_MEMBER(ChainValue, &sep, &items) |
| 634 | AST_END(ChainValue, "chain_value"sv) | 640 | AST_END(ChainValue) |
| 635 | 641 | ||
| 636 | AST_NODE(AssignableChain) | 642 | AST_NODE(AssignableChain) |
| 637 | ast_ptr<true, Seperator_t> sep; | 643 | ast_ptr<true, Seperator_t> sep; |
| 638 | ast_sel_list<true, Callable_t, Invoke_t, DotChainItem_t, ColonChainItem_t, Exp_t, String_t> items; | 644 | ast_sel_list<true, Callable_t, Invoke_t, DotChainItem_t, ColonChainItem_t, Exp_t, String_t> items; |
| 639 | AST_MEMBER(AssignableChain, &sep, &items) | 645 | AST_MEMBER(AssignableChain, &sep, &items) |
| 640 | AST_END(AssignableChain, "assignable_chain"sv) | 646 | AST_END(AssignableChain) |
| 641 | 647 | ||
| 642 | AST_NODE(Value) | 648 | AST_NODE(Value) |
| 643 | ast_sel<true, SimpleValue_t, SimpleTable_t, ChainValue_t, String_t> item; | 649 | ast_sel<true, SimpleValue_t, SimpleTable_t, ChainValue_t, String_t> item; |
| 644 | AST_MEMBER(Value, &item) | 650 | AST_MEMBER(Value, &item) |
| 645 | AST_END(Value, "value"sv) | 651 | AST_END(Value) |
| 646 | 652 | ||
| 647 | AST_LEAF(DefaultValue) | 653 | AST_LEAF(DefaultValue) |
| 648 | AST_END(DefaultValue, "default_value"sv) | 654 | AST_END(DefaultValue) |
| 649 | 655 | ||
| 650 | AST_NODE(SpreadExp) | 656 | AST_NODE(SpreadExp) |
| 651 | ast_ptr<true, Exp_t> exp; | 657 | ast_ptr<true, Exp_t> exp; |
| 652 | AST_MEMBER(SpreadExp, &exp) | 658 | AST_MEMBER(SpreadExp, &exp) |
| 653 | AST_END(SpreadExp, "spread_exp"sv) | 659 | AST_END(SpreadExp) |
| 654 | 660 | ||
| 655 | AST_NODE(SpreadListExp) | 661 | AST_NODE(SpreadListExp) |
| 656 | ast_ptr<true, Exp_t> exp; | 662 | ast_ptr<true, Exp_t> exp; |
| 657 | AST_MEMBER(SpreadListExp, &exp) | 663 | AST_MEMBER(SpreadListExp, &exp) |
| 658 | AST_END(SpreadListExp, "spread_list_exp"sv) | 664 | AST_END(SpreadListExp) |
| 659 | 665 | ||
| 660 | AST_NODE(TableLit) | 666 | AST_NODE(TableLit) |
| 661 | ast_ptr<true, Seperator_t> sep; | 667 | ast_ptr<true, Seperator_t> sep; |
| @@ -666,7 +672,7 @@ AST_NODE(TableLit) | |||
| 666 | MetaVariablePair_t, MetaNormalPair_t, | 672 | MetaVariablePair_t, MetaNormalPair_t, |
| 667 | /*non-syntax-rule*/ TableBlockIndent_t, SpreadListExp_t> values; | 673 | /*non-syntax-rule*/ TableBlockIndent_t, SpreadListExp_t> values; |
| 668 | AST_MEMBER(TableLit, &sep, &values) | 674 | AST_MEMBER(TableLit, &sep, &values) |
| 669 | AST_END(TableLit, "table_lit"sv) | 675 | AST_END(TableLit) |
| 670 | 676 | ||
| 671 | AST_NODE(TableBlockIndent) | 677 | AST_NODE(TableBlockIndent) |
| 672 | ast_ptr<true, Seperator_t> sep; | 678 | ast_ptr<true, Seperator_t> sep; |
| @@ -674,25 +680,25 @@ AST_NODE(TableBlockIndent) | |||
| 674 | VariablePair_t, NormalPair_t, Exp_t, TableBlockIndent_t, | 680 | VariablePair_t, NormalPair_t, Exp_t, TableBlockIndent_t, |
| 675 | MetaVariablePair_t, MetaNormalPair_t> values; | 681 | MetaVariablePair_t, MetaNormalPair_t> values; |
| 676 | AST_MEMBER(TableBlockIndent, &sep, &values) | 682 | AST_MEMBER(TableBlockIndent, &sep, &values) |
| 677 | AST_END(TableBlockIndent, "table_block_indent"sv) | 683 | AST_END(TableBlockIndent) |
| 678 | 684 | ||
| 679 | AST_NODE(TableBlock) | 685 | AST_NODE(TableBlock) |
| 680 | ast_ptr<true, Seperator_t> sep; | 686 | ast_ptr<true, Seperator_t> sep; |
| 681 | ast_sel_list<false, VariablePair_t, NormalPair_t, TableBlockIndent_t, Exp_t, TableBlock_t, SpreadExp_t, MetaVariablePair_t, MetaNormalPair_t> values; | 687 | ast_sel_list<false, VariablePair_t, NormalPair_t, TableBlockIndent_t, Exp_t, TableBlock_t, SpreadExp_t, MetaVariablePair_t, MetaNormalPair_t> values; |
| 682 | AST_MEMBER(TableBlock, &sep, &values) | 688 | AST_MEMBER(TableBlock, &sep, &values) |
| 683 | AST_END(TableBlock, "table_block"sv) | 689 | AST_END(TableBlock) |
| 684 | 690 | ||
| 685 | AST_NODE(ClassMemberList) | 691 | AST_NODE(ClassMemberList) |
| 686 | ast_ptr<true, Seperator_t> sep; | 692 | ast_ptr<true, Seperator_t> sep; |
| 687 | ast_sel_list<true, VariablePair_t, NormalPair_t, MetaVariablePair_t, MetaNormalPair_t> values; | 693 | ast_sel_list<true, VariablePair_t, NormalPair_t, MetaVariablePair_t, MetaNormalPair_t> values; |
| 688 | AST_MEMBER(ClassMemberList, &sep, &values) | 694 | AST_MEMBER(ClassMemberList, &sep, &values) |
| 689 | AST_END(ClassMemberList, "class_member_list"sv) | 695 | AST_END(ClassMemberList) |
| 690 | 696 | ||
| 691 | AST_NODE(ClassBlock) | 697 | AST_NODE(ClassBlock) |
| 692 | ast_ptr<true, Seperator_t> sep; | 698 | ast_ptr<true, Seperator_t> sep; |
| 693 | ast_sel_list<true, ClassMemberList_t, Statement_t> contents; | 699 | ast_sel_list<true, ClassMemberList_t, Statement_t> contents; |
| 694 | AST_MEMBER(ClassBlock, &sep, &contents) | 700 | AST_MEMBER(ClassBlock, &sep, &contents) |
| 695 | AST_END(ClassBlock, "class_block"sv) | 701 | AST_END(ClassBlock) |
| 696 | 702 | ||
| 697 | AST_NODE(ClassDecl) | 703 | AST_NODE(ClassDecl) |
| 698 | ast_ptr<false, Assignable_t> name; | 704 | ast_ptr<false, Assignable_t> name; |
| @@ -700,59 +706,59 @@ AST_NODE(ClassDecl) | |||
| 700 | ast_ptr<false, ExpList_t> mixes; | 706 | ast_ptr<false, ExpList_t> mixes; |
| 701 | ast_ptr<false, ClassBlock_t> body; | 707 | ast_ptr<false, ClassBlock_t> body; |
| 702 | AST_MEMBER(ClassDecl, &name, &extend, &mixes, &body) | 708 | AST_MEMBER(ClassDecl, &name, &extend, &mixes, &body) |
| 703 | AST_END(ClassDecl, "class_decl"sv) | 709 | AST_END(ClassDecl) |
| 704 | 710 | ||
| 705 | AST_NODE(GlobalValues) | 711 | AST_NODE(GlobalValues) |
| 706 | ast_ptr<true, NameList_t> nameList; | 712 | ast_ptr<true, NameList_t> nameList; |
| 707 | ast_sel<false, TableBlock_t, ExpListLow_t> valueList; | 713 | ast_sel<false, TableBlock_t, ExpListLow_t> valueList; |
| 708 | AST_MEMBER(GlobalValues, &nameList, &valueList) | 714 | AST_MEMBER(GlobalValues, &nameList, &valueList) |
| 709 | AST_END(GlobalValues, "global_values"sv) | 715 | AST_END(GlobalValues) |
| 710 | 716 | ||
| 711 | AST_LEAF(GlobalOp) | 717 | AST_LEAF(GlobalOp) |
| 712 | AST_END(GlobalOp, "global_op"sv) | 718 | AST_END(GlobalOp) |
| 713 | 719 | ||
| 714 | AST_NODE(Global) | 720 | AST_NODE(Global) |
| 715 | ast_sel<true, ClassDecl_t, GlobalOp_t, GlobalValues_t> item; | 721 | ast_sel<true, ClassDecl_t, GlobalOp_t, GlobalValues_t> item; |
| 716 | AST_MEMBER(Global, &item) | 722 | AST_MEMBER(Global, &item) |
| 717 | AST_END(Global, "global"sv) | 723 | AST_END(Global) |
| 718 | 724 | ||
| 719 | AST_LEAF(ExportDefault) | 725 | AST_LEAF(ExportDefault) |
| 720 | AST_END(ExportDefault, "export_default"sv) | 726 | AST_END(ExportDefault) |
| 721 | 727 | ||
| 722 | AST_NODE(Export) | 728 | AST_NODE(Export) |
| 723 | ast_ptr<false, ExportDefault_t> def; | 729 | ast_ptr<false, ExportDefault_t> def; |
| 724 | ast_sel<true, ExpList_t, Exp_t, Macro_t, DotChainItem_t> target; | 730 | ast_sel<true, ExpList_t, Exp_t, Macro_t, DotChainItem_t> target; |
| 725 | ast_ptr<false, Assign_t> assign; | 731 | ast_ptr<false, Assign_t> assign; |
| 726 | AST_MEMBER(Export, &def, &target, &assign) | 732 | AST_MEMBER(Export, &def, &target, &assign) |
| 727 | AST_END(Export, "export"sv) | 733 | AST_END(Export) |
| 728 | 734 | ||
| 729 | AST_NODE(FnArgDef) | 735 | AST_NODE(FnArgDef) |
| 730 | ast_sel<true, Variable_t, SelfItem_t> name; | 736 | ast_sel<true, Variable_t, SelfItem_t> name; |
| 731 | ast_ptr<false, ExistentialOp_t> op; | 737 | ast_ptr<false, ExistentialOp_t> op; |
| 732 | ast_ptr<false, Exp_t> defaultValue; | 738 | ast_ptr<false, Exp_t> defaultValue; |
| 733 | AST_MEMBER(FnArgDef, &name, &op, &defaultValue) | 739 | AST_MEMBER(FnArgDef, &name, &op, &defaultValue) |
| 734 | AST_END(FnArgDef, "fn_arg_def"sv) | 740 | AST_END(FnArgDef) |
| 735 | 741 | ||
| 736 | AST_NODE(FnArgDefList) | 742 | AST_NODE(FnArgDefList) |
| 737 | ast_ptr<true, Seperator_t> sep; | 743 | ast_ptr<true, Seperator_t> sep; |
| 738 | ast_list<false, FnArgDef_t> definitions; | 744 | ast_list<false, FnArgDef_t> definitions; |
| 739 | ast_ptr<false, VarArg_t> varArg; | 745 | ast_ptr<false, VarArg_t> varArg; |
| 740 | AST_MEMBER(FnArgDefList, &sep, &definitions, &varArg) | 746 | AST_MEMBER(FnArgDefList, &sep, &definitions, &varArg) |
| 741 | AST_END(FnArgDefList, "fn_arg_def_list"sv) | 747 | AST_END(FnArgDefList) |
| 742 | 748 | ||
| 743 | AST_NODE(OuterVarShadow) | 749 | AST_NODE(OuterVarShadow) |
| 744 | ast_ptr<false, NameList_t> varList; | 750 | ast_ptr<false, NameList_t> varList; |
| 745 | AST_MEMBER(OuterVarShadow, &varList) | 751 | AST_MEMBER(OuterVarShadow, &varList) |
| 746 | AST_END(OuterVarShadow, "outer_var_shadow"sv) | 752 | AST_END(OuterVarShadow) |
| 747 | 753 | ||
| 748 | AST_NODE(FnArgsDef) | 754 | AST_NODE(FnArgsDef) |
| 749 | ast_ptr<false, FnArgDefList_t> defList; | 755 | ast_ptr<false, FnArgDefList_t> defList; |
| 750 | ast_ptr<false, OuterVarShadow_t> shadowOption; | 756 | ast_ptr<false, OuterVarShadow_t> shadowOption; |
| 751 | AST_MEMBER(FnArgsDef, &defList, &shadowOption) | 757 | AST_MEMBER(FnArgsDef, &defList, &shadowOption) |
| 752 | AST_END(FnArgsDef, "fn_args_def"sv) | 758 | AST_END(FnArgsDef) |
| 753 | 759 | ||
| 754 | AST_LEAF(FnArrow) | 760 | AST_LEAF(FnArrow) |
| 755 | AST_END(FnArrow, "fn_arrow"sv) | 761 | AST_END(FnArrow) |
| 756 | 762 | ||
| 757 | AST_NODE(FunLit) | 763 | AST_NODE(FunLit) |
| 758 | ast_ptr<false, FnArgsDef_t> argsDef; | 764 | ast_ptr<false, FnArgsDef_t> argsDef; |
| @@ -761,121 +767,121 @@ AST_NODE(FunLit) | |||
| 761 | ast_ptr<false, Body_t> body; | 767 | ast_ptr<false, Body_t> body; |
| 762 | bool noRecursion = false; | 768 | bool noRecursion = false; |
| 763 | AST_MEMBER(FunLit, &argsDef, &defaultReturn, &arrow, &body) | 769 | AST_MEMBER(FunLit, &argsDef, &defaultReturn, &arrow, &body) |
| 764 | AST_END(FunLit, "fun_lit"sv) | 770 | AST_END(FunLit) |
| 765 | 771 | ||
| 766 | AST_NODE(MacroName) | 772 | AST_NODE(MacroName) |
| 767 | ast_ptr<true, UnicodeName_t> name; | 773 | ast_ptr<true, UnicodeName_t> name; |
| 768 | AST_MEMBER(MacroName, &name) | 774 | AST_MEMBER(MacroName, &name) |
| 769 | AST_END(MacroName, "macro_name"sv) | 775 | AST_END(MacroName) |
| 770 | 776 | ||
| 771 | AST_NODE(MacroLit) | 777 | AST_NODE(MacroLit) |
| 772 | ast_ptr<false, FnArgDefList_t> argsDef; | 778 | ast_ptr<false, FnArgDefList_t> argsDef; |
| 773 | ast_ptr<true, Body_t> body; | 779 | ast_ptr<true, Body_t> body; |
| 774 | AST_MEMBER(MacroLit, &argsDef, &body) | 780 | AST_MEMBER(MacroLit, &argsDef, &body) |
| 775 | AST_END(MacroLit, "macro_lit"sv) | 781 | AST_END(MacroLit) |
| 776 | 782 | ||
| 777 | AST_NODE(MacroFunc) | 783 | AST_NODE(MacroFunc) |
| 778 | ast_ptr<true, MacroName_t> name; | 784 | ast_ptr<true, MacroName_t> name; |
| 779 | ast_sel<true, Invoke_t, InvokeArgs_t> invoke; | 785 | ast_sel<true, Invoke_t, InvokeArgs_t> invoke; |
| 780 | AST_MEMBER(MacroFunc, &name, &invoke) | 786 | AST_MEMBER(MacroFunc, &name, &invoke) |
| 781 | AST_END(MacroFunc, "macro_func"sv) | 787 | AST_END(MacroFunc) |
| 782 | 788 | ||
| 783 | AST_NODE(MacroInPlace) | 789 | AST_NODE(MacroInPlace) |
| 784 | ast_ptr<true, Body_t> body; | 790 | ast_ptr<true, Body_t> body; |
| 785 | AST_MEMBER(MacroInPlace, &body) | 791 | AST_MEMBER(MacroInPlace, &body) |
| 786 | AST_END(MacroInPlace, "macro_in_place"sv) | 792 | AST_END(MacroInPlace) |
| 787 | 793 | ||
| 788 | AST_NODE(Macro) | 794 | AST_NODE(Macro) |
| 789 | ast_ptr<true, UnicodeName_t> name; | 795 | ast_ptr<true, UnicodeName_t> name; |
| 790 | ast_sel<true, MacroLit_t, MacroFunc_t> decl; | 796 | ast_sel<true, MacroLit_t, MacroFunc_t> decl; |
| 791 | AST_MEMBER(Macro, &name, &decl) | 797 | AST_MEMBER(Macro, &name, &decl) |
| 792 | AST_END(Macro, "macro"sv) | 798 | AST_END(Macro) |
| 793 | 799 | ||
| 794 | AST_NODE(NameOrDestructure) | 800 | AST_NODE(NameOrDestructure) |
| 795 | ast_sel<true, Variable_t, TableLit_t, Comprehension_t> item; | 801 | ast_sel<true, Variable_t, TableLit_t, Comprehension_t> item; |
| 796 | AST_MEMBER(NameOrDestructure, &item) | 802 | AST_MEMBER(NameOrDestructure, &item) |
| 797 | AST_END(NameOrDestructure, "name_or_des"sv) | 803 | AST_END(NameOrDestructure) |
| 798 | 804 | ||
| 799 | AST_NODE(AssignableNameList) | 805 | AST_NODE(AssignableNameList) |
| 800 | ast_ptr<true, Seperator_t> sep; | 806 | ast_ptr<true, Seperator_t> sep; |
| 801 | ast_list<true, NameOrDestructure_t> items; | 807 | ast_list<true, NameOrDestructure_t> items; |
| 802 | AST_MEMBER(AssignableNameList, &sep, &items) | 808 | AST_MEMBER(AssignableNameList, &sep, &items) |
| 803 | AST_END(AssignableNameList, "assignable_name_list"sv) | 809 | AST_END(AssignableNameList) |
| 804 | 810 | ||
| 805 | AST_NODE(InvokeArgs) | 811 | AST_NODE(InvokeArgs) |
| 806 | ast_ptr<true, Seperator_t> sep; | 812 | ast_ptr<true, Seperator_t> sep; |
| 807 | ast_sel_list<true, Exp_t, TableBlock_t> args; | 813 | ast_sel_list<true, Exp_t, TableBlock_t> args; |
| 808 | AST_MEMBER(InvokeArgs, &sep, &args) | 814 | AST_MEMBER(InvokeArgs, &sep, &args) |
| 809 | AST_END(InvokeArgs, "invoke_args"sv) | 815 | AST_END(InvokeArgs) |
| 810 | 816 | ||
| 811 | AST_LEAF(ConstValue) | 817 | AST_LEAF(ConstValue) |
| 812 | AST_END(ConstValue, "const_value"sv) | 818 | AST_END(ConstValue) |
| 813 | 819 | ||
| 814 | AST_NODE(UnaryValue) | 820 | AST_NODE(UnaryValue) |
| 815 | ast_list<true, UnaryOperator_t> ops; | 821 | ast_list<true, UnaryOperator_t> ops; |
| 816 | ast_ptr<true, Value_t> value; | 822 | ast_ptr<true, Value_t> value; |
| 817 | AST_MEMBER(UnaryValue, &ops, &value) | 823 | AST_MEMBER(UnaryValue, &ops, &value) |
| 818 | AST_END(UnaryValue, "unary_value"sv) | 824 | AST_END(UnaryValue) |
| 819 | 825 | ||
| 820 | AST_NODE(UnaryExp) | 826 | AST_NODE(UnaryExp) |
| 821 | ast_list<false, UnaryOperator_t> ops; | 827 | ast_list<false, UnaryOperator_t> ops; |
| 822 | ast_list<true, Value_t> expos; | 828 | ast_list<true, Value_t> expos; |
| 823 | ast_ptr<false, In_t> inExp; | 829 | ast_ptr<false, In_t> inExp; |
| 824 | AST_MEMBER(UnaryExp, &ops, &expos, &inExp) | 830 | AST_MEMBER(UnaryExp, &ops, &expos, &inExp) |
| 825 | AST_END(UnaryExp, "unary_exp"sv) | 831 | AST_END(UnaryExp) |
| 826 | 832 | ||
| 827 | AST_NODE(ExpListAssign) | 833 | AST_NODE(ExpListAssign) |
| 828 | ast_ptr<true, ExpList_t> expList; | 834 | ast_ptr<true, ExpList_t> expList; |
| 829 | ast_sel<false, Update_t, Assign_t> action; | 835 | ast_sel<false, Update_t, Assign_t> action; |
| 830 | AST_MEMBER(ExpListAssign, &expList, &action) | 836 | AST_MEMBER(ExpListAssign, &expList, &action) |
| 831 | AST_END(ExpListAssign, "exp_list_assign"sv) | 837 | AST_END(ExpListAssign) |
| 832 | 838 | ||
| 833 | AST_NODE(IfLine) | 839 | AST_NODE(IfLine) |
| 834 | ast_ptr<true, IfType_t> type; | 840 | ast_ptr<true, IfType_t> type; |
| 835 | ast_ptr<true, IfCond_t> condition; | 841 | ast_ptr<true, IfCond_t> condition; |
| 836 | AST_MEMBER(IfLine, &type, &condition) | 842 | AST_MEMBER(IfLine, &type, &condition) |
| 837 | AST_END(IfLine, "if_line"sv) | 843 | AST_END(IfLine) |
| 838 | 844 | ||
| 839 | AST_NODE(WhileLine) | 845 | AST_NODE(WhileLine) |
| 840 | ast_ptr<true, WhileType_t> type; | 846 | ast_ptr<true, WhileType_t> type; |
| 841 | ast_ptr<true, Exp_t> condition; | 847 | ast_ptr<true, Exp_t> condition; |
| 842 | AST_MEMBER(WhileLine, &type, &condition) | 848 | AST_MEMBER(WhileLine, &type, &condition) |
| 843 | AST_END(WhileLine, "while_line"sv) | 849 | AST_END(WhileLine) |
| 844 | 850 | ||
| 845 | AST_LEAF(BreakLoop) | 851 | AST_LEAF(BreakLoop) |
| 846 | AST_END(BreakLoop, "break_loop"sv) | 852 | AST_END(BreakLoop) |
| 847 | 853 | ||
| 848 | AST_NODE(PipeBody) | 854 | AST_NODE(PipeBody) |
| 849 | ast_ptr<true, Seperator_t> sep; | 855 | ast_ptr<true, Seperator_t> sep; |
| 850 | ast_list<true, UnaryExp_t> values; | 856 | ast_list<true, UnaryExp_t> values; |
| 851 | AST_MEMBER(PipeBody, &sep, &values) | 857 | AST_MEMBER(PipeBody, &sep, &values) |
| 852 | AST_END(PipeBody, "pipe_body"sv) | 858 | AST_END(PipeBody) |
| 853 | 859 | ||
| 854 | AST_NODE(StatementAppendix) | 860 | AST_NODE(StatementAppendix) |
| 855 | ast_sel<true, IfLine_t, WhileLine_t, CompInner_t> item; | 861 | ast_sel<true, IfLine_t, WhileLine_t, CompInner_t> item; |
| 856 | AST_MEMBER(StatementAppendix, &item) | 862 | AST_MEMBER(StatementAppendix, &item) |
| 857 | AST_END(StatementAppendix, "statement_appendix"sv) | 863 | AST_END(StatementAppendix) |
| 858 | 864 | ||
| 859 | AST_LEAF(StatementSep) | 865 | AST_LEAF(StatementSep) |
| 860 | AST_END(StatementSep, "statement_sep"sv) | 866 | AST_END(StatementSep) |
| 861 | 867 | ||
| 862 | AST_LEAF(YueLineComment) | 868 | AST_LEAF(YueLineComment) |
| 863 | AST_END(YueLineComment, "comment"sv) | 869 | AST_END(YueLineComment) |
| 864 | 870 | ||
| 865 | AST_LEAF(MultilineCommentInner) | 871 | AST_LEAF(MultilineCommentInner) |
| 866 | AST_END(MultilineCommentInner, "comment"sv) | 872 | AST_END(MultilineCommentInner) |
| 867 | 873 | ||
| 868 | AST_NODE(YueMultilineComment) | 874 | AST_NODE(YueMultilineComment) |
| 869 | ast_ptr<true, MultilineCommentInner_t> inner; | 875 | ast_ptr<true, MultilineCommentInner_t> inner; |
| 870 | AST_MEMBER(YueMultilineComment, &inner) | 876 | AST_MEMBER(YueMultilineComment, &inner) |
| 871 | AST_END(YueMultilineComment, "comment"sv) | 877 | AST_END(YueMultilineComment) |
| 872 | 878 | ||
| 873 | AST_NODE(ChainAssign) | 879 | AST_NODE(ChainAssign) |
| 874 | ast_ptr<true, Seperator_t> sep; | 880 | ast_ptr<true, Seperator_t> sep; |
| 875 | ast_list<true, Exp_t> exprs; | 881 | ast_list<true, Exp_t> exprs; |
| 876 | ast_ptr<true, Assign_t> assign; | 882 | ast_ptr<true, Assign_t> assign; |
| 877 | AST_MEMBER(ChainAssign, &sep, &exprs, &assign) | 883 | AST_MEMBER(ChainAssign, &sep, &exprs, &assign) |
| 878 | AST_END(ChainAssign, "chain_assign") | 884 | AST_END(ChainAssign) |
| 879 | 885 | ||
| 880 | AST_NODE(Statement) | 886 | AST_NODE(Statement) |
| 881 | ast_ptr<true, Seperator_t> sep; | 887 | ast_ptr<true, Seperator_t> sep; |
| @@ -888,28 +894,28 @@ AST_NODE(Statement) | |||
| 888 | > content; | 894 | > content; |
| 889 | ast_ptr<false, StatementAppendix_t> appendix; | 895 | ast_ptr<false, StatementAppendix_t> appendix; |
| 890 | AST_MEMBER(Statement, &sep, &comments, &content, &appendix) | 896 | AST_MEMBER(Statement, &sep, &comments, &content, &appendix) |
| 891 | AST_END(Statement, "statement"sv) | 897 | AST_END(Statement) |
| 892 | 898 | ||
| 893 | AST_NODE(Body) | 899 | AST_NODE(Body) |
| 894 | ast_sel<true, Block_t, Statement_t> content; | 900 | ast_sel<true, Block_t, Statement_t> content; |
| 895 | AST_MEMBER(Body, &content) | 901 | AST_MEMBER(Body, &content) |
| 896 | AST_END(Body, "body"sv) | 902 | AST_END(Body) |
| 897 | 903 | ||
| 898 | AST_NODE(Block) | 904 | AST_NODE(Block) |
| 899 | ast_ptr<true, Seperator_t> sep; | 905 | ast_ptr<true, Seperator_t> sep; |
| 900 | ast_list<false, Statement_t> statements; | 906 | ast_list<false, Statement_t> statements; |
| 901 | AST_MEMBER(Block, &sep, &statements) | 907 | AST_MEMBER(Block, &sep, &statements) |
| 902 | AST_END(Block, "block"sv) | 908 | AST_END(Block) |
| 903 | 909 | ||
| 904 | AST_NODE(BlockEnd) | 910 | AST_NODE(BlockEnd) |
| 905 | ast_ptr<true, Block_t> block; | 911 | ast_ptr<true, Block_t> block; |
| 906 | AST_MEMBER(BlockEnd, &block) | 912 | AST_MEMBER(BlockEnd, &block) |
| 907 | AST_END(BlockEnd, "block_end"sv) | 913 | AST_END(BlockEnd) |
| 908 | 914 | ||
| 909 | AST_NODE(File) | 915 | AST_NODE(File) |
| 910 | ast_ptr<false, Block_t> block; | 916 | ast_ptr<false, Block_t> block; |
| 911 | AST_MEMBER(File, &block) | 917 | AST_MEMBER(File, &block) |
| 912 | AST_END(File, "file"sv) | 918 | AST_END(File) |
| 913 | 919 | ||
| 914 | // clang-format on | 920 | // clang-format on |
| 915 | 921 | ||
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index 994ab57..a661356 100644 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp | |||
| @@ -29,7 +29,7 @@ extern "C" { | |||
| 29 | } // extern "C" | 29 | } // extern "C" |
| 30 | 30 | ||
| 31 | // name of table stored in lua registry | 31 | // name of table stored in lua registry |
| 32 | #define YUE_MODULE "__yue_modules__" | 32 | #define YUE_MODULES "__yue_modules__" |
| 33 | 33 | ||
| 34 | #if LUA_VERSION_NUM > 501 | 34 | #if LUA_VERSION_NUM > 501 |
| 35 | #ifndef LUA_COMPAT_5_1 | 35 | #ifndef LUA_COMPAT_5_1 |
| @@ -75,7 +75,7 @@ static std::unordered_set<std::string> Metamethods = { | |||
| 75 | "close"s // Lua 5.4 | 75 | "close"s // Lua 5.4 |
| 76 | }; | 76 | }; |
| 77 | 77 | ||
| 78 | const std::string_view version = "0.23.9"sv; | 78 | const std::string_view version = "0.24.0"sv; |
| 79 | const std::string_view extension = "yue"sv; | 79 | const std::string_view extension = "yue"sv; |
| 80 | 80 | ||
| 81 | class CompileError : public std::logic_error { | 81 | class CompileError : public std::logic_error { |
| @@ -136,8 +136,8 @@ public: | |||
| 136 | _sameModule = true; | 136 | _sameModule = true; |
| 137 | int top = lua_gettop(L); | 137 | int top = lua_gettop(L); |
| 138 | DEFER(lua_settop(L, top)); | 138 | DEFER(lua_settop(L, top)); |
| 139 | lua_pushliteral(L, YUE_MODULE); // YUE_MODULE | 139 | lua_pushliteral(L, YUE_MODULES); // YUE_MODULES |
| 140 | lua_rawget(L, LUA_REGISTRYINDEX); // reg[YUE_MODULE], tb | 140 | lua_rawget(L, LUA_REGISTRYINDEX); // reg[YUE_MODULES], tb |
| 141 | BREAK_IF(lua_istable(L, -1) == 0); | 141 | BREAK_IF(lua_istable(L, -1) == 0); |
| 142 | int idx = static_cast<int>(lua_objlen(L, -1)); // idx = #tb, tb | 142 | int idx = static_cast<int>(lua_objlen(L, -1)); // idx = #tb, tb |
| 143 | BREAK_IF(idx == 0); | 143 | BREAK_IF(idx == 0); |
| @@ -351,8 +351,8 @@ public: | |||
| 351 | if (!_sameModule) { | 351 | if (!_sameModule) { |
| 352 | int top = lua_gettop(L); | 352 | int top = lua_gettop(L); |
| 353 | DEFER(lua_settop(L, top)); | 353 | DEFER(lua_settop(L, top)); |
| 354 | lua_pushliteral(L, YUE_MODULE); // YUE_MODULE | 354 | lua_pushliteral(L, YUE_MODULES); // YUE_MODULES |
| 355 | lua_rawget(L, LUA_REGISTRYINDEX); // reg[YUE_MODULE], tb | 355 | lua_rawget(L, LUA_REGISTRYINDEX); // reg[YUE_MODULES], tb |
| 356 | int idx = static_cast<int>(lua_objlen(L, -1)); | 356 | int idx = static_cast<int>(lua_objlen(L, -1)); |
| 357 | lua_pushnil(L); // tb nil | 357 | lua_pushnil(L); // tb nil |
| 358 | lua_rawseti(L, -2, idx); // tb[idx] = nil, tb | 358 | lua_rawseti(L, -2, idx); // tb[idx] = nil, tb |
| @@ -370,7 +370,7 @@ private: | |||
| 370 | std::function<void(void*)> _luaOpen; | 370 | std::function<void(void*)> _luaOpen; |
| 371 | #endif // YUE_NO_MACRO | 371 | #endif // YUE_NO_MACRO |
| 372 | YueConfig _config; | 372 | YueConfig _config; |
| 373 | YueParser _parser; | 373 | YueParser& _parser = YueParser::shared(); |
| 374 | ParseInfo _info; | 374 | ParseInfo _info; |
| 375 | int _indentOffset = 0; | 375 | int _indentOffset = 0; |
| 376 | struct VarArgState { | 376 | struct VarArgState { |
| @@ -4960,8 +4960,8 @@ private: | |||
| 4960 | 4960 | ||
| 4961 | void pushCurrentModule() { | 4961 | void pushCurrentModule() { |
| 4962 | if (_useModule) { | 4962 | if (_useModule) { |
| 4963 | lua_pushliteral(L, YUE_MODULE); // YUE_MODULE | 4963 | lua_pushliteral(L, YUE_MODULES); // YUE_MODULES |
| 4964 | lua_rawget(L, LUA_REGISTRYINDEX); // reg[YUE_MODULE], tb | 4964 | lua_rawget(L, LUA_REGISTRYINDEX); // reg[YUE_MODULES], tb |
| 4965 | int idx = static_cast<int>(lua_objlen(L, -1)); // idx = #tb, tb | 4965 | int idx = static_cast<int>(lua_objlen(L, -1)); // idx = #tb, tb |
| 4966 | lua_rawgeti(L, -1, idx); // tb[idx], tb cur | 4966 | lua_rawgeti(L, -1, idx); // tb[idx], tb cur |
| 4967 | lua_remove(L, -2); // cur | 4967 | lua_remove(L, -2); // cur |
| @@ -4987,14 +4987,14 @@ private: | |||
| 4987 | } | 4987 | } |
| 4988 | _stateOwner = true; | 4988 | _stateOwner = true; |
| 4989 | } | 4989 | } |
| 4990 | lua_pushliteral(L, YUE_MODULE); // YUE_MODULE | 4990 | lua_pushliteral(L, YUE_MODULES); // YUE_MODULES |
| 4991 | lua_rawget(L, LUA_REGISTRYINDEX); // reg[YUE_MODULE], tb | 4991 | lua_rawget(L, LUA_REGISTRYINDEX); // reg[YUE_MODULES], tb |
| 4992 | if (lua_isnil(L, -1) != 0) { // tb == nil | 4992 | if (lua_isnil(L, -1) != 0) { // tb == nil |
| 4993 | lua_pop(L, 1); | 4993 | lua_pop(L, 1); |
| 4994 | lua_newtable(L); // tb | 4994 | lua_newtable(L); // tb |
| 4995 | lua_pushliteral(L, YUE_MODULE); // tb YUE_MODULE | 4995 | lua_pushliteral(L, YUE_MODULES); // tb YUE_MODULES |
| 4996 | lua_pushvalue(L, -2); // tb YUE_MODULE tb | 4996 | lua_pushvalue(L, -2); // tb YUE_MODULE tb |
| 4997 | lua_rawset(L, LUA_REGISTRYINDEX); // reg[YUE_MODULE] = tb, tb | 4997 | lua_rawset(L, LUA_REGISTRYINDEX); // reg[YUE_MODULES] = tb, tb |
| 4998 | } // tb | 4998 | } // tb |
| 4999 | int idx = static_cast<int>(lua_objlen(L, -1)); // idx = #tb, tb | 4999 | int idx = static_cast<int>(lua_objlen(L, -1)); // idx = #tb, tb |
| 5000 | lua_newtable(L); // tb cur | 5000 | lua_newtable(L); // tb cur |
| @@ -5016,7 +5016,7 @@ private: | |||
| 5016 | bool isModuleLoaded(std::string_view name) { | 5016 | bool isModuleLoaded(std::string_view name) { |
| 5017 | int top = lua_gettop(L); | 5017 | int top = lua_gettop(L); |
| 5018 | DEFER(lua_settop(L, top)); | 5018 | DEFER(lua_settop(L, top)); |
| 5019 | lua_pushliteral(L, YUE_MODULE); // YUE_MODULE | 5019 | lua_pushliteral(L, YUE_MODULES); // YUE_MODULES |
| 5020 | lua_rawget(L, LUA_REGISTRYINDEX); // modules | 5020 | lua_rawget(L, LUA_REGISTRYINDEX); // modules |
| 5021 | lua_pushlstring(L, &name.front(), name.size()); | 5021 | lua_pushlstring(L, &name.front(), name.size()); |
| 5022 | lua_rawget(L, -2); // modules module | 5022 | lua_rawget(L, -2); // modules module |
| @@ -5027,7 +5027,7 @@ private: | |||
| 5027 | } | 5027 | } |
| 5028 | 5028 | ||
| 5029 | void pushModuleTable(std::string_view name) { | 5029 | void pushModuleTable(std::string_view name) { |
| 5030 | lua_pushliteral(L, YUE_MODULE); // YUE_MODULE | 5030 | lua_pushliteral(L, YUE_MODULES); // YUE_MODULES |
| 5031 | lua_rawget(L, LUA_REGISTRYINDEX); // modules | 5031 | lua_rawget(L, LUA_REGISTRYINDEX); // modules |
| 5032 | lua_pushlstring(L, &name.front(), name.size()); | 5032 | lua_pushlstring(L, &name.front(), name.size()); |
| 5033 | lua_rawget(L, -2); // modules module | 5033 | lua_rawget(L, -2); // modules module |
| @@ -9869,9 +9869,17 @@ private: | |||
| 9869 | if (importAllMacro) { | 9869 | if (importAllMacro) { |
| 9870 | lua_pushnil(L); // cur mod startKey | 9870 | lua_pushnil(L); // cur mod startKey |
| 9871 | while (lua_next(L, -2) != 0) { // cur mod key value | 9871 | while (lua_next(L, -2) != 0) { // cur mod key value |
| 9872 | lua_pushvalue(L, -2); // cur mod key value key | 9872 | const char* key = lua_tostring(L, -2); |
| 9873 | lua_insert(L, -2); // cur mod key key value | 9873 | auto it = std::find_if(macroPairs.begin(), macroPairs.end(), [&](const auto& item) { |
| 9874 | lua_rawset(L, -5); // cur[key] = value, cur mod key | 9874 | return key == item.first; |
| 9875 | }); | ||
| 9876 | if (it == macroPairs.end()) { | ||
| 9877 | lua_pushvalue(L, -2); // cur mod key value key | ||
| 9878 | lua_insert(L, -2); // cur mod key key value | ||
| 9879 | lua_rawset(L, -5); // cur[key] = value, cur mod key | ||
| 9880 | } else { | ||
| 9881 | lua_pop(L, 1); // cur mod key | ||
| 9882 | } | ||
| 9875 | } | 9883 | } |
| 9876 | } | 9884 | } |
| 9877 | for (const auto& pair : macroPairs) { | 9885 | for (const auto& pair : macroPairs) { |
| @@ -10696,9 +10704,9 @@ CompileInfo YueCompiler::compile(std::string_view codes, const YueConfig& config | |||
| 10696 | void YueCompiler::clear(void* luaState) { | 10704 | void YueCompiler::clear(void* luaState) { |
| 10697 | #ifndef YUE_NO_MACRO | 10705 | #ifndef YUE_NO_MACRO |
| 10698 | auto L = static_cast<lua_State*>(luaState); | 10706 | auto L = static_cast<lua_State*>(luaState); |
| 10699 | lua_pushliteral(L, YUE_MODULE); // YUE_MODULE | 10707 | lua_pushliteral(L, YUE_MODULES); // YUE_MODULES |
| 10700 | lua_pushnil(L); | 10708 | lua_pushnil(L); |
| 10701 | lua_rawset(L, LUA_REGISTRYINDEX); // reg[YUE_MODULE] = nil | 10709 | lua_rawset(L, LUA_REGISTRYINDEX); // reg[YUE_MODULES] = nil |
| 10702 | #else | 10710 | #else |
| 10703 | (void)(luaState); | 10711 | (void)(luaState); |
| 10704 | #endif // YUE_NO_MACRO | 10712 | #endif // YUE_NO_MACRO |
diff --git a/src/yuescript/yue_parser.cpp b/src/yuescript/yue_parser.cpp index 986f67a..83aba40 100644 --- a/src/yuescript/yue_parser.cpp +++ b/src/yuescript/yue_parser.cpp | |||
| @@ -309,7 +309,7 @@ YueParser::YueParser() { | |||
| 309 | ); | 309 | ); |
| 310 | 310 | ||
| 311 | MacroNamePair = MacroName >> ':' >> space >> MacroName; | 311 | MacroNamePair = MacroName >> ':' >> space >> MacroName; |
| 312 | ImportAllMacro = '$'; | 312 | ImportAllMacro = '$' >> not_(UnicodeName); |
| 313 | import_tab_item = | 313 | import_tab_item = |
| 314 | VariablePair | | 314 | VariablePair | |
| 315 | NormalPair | | 315 | NormalPair | |
| @@ -324,6 +324,7 @@ YueParser::YueParser() { | |||
| 324 | push_indent_match >> (space >> import_tab_list >> pop_indent | pop_indent) | 324 | push_indent_match >> (space >> import_tab_list >> pop_indent | pop_indent) |
| 325 | ) | space; | 325 | ) | space; |
| 326 | import_tab_lines = space_break >> import_tab_line >> *(-(space >> ',') >> space_break >> import_tab_line) >> -(space >> ','); | 326 | import_tab_lines = space_break >> import_tab_line >> *(-(space >> ',') >> space_break >> import_tab_line) >> -(space >> ','); |
| 327 | import_tab_key_value = key_value | ':' >> MacroName | MacroNamePair | ImportAllMacro; | ||
| 327 | ImportTabLit = ( | 328 | ImportTabLit = ( |
| 328 | '{' >> Seperator >> | 329 | '{' >> Seperator >> |
| 329 | -(space >> import_tab_list) >> | 330 | -(space >> import_tab_list) >> |
| @@ -332,7 +333,7 @@ YueParser::YueParser() { | |||
| 332 | white >> | 333 | white >> |
| 333 | '}' | 334 | '}' |
| 334 | ) | ( | 335 | ) | ( |
| 335 | Seperator >> key_value >> *(space >> ',' >> space >> key_value) | 336 | Seperator >> import_tab_key_value >> *(space >> ',' >> space >> import_tab_key_value) |
| 336 | ); | 337 | ); |
| 337 | 338 | ||
| 338 | ImportAs = ImportLiteral >> -(space >> key("as") >> space >> (ImportTabLit | Variable | ImportAllMacro)); | 339 | ImportAs = ImportLiteral >> -(space >> key("as") >> space >> (ImportTabLit | Variable | ImportAllMacro)); |
| @@ -1083,6 +1084,23 @@ ParseInfo YueParser::parse(std::string_view codes, rule& r) { | |||
| 1083 | return res; | 1084 | return res; |
| 1084 | } | 1085 | } |
| 1085 | 1086 | ||
| 1087 | ParseInfo YueParser::parse(std::string_view astName, std::string_view codes) { | ||
| 1088 | auto it = _rules.find(astName); | ||
| 1089 | if (it != _rules.end()) { | ||
| 1090 | return parse(codes, *it->second); | ||
| 1091 | } | ||
| 1092 | return {}; | ||
| 1093 | } | ||
| 1094 | |||
| 1095 | bool YueParser::match(std::string_view astName, std::string_view codes) { | ||
| 1096 | auto it = _rules.find(astName); | ||
| 1097 | if (it != _rules.end()) { | ||
| 1098 | auto rEnd = rule(*it->second >> eof()); | ||
| 1099 | return parse(codes, rEnd).node; | ||
| 1100 | } | ||
| 1101 | return false; | ||
| 1102 | } | ||
| 1103 | |||
| 1086 | std::string YueParser::toString(ast_node* node) { | 1104 | std::string YueParser::toString(ast_node* node) { |
| 1087 | return _converter.to_bytes(std::wstring(node->m_begin.m_it, node->m_end.m_it)); | 1105 | return _converter.to_bytes(std::wstring(node->m_begin.m_it, node->m_end.m_it)); |
| 1088 | } | 1106 | } |
| @@ -1091,6 +1109,11 @@ std::string YueParser::toString(input::iterator begin, input::iterator end) { | |||
| 1091 | return _converter.to_bytes(std::wstring(begin, end)); | 1109 | return _converter.to_bytes(std::wstring(begin, end)); |
| 1092 | } | 1110 | } |
| 1093 | 1111 | ||
| 1112 | YueParser& YueParser::shared() { | ||
| 1113 | thread_local static YueParser parser; | ||
| 1114 | return parser; | ||
| 1115 | } | ||
| 1116 | |||
| 1094 | namespace Utils { | 1117 | namespace Utils { |
| 1095 | void replace(std::string& str, std::string_view from, std::string_view to) { | 1118 | void replace(std::string& str, std::string_view from, std::string_view to) { |
| 1096 | size_t start_pos = 0; | 1119 | size_t start_pos = 0; |
diff --git a/src/yuescript/yue_parser.h b/src/yuescript/yue_parser.h index 6623653..3c50602 100644 --- a/src/yuescript/yue_parser.h +++ b/src/yuescript/yue_parser.h | |||
| @@ -16,6 +16,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI | |||
| 16 | #include <stack> | 16 | #include <stack> |
| 17 | #include <string> | 17 | #include <string> |
| 18 | #include <string_view> | 18 | #include <string_view> |
| 19 | #include <unordered_map> | ||
| 19 | #include <unordered_set> | 20 | #include <unordered_set> |
| 20 | 21 | ||
| 21 | #include "yuescript/ast.hpp" | 22 | #include "yuescript/ast.hpp" |
| @@ -55,7 +56,7 @@ struct identity { | |||
| 55 | 56 | ||
| 56 | #define AST_RULE(type) \ | 57 | #define AST_RULE(type) \ |
| 57 | rule type; \ | 58 | rule type; \ |
| 58 | ast<type##_t> type##_impl = type; \ | 59 | ast<type##_t> type##_impl{collect(ast_name<type##_t>(), type)}; \ |
| 59 | inline rule& getRule(identity<type##_t>) { return type; } | 60 | inline rule& getRule(identity<type##_t>) { return type; } |
| 60 | #else // NDEBUG | 61 | #else // NDEBUG |
| 61 | #define NONE_AST_RULE(type) \ | 62 | #define NONE_AST_RULE(type) \ |
| @@ -63,7 +64,7 @@ struct identity { | |||
| 63 | 64 | ||
| 64 | #define AST_RULE(type) \ | 65 | #define AST_RULE(type) \ |
| 65 | rule type{#type, rule::initTag{}}; \ | 66 | rule type{#type, rule::initTag{}}; \ |
| 66 | ast<type##_t> type##_impl = type; \ | 67 | ast<type##_t> type##_impl{collect(ast_name<type##_t>(), type)}; \ |
| 67 | inline rule& getRule(identity<type##_t>) { return type; } | 68 | inline rule& getRule(identity<type##_t>) { return type; } |
| 68 | #endif // NDEBUG | 69 | #endif // NDEBUG |
| 69 | 70 | ||
| @@ -72,19 +73,21 @@ extern std::unordered_set<std::string> Keywords; | |||
| 72 | 73 | ||
| 73 | class YueParser { | 74 | class YueParser { |
| 74 | public: | 75 | public: |
| 75 | YueParser(); | ||
| 76 | |||
| 77 | template <class AST> | 76 | template <class AST> |
| 78 | ParseInfo parse(std::string_view codes) { | 77 | ParseInfo parse(std::string_view codes) { |
| 79 | return parse(codes, getRule<AST>()); | 78 | return parse(codes, getRule<AST>()); |
| 80 | } | 79 | } |
| 81 | 80 | ||
| 81 | ParseInfo parse(std::string_view astName, std::string_view codes); | ||
| 82 | |||
| 82 | template <class AST> | 83 | template <class AST> |
| 83 | bool match(std::string_view codes) { | 84 | bool match(std::string_view codes) { |
| 84 | auto rEnd = rule(getRule<AST>() >> eof()); | 85 | auto rEnd = rule(getRule<AST>() >> eof()); |
| 85 | return parse(codes, rEnd).node; | 86 | return parse(codes, rEnd).node; |
| 86 | } | 87 | } |
| 87 | 88 | ||
| 89 | bool match(std::string_view astName, std::string_view codes); | ||
| 90 | |||
| 88 | template <class AST> | 91 | template <class AST> |
| 89 | bool startWith(std::string_view codes) { | 92 | bool startWith(std::string_view codes) { |
| 90 | return startWith(codes, getRule<AST>()); | 93 | return startWith(codes, getRule<AST>()); |
| @@ -93,7 +96,10 @@ public: | |||
| 93 | std::string toString(ast_node* node); | 96 | std::string toString(ast_node* node); |
| 94 | std::string toString(input::iterator begin, input::iterator end); | 97 | std::string toString(input::iterator begin, input::iterator end); |
| 95 | 98 | ||
| 99 | static YueParser& shared(); | ||
| 100 | |||
| 96 | protected: | 101 | protected: |
| 102 | YueParser(); | ||
| 97 | ParseInfo parse(std::string_view codes, rule& r); | 103 | ParseInfo parse(std::string_view codes, rule& r); |
| 98 | bool startWith(std::string_view codes, rule& r); | 104 | bool startWith(std::string_view codes, rule& r); |
| 99 | 105 | ||
| @@ -125,6 +131,7 @@ protected: | |||
| 125 | 131 | ||
| 126 | private: | 132 | private: |
| 127 | Converter _converter; | 133 | Converter _converter; |
| 134 | std::unordered_map<std::string_view, rule*> _rules; | ||
| 128 | 135 | ||
| 129 | template <class T> | 136 | template <class T> |
| 130 | inline rule& getRule(identity<T>) { | 137 | inline rule& getRule(identity<T>) { |
| @@ -132,6 +139,11 @@ private: | |||
| 132 | return cut; | 139 | return cut; |
| 133 | } | 140 | } |
| 134 | 141 | ||
| 142 | inline rule& collect(std::string_view name, rule& rule) { | ||
| 143 | _rules[name] = rule.this_ptr(); | ||
| 144 | return rule; | ||
| 145 | } | ||
| 146 | |||
| 135 | NONE_AST_RULE(empty_block_error); | 147 | NONE_AST_RULE(empty_block_error); |
| 136 | NONE_AST_RULE(leading_spaces_error); | 148 | NONE_AST_RULE(leading_spaces_error); |
| 137 | NONE_AST_RULE(indentation_error); | 149 | NONE_AST_RULE(indentation_error); |
| @@ -188,6 +200,7 @@ private: | |||
| 188 | NONE_AST_RULE(import_tab_list); | 200 | NONE_AST_RULE(import_tab_list); |
| 189 | NONE_AST_RULE(import_tab_line); | 201 | NONE_AST_RULE(import_tab_line); |
| 190 | NONE_AST_RULE(import_tab_lines); | 202 | NONE_AST_RULE(import_tab_lines); |
| 203 | NONE_AST_RULE(import_tab_key_value); | ||
| 191 | NONE_AST_RULE(with_exp); | 204 | NONE_AST_RULE(with_exp); |
| 192 | NONE_AST_RULE(disable_do); | 205 | NONE_AST_RULE(disable_do); |
| 193 | NONE_AST_RULE(enable_do); | 206 | NONE_AST_RULE(enable_do); |
diff --git a/src/yuescript/yuescript.cpp b/src/yuescript/yuescript.cpp index 2de5571..84a9554 100644 --- a/src/yuescript/yuescript.cpp +++ b/src/yuescript/yuescript.cpp | |||
| @@ -180,7 +180,7 @@ static int yueformat(lua_State* L) { | |||
| 180 | tabSize = static_cast<int>(luaL_checkinteger(L, 2)); | 180 | tabSize = static_cast<int>(luaL_checkinteger(L, 2)); |
| 181 | } | 181 | } |
| 182 | std::string_view codes(input, len); | 182 | std::string_view codes(input, len); |
| 183 | auto info = yue::YueParser{}.parse<yue::File_t>(codes); | 183 | auto info = yue::YueParser::shared().parse<yue::File_t>(codes); |
| 184 | if (info.error) { | 184 | if (info.error) { |
| 185 | const auto& error = info.error.value(); | 185 | const auto& error = info.error.value(); |
| 186 | if (!info.codes) { | 186 | if (!info.codes) { |
| @@ -271,12 +271,19 @@ static int yuetoast(lua_State* L) { | |||
| 271 | size_t size = 0; | 271 | size_t size = 0; |
| 272 | const char* input = luaL_checklstring(L, 1, &size); | 272 | const char* input = luaL_checklstring(L, 1, &size); |
| 273 | int flattenLevel = 0; | 273 | int flattenLevel = 0; |
| 274 | if (lua_isnoneornil(L, 2) == 0) { | 274 | if (!lua_isnoneornil(L, 2)) { |
| 275 | flattenLevel = static_cast<int>(luaL_checkinteger(L, 2)); | 275 | flattenLevel = static_cast<int>(luaL_checkinteger(L, 2)); |
| 276 | flattenLevel = std::max(std::min(2, flattenLevel), 0); | 276 | flattenLevel = std::max(std::min(2, flattenLevel), 0); |
| 277 | } | 277 | } |
| 278 | yue::YueParser parser; | 278 | std::string_view ruleName; |
| 279 | auto info = parser.parse<yue::File_t>({input, size}); | 279 | if (!lua_isnoneornil(L, 3)) { |
| 280 | size_t nameSize = 0; | ||
| 281 | if (auto name = luaL_checklstring(L, 3, &nameSize)) { | ||
| 282 | ruleName = {name, nameSize}; | ||
| 283 | } | ||
| 284 | } | ||
| 285 | auto& yueParser = yue::YueParser::shared(); | ||
| 286 | auto info = ruleName.empty() ? yueParser.parse<yue::File_t>({input, size}) : yueParser.parse(ruleName, {input, size}); | ||
| 280 | if (!info.error) { | 287 | if (!info.error) { |
| 281 | lua_createtable(L, 0, 0); | 288 | lua_createtable(L, 0, 0); |
| 282 | int tableIndex = lua_gettop(L); | 289 | int tableIndex = lua_gettop(L); |
| @@ -413,9 +420,20 @@ static int yuetoast(lua_State* L) { | |||
| 413 | } | 420 | } |
| 414 | } | 421 | } |
| 415 | 422 | ||
| 423 | static int yueisast(lua_State* L) { | ||
| 424 | size_t nameLen = 0; | ||
| 425 | auto name = luaL_tolstring(L, 1, &nameLen); | ||
| 426 | size_t codeLen = 0; | ||
| 427 | auto code = luaL_tolstring(L, 2, &codeLen); | ||
| 428 | bool result = yue::YueParser::shared().match({name, nameLen}, {code, codeLen}); | ||
| 429 | lua_pushboolean(L, result ? 1 : 0); | ||
| 430 | return 1; | ||
| 431 | } | ||
| 432 | |||
| 416 | static const luaL_Reg yuelib[] = { | 433 | static const luaL_Reg yuelib[] = { |
| 417 | {"to_lua", yuetolua}, | 434 | {"to_lua", yuetolua}, |
| 418 | {"to_ast", yuetoast}, | 435 | {"to_ast", yuetoast}, |
| 436 | {"is_ast", yueisast}, | ||
| 419 | {"check", yuecheck}, | 437 | {"check", yuecheck}, |
| 420 | {"format", yueformat}, | 438 | {"format", yueformat}, |
| 421 | {"version", nullptr}, | 439 | {"version", nullptr}, |
