From 7e057d0dd7048d1aa8fbcadb9998902462a384d6 Mon Sep 17 00:00:00 2001 From: Li Jin <dragon-fly@qq.com> Date: Mon, 6 Jul 2020 15:36:16 +0800 Subject: fix compile error for "t = { [ [[abc]] ] : 42 }", make "t = {[[abc]]:42}" valid codes. --- src/MoonP/moon_ast.h | 3 ++- src/MoonP/moon_compiler.cpp | 10 +++++++--- src/MoonP/moon_parser.cpp | 3 ++- 3 files changed, 11 insertions(+), 5 deletions(-) (limited to 'src') 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) class DoubleString_t; class SingleString_t; +class LuaString_t; AST_NODE(normal_pair) - ast_sel<true, KeyName_t, Exp_t, DoubleString_t, SingleString_t> key; + ast_sel<true, KeyName_t, Exp_t, DoubleString_t, SingleString_t, LuaString_t> key; ast_sel<true, Exp_t, TableBlock_t> value; AST_MEMBER(normal_pair, &key, &value) 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) { } const std::string_view version() { - return "0.4.1"sv; + return "0.4.3"sv; } // name of table stored in lua registry @@ -134,12 +134,13 @@ public: if (_useModule) { _useModule = false; if (!_sameModule) { + int top = lua_gettop(L); + DEFER(lua_settop(L, top)); lua_pushliteral(L, MOONP_MODULE); // MOONP_MODULE lua_rawget(L, LUA_REGISTRYINDEX); // reg[MOONP_MODULE], tb int idx = static_cast<int>(lua_objlen(L, -1)); lua_pushnil(L); // tb nil lua_rawseti(L, -2, idx); // tb[idx] = nil, tb - lua_pop(L, 1); // empty } } } @@ -2982,7 +2983,7 @@ private: break; case id<Exp_t>(): transformExp(static_cast<Exp_t*>(item), temp, ExpUsage::Closure); - temp.back() = s("["sv) + temp.back() + s("]"sv); + temp.back() = s(temp.back().front() == '[' ? "[ "sv : "["sv) + temp.back() + s("]"sv); break; case id<InvokeArgs_t>(): transformInvokeArgs(static_cast<InvokeArgs_t*>(item), temp); break; default: assert(false); break; @@ -3822,6 +3823,9 @@ private: case id<SingleString_t>(): transformSingleString(static_cast<SingleString_t*>(key), temp); temp.back() = s("["sv) + temp.back() + s("]"sv); break; + case id<LuaString_t>(): transformLuaString(static_cast<LuaString_t*>(key), temp); + temp.back() = s("[ "sv) + temp.back() + s("]"sv); + break; default: assert(false); break; } 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() { KeyName | sym('[') >> Exp >> sym(']') | Space >> DoubleString | - Space >> SingleString + Space >> SingleString | + Space >> LuaString ) >> symx(':') >> (Exp | TableBlock | +(SpaceBreak) >> Exp); -- cgit v1.2.3-55-g6feb