aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2020-07-06 15:36:16 +0800
committerLi Jin <dragon-fly@qq.com>2020-07-06 15:36:16 +0800
commit7e057d0dd7048d1aa8fbcadb9998902462a384d6 (patch)
tree448fb6d5e044cbd8d12c10ff2b4b9c1f6fa2d169
parent7682305156719aad1397d9eb63e97ecdb8393316 (diff)
downloadyuescript-7e057d0dd7048d1aa8fbcadb9998902462a384d6.tar.gz
yuescript-7e057d0dd7048d1aa8fbcadb9998902462a384d6.tar.bz2
yuescript-7e057d0dd7048d1aa8fbcadb9998902462a384d6.zip
fix compile error for "t = { [ [[abc]] ] : 42 }", make "t = {[[abc]]:42}" valid codes.
-rw-r--r--spec/inputs/syntax.moon2
-rw-r--r--spec/inputs/tables.moon2
-rw-r--r--src/MoonP/moon_ast.h3
-rw-r--r--src/MoonP/moon_compiler.cpp10
-rw-r--r--src/MoonP/moon_parser.cpp3
5 files changed, 15 insertions, 5 deletions
diff --git a/spec/inputs/syntax.moon b/spec/inputs/syntax.moon
index b1a64d3..ccee5f2 100644
--- a/spec/inputs/syntax.moon
+++ b/spec/inputs/syntax.moon
@@ -68,11 +68,13 @@ something"else"
68 68
69_ = something[[hey]] * 2 69_ = something[[hey]] * 2
70_ = something[======[hey]======] * 2 70_ = something[======[hey]======] * 2
71_ = something[ [======[hey]======] ] * 2
71 72
72 73
73_ = something'else', 2 74_ = something'else', 2
74_ = something"else", 2 75_ = something"else", 2
75_ = something[[else]], 2 76_ = something[[else]], 2
77_ = something[ [[else]] ], 2
76 78
77something 'else', 2 79something 'else', 2
78something "else", 2 80something "else", 2
diff --git a/spec/inputs/tables.moon b/spec/inputs/tables.moon
index d7596f5..9383538 100644
--- a/spec/inputs/tables.moon
+++ b/spec/inputs/tables.moon
@@ -98,7 +98,9 @@ t = {
98xam = { 98xam = {
99 hello: 1234 99 hello: 1234
100 "hello": 12354 100 "hello": 12354
101 [[hello]]: 12354
101 ["hello"]: 12354 102 ["hello"]: 12354
103 [ [[hello]] ]: 12354
102} 104}
103 105
104 106
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
391class DoubleString_t; 391class DoubleString_t;
392class SingleString_t; 392class SingleString_t;
393class LuaString_t;
393 394
394AST_NODE(normal_pair) 395AST_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)
398AST_END(normal_pair) 399AST_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
51const std::string_view version() { 51const 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);