diff options
| author | Li Jin <dragon-fly@qq.com> | 2020-07-06 15:36:16 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2020-07-06 15:36:16 +0800 |
| commit | 7e057d0dd7048d1aa8fbcadb9998902462a384d6 (patch) | |
| tree | 448fb6d5e044cbd8d12c10ff2b4b9c1f6fa2d169 /src | |
| parent | 7682305156719aad1397d9eb63e97ecdb8393316 (diff) | |
| download | yuescript-7e057d0dd7048d1aa8fbcadb9998902462a384d6.tar.gz yuescript-7e057d0dd7048d1aa8fbcadb9998902462a384d6.tar.bz2 yuescript-7e057d0dd7048d1aa8fbcadb9998902462a384d6.zip | |
fix compile error for "t = { [ [[abc]] ] : 42 }", make "t = {[[abc]]:42}" valid codes.
Diffstat (limited to '')
| -rw-r--r-- | src/MoonP/moon_ast.h | 3 | ||||
| -rw-r--r-- | src/MoonP/moon_compiler.cpp | 10 | ||||
| -rw-r--r-- | src/MoonP/moon_parser.cpp | 3 |
3 files changed, 11 insertions, 5 deletions
diff --git a/src/MoonP/moon_ast.h b/src/MoonP/moon_ast.h index 1491344..91d7614 100644 --- a/src/MoonP/moon_ast.h +++ b/src/MoonP/moon_ast.h | |||
| @@ -390,9 +390,10 @@ AST_END(variable_pair) | |||
| 390 | 390 | ||
| 391 | class DoubleString_t; | 391 | class DoubleString_t; |
| 392 | class SingleString_t; | 392 | class SingleString_t; |
| 393 | class LuaString_t; | ||
| 393 | 394 | ||
| 394 | AST_NODE(normal_pair) | 395 | AST_NODE(normal_pair) |
| 395 | ast_sel<true, KeyName_t, Exp_t, DoubleString_t, SingleString_t> key; | 396 | ast_sel<true, KeyName_t, Exp_t, DoubleString_t, SingleString_t, LuaString_t> key; |
| 396 | ast_sel<true, Exp_t, TableBlock_t> value; | 397 | ast_sel<true, Exp_t, TableBlock_t> value; |
| 397 | AST_MEMBER(normal_pair, &key, &value) | 398 | AST_MEMBER(normal_pair, &key, &value) |
| 398 | AST_END(normal_pair) | 399 | AST_END(normal_pair) |
diff --git a/src/MoonP/moon_compiler.cpp b/src/MoonP/moon_compiler.cpp index a3ed4de..1283422 100644 --- a/src/MoonP/moon_compiler.cpp +++ b/src/MoonP/moon_compiler.cpp | |||
| @@ -49,7 +49,7 @@ inline std::string s(std::string_view sv) { | |||
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | const std::string_view version() { | 51 | const std::string_view version() { |
| 52 | return "0.4.1"sv; | 52 | return "0.4.3"sv; |
| 53 | } | 53 | } |
| 54 | 54 | ||
| 55 | // name of table stored in lua registry | 55 | // name of table stored in lua registry |
| @@ -134,12 +134,13 @@ public: | |||
| 134 | if (_useModule) { | 134 | if (_useModule) { |
| 135 | _useModule = false; | 135 | _useModule = false; |
| 136 | if (!_sameModule) { | 136 | if (!_sameModule) { |
| 137 | int top = lua_gettop(L); | ||
| 138 | DEFER(lua_settop(L, top)); | ||
| 137 | lua_pushliteral(L, MOONP_MODULE); // MOONP_MODULE | 139 | lua_pushliteral(L, MOONP_MODULE); // MOONP_MODULE |
| 138 | lua_rawget(L, LUA_REGISTRYINDEX); // reg[MOONP_MODULE], tb | 140 | lua_rawget(L, LUA_REGISTRYINDEX); // reg[MOONP_MODULE], tb |
| 139 | int idx = static_cast<int>(lua_objlen(L, -1)); | 141 | int idx = static_cast<int>(lua_objlen(L, -1)); |
| 140 | lua_pushnil(L); // tb nil | 142 | lua_pushnil(L); // tb nil |
| 141 | lua_rawseti(L, -2, idx); // tb[idx] = nil, tb | 143 | lua_rawseti(L, -2, idx); // tb[idx] = nil, tb |
| 142 | lua_pop(L, 1); // empty | ||
| 143 | } | 144 | } |
| 144 | } | 145 | } |
| 145 | } | 146 | } |
| @@ -2982,7 +2983,7 @@ private: | |||
| 2982 | break; | 2983 | break; |
| 2983 | case id<Exp_t>(): | 2984 | case id<Exp_t>(): |
| 2984 | transformExp(static_cast<Exp_t*>(item), temp, ExpUsage::Closure); | 2985 | transformExp(static_cast<Exp_t*>(item), temp, ExpUsage::Closure); |
| 2985 | temp.back() = s("["sv) + temp.back() + s("]"sv); | 2986 | temp.back() = s(temp.back().front() == '[' ? "[ "sv : "["sv) + temp.back() + s("]"sv); |
| 2986 | break; | 2987 | break; |
| 2987 | case id<InvokeArgs_t>(): transformInvokeArgs(static_cast<InvokeArgs_t*>(item), temp); break; | 2988 | case id<InvokeArgs_t>(): transformInvokeArgs(static_cast<InvokeArgs_t*>(item), temp); break; |
| 2988 | default: assert(false); break; | 2989 | default: assert(false); break; |
| @@ -3822,6 +3823,9 @@ private: | |||
| 3822 | case id<SingleString_t>(): transformSingleString(static_cast<SingleString_t*>(key), temp); | 3823 | case id<SingleString_t>(): transformSingleString(static_cast<SingleString_t*>(key), temp); |
| 3823 | temp.back() = s("["sv) + temp.back() + s("]"sv); | 3824 | temp.back() = s("["sv) + temp.back() + s("]"sv); |
| 3824 | break; | 3825 | break; |
| 3826 | case id<LuaString_t>(): transformLuaString(static_cast<LuaString_t*>(key), temp); | ||
| 3827 | temp.back() = s("[ "sv) + temp.back() + s("]"sv); | ||
| 3828 | break; | ||
| 3825 | default: assert(false); break; | 3829 | default: assert(false); break; |
| 3826 | } | 3830 | } |
| 3827 | auto value = pair->value.get(); | 3831 | auto value = pair->value.get(); |
diff --git a/src/MoonP/moon_parser.cpp b/src/MoonP/moon_parser.cpp index 4dee5b1..df7d810 100644 --- a/src/MoonP/moon_parser.cpp +++ b/src/MoonP/moon_parser.cpp | |||
| @@ -475,7 +475,8 @@ MoonParser::MoonParser() { | |||
| 475 | KeyName | | 475 | KeyName | |
| 476 | sym('[') >> Exp >> sym(']') | | 476 | sym('[') >> Exp >> sym(']') | |
| 477 | Space >> DoubleString | | 477 | Space >> DoubleString | |
| 478 | Space >> SingleString | 478 | Space >> SingleString | |
| 479 | Space >> LuaString | ||
| 479 | ) >> | 480 | ) >> |
| 480 | symx(':') >> | 481 | symx(':') >> |
| 481 | (Exp | TableBlock | +(SpaceBreak) >> Exp); | 482 | (Exp | TableBlock | +(SpaceBreak) >> Exp); |
