diff options
author | Li Jin <dragon-fly@qq.com> | 2022-06-12 00:16:35 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2022-06-12 00:16:35 +0800 |
commit | 1fa4049fc55986af8615ea836a60ac8cae255ad6 (patch) | |
tree | ba2e35613b32ca3bd46f6d6ff932de2a457328ea /src/yuescript/yue_compiler.cpp | |
parent | 4350d4b094c2c7202b7ad79d15187c1402bd13eb (diff) | |
download | yuescript-1fa4049fc55986af8615ea836a60ac8cae255ad6.tar.gz yuescript-1fa4049fc55986af8615ea836a60ac8cae255ad6.tar.bz2 yuescript-1fa4049fc55986af8615ea836a60ac8cae255ad6.zip |
fix issue #105.
Diffstat (limited to '')
-rwxr-xr-x | src/yuescript/yue_compiler.cpp | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index d270455..8535b43 100755 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp | |||
@@ -56,7 +56,7 @@ using namespace parserlib; | |||
56 | 56 | ||
57 | typedef std::list<std::string> str_list; | 57 | typedef std::list<std::string> str_list; |
58 | 58 | ||
59 | const std::string_view version = "0.11.0"sv; | 59 | const std::string_view version = "0.11.1"sv; |
60 | const std::string_view extension = "yue"sv; | 60 | const std::string_view extension = "yue"sv; |
61 | 61 | ||
62 | class YueCompilerImpl { | 62 | class YueCompilerImpl { |
@@ -806,8 +806,10 @@ private: | |||
806 | case id<SelfName_t>(): | 806 | case id<SelfName_t>(): |
807 | return true; | 807 | return true; |
808 | } | 808 | } |
809 | } else if (firstItem->getId() == id<DotChainItem_t>()) { | 809 | } else switch (firstItem->getId()) { |
810 | return true; | 810 | case id<DotChainItem_t>(): |
811 | case id<Exp_t>(): | ||
812 | return true; | ||
811 | } | 813 | } |
812 | } else { | 814 | } else { |
813 | if (std::find_if(chainItems.begin(), chainItems.end(), [](ast_node* node) { | 815 | if (std::find_if(chainItems.begin(), chainItems.end(), [](ast_node* node) { |
@@ -1055,6 +1057,7 @@ private: | |||
1055 | case id<BreakLoop_t>(): transformBreakLoop(static_cast<BreakLoop_t*>(content), out); break; | 1057 | case id<BreakLoop_t>(): transformBreakLoop(static_cast<BreakLoop_t*>(content), out); break; |
1056 | case id<Label_t>(): transformLabel(static_cast<Label_t*>(content), out); break; | 1058 | case id<Label_t>(): transformLabel(static_cast<Label_t*>(content), out); break; |
1057 | case id<Goto_t>(): transformGoto(static_cast<Goto_t*>(content), out); break; | 1059 | case id<Goto_t>(): transformGoto(static_cast<Goto_t*>(content), out); break; |
1060 | case id<ShortTabAppending_t>(): transformShortTabAppending(static_cast<ShortTabAppending_t*>(content), out); break; | ||
1058 | case id<LocalAttrib_t>(): transformLocalAttrib(static_cast<LocalAttrib_t*>(content), out); break; | 1061 | case id<LocalAttrib_t>(): transformLocalAttrib(static_cast<LocalAttrib_t*>(content), out); break; |
1059 | case id<PipeBody_t>(): throw std::logic_error(_info.errorMessage("pipe chain must be following a value"sv, x)); break; | 1062 | case id<PipeBody_t>(): throw std::logic_error(_info.errorMessage("pipe chain must be following a value"sv, x)); break; |
1060 | case id<ExpListAssign_t>(): { | 1063 | case id<ExpListAssign_t>(): { |
@@ -1278,6 +1281,13 @@ private: | |||
1278 | temp.push_back(clearBuf()); | 1281 | temp.push_back(clearBuf()); |
1279 | } else if (ast_is<table_appending_op_t>(chainValue->items.back())) { | 1282 | } else if (ast_is<table_appending_op_t>(chainValue->items.back())) { |
1280 | chainValue->items.pop_back(); | 1283 | chainValue->items.pop_back(); |
1284 | if (chainValue->items.empty()) { | ||
1285 | if (_withVars.empty()) { | ||
1286 | throw std::logic_error(_info.errorMessage("short table appending must be called within a with block"sv, x)); | ||
1287 | } else { | ||
1288 | chainValue->items.push_back(toAst<Callable_t>(_withVars.top(), chainValue)); | ||
1289 | } | ||
1290 | } | ||
1281 | auto varName = singleVariableFrom(chainValue); | 1291 | auto varName = singleVariableFrom(chainValue); |
1282 | bool isScoped = false; | 1292 | bool isScoped = false; |
1283 | if (varName.empty() || !isLocal(varName)) { | 1293 | if (varName.empty() || !isLocal(varName)) { |
@@ -3797,6 +3807,7 @@ private: | |||
3797 | switch (chainList.front()->getId()) { | 3807 | switch (chainList.front()->getId()) { |
3798 | case id<DotChainItem_t>(): | 3808 | case id<DotChainItem_t>(): |
3799 | case id<ColonChainItem_t>(): | 3809 | case id<ColonChainItem_t>(): |
3810 | case id<Exp_t>(): | ||
3800 | if (_withVars.empty()) { | 3811 | if (_withVars.empty()) { |
3801 | throw std::logic_error(_info.errorMessage("short dot/colon syntax must be called within a with block"sv, chainList.front())); | 3812 | throw std::logic_error(_info.errorMessage("short dot/colon syntax must be called within a with block"sv, chainList.front())); |
3802 | } else { | 3813 | } else { |
@@ -3943,8 +3954,9 @@ private: | |||
3943 | switch (x->getId()) { | 3954 | switch (x->getId()) { |
3944 | case id<DotChainItem_t>(): | 3955 | case id<DotChainItem_t>(): |
3945 | case id<ColonChainItem_t>(): | 3956 | case id<ColonChainItem_t>(): |
3957 | case id<Exp_t>(): | ||
3946 | if (_withVars.empty()) { | 3958 | if (_withVars.empty()) { |
3947 | throw std::logic_error(_info.errorMessage("short dot/colon syntax must be called within a with block"sv, x)); | 3959 | throw std::logic_error(_info.errorMessage("short dot/colon and indexing syntax must be called within a with block"sv, x)); |
3948 | } else { | 3960 | } else { |
3949 | temp.push_back(_withVars.top()); | 3961 | temp.push_back(_withVars.top()); |
3950 | } | 3962 | } |
@@ -4440,7 +4452,7 @@ private: | |||
4440 | void transformChainValue(ChainValue_t* chainValue, str_list& out, ExpUsage usage, ExpList_t* assignList = nullptr, bool allowBlockMacroReturn = false) { | 4452 | void transformChainValue(ChainValue_t* chainValue, str_list& out, ExpUsage usage, ExpList_t* assignList = nullptr, bool allowBlockMacroReturn = false) { |
4441 | if (isMacroChain(chainValue)) { | 4453 | if (isMacroChain(chainValue)) { |
4442 | #ifndef YUE_NO_MACRO | 4454 | #ifndef YUE_NO_MACRO |
4443 | ast_ptr<false,ast_node> node; | 4455 | ast_ptr<false, ast_node> node; |
4444 | std::unique_ptr<input> codes; | 4456 | std::unique_ptr<input> codes; |
4445 | std::string luaCodes; | 4457 | std::string luaCodes; |
4446 | str_list localVars; | 4458 | str_list localVars; |
@@ -7181,6 +7193,15 @@ private: | |||
7181 | void transformGoto(Goto_t* gotoNode, str_list& out) { | 7193 | void transformGoto(Goto_t* gotoNode, str_list& out) { |
7182 | out.push_back(indent() + "goto "s + _parser.toString(gotoNode->label) + nll(gotoNode)); | 7194 | out.push_back(indent() + "goto "s + _parser.toString(gotoNode->label) + nll(gotoNode)); |
7183 | } | 7195 | } |
7196 | |||
7197 | void transformShortTabAppending(ShortTabAppending_t* tab, str_list& out) { | ||
7198 | if (_withVars.empty()) { | ||
7199 | throw std::logic_error(_info.errorMessage("short table appending syntax must be called within a with block"sv, tab)); | ||
7200 | } | ||
7201 | auto assignment = toAst<ExpListAssign_t>(_withVars.top() + "[]=nil"s, tab); | ||
7202 | assignment->action.set(tab->assign); | ||
7203 | transformAssignment(assignment, out); | ||
7204 | } | ||
7184 | }; | 7205 | }; |
7185 | 7206 | ||
7186 | const std::string YueCompilerImpl::Empty; | 7207 | const std::string YueCompilerImpl::Empty; |