From f9859f5c6739c9a0d491ba64e241d147d4114ecb Mon Sep 17 00:00:00 2001 From: Li Jin Date: Mon, 9 Aug 2021 15:43:43 +0800 Subject: fix issue #62. The update statement is now creating local variable. --- src/yuescript/yue_compiler.cpp | 13 +++++++++---- src/yuescript/yue_parser.cpp | 4 ++-- 2 files changed, 11 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index 90fc60f..f1b6253 100644 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp @@ -38,7 +38,7 @@ extern "C" { namespace yue { using namespace std::string_view_literals; -using namespace std::literals::string_literals; +using namespace std::string_literals; using namespace parserlib; #define BLOCK_START do { @@ -56,7 +56,7 @@ using namespace parserlib; typedef std::list str_list; -const std::string_view version = "0.7.15"sv; +const std::string_view version = "0.7.16"sv; const std::string_view extension = "yue"sv; class YueCompilerImpl { @@ -1722,7 +1722,8 @@ private: auto leftValue = singleValueFrom(leftExp); if (!leftValue) throw std::logic_error(_info.errorMessage("left hand expression is not assignable"sv, leftExp)); if (auto chain = leftValue->item.as()) { - if (specialChainValue(chain) == ChainType::Metatable) {throw std::logic_error(_info.errorMessage("can not apply update to a metatable"sv, leftExp)); + if (specialChainValue(chain) == ChainType::Metatable) { + throw std::logic_error(_info.errorMessage("can not apply update to a metatable"sv, leftExp)); } auto tmpChain = x->new_ptr(); for (auto item : chain->items.objects()) { @@ -1747,6 +1748,7 @@ private: chain->items.clear(); chain->items.dup(tmpChain->items); } + auto defs = getPredefine(assignment); transformValue(leftValue, temp); auto left = std::move(temp.back()); temp.pop_back(); @@ -1756,7 +1758,10 @@ private: if (!singleValueFrom(update->value)) { right = '(' + right + ')'; } - _buf << join(temp) << indent() << left << " = "sv << left << + _buf << join(temp); + if (!defs.empty()) _buf << defs; + else _buf << indent() << left; + _buf << " = "sv << left << ' ' << _parser.toString(update->op) << ' ' << right << nll(assignment); out.push_back(clearBuf()); break; diff --git a/src/yuescript/yue_parser.cpp b/src/yuescript/yue_parser.cpp index c79d58e..f530776 100644 --- a/src/yuescript/yue_parser.cpp +++ b/src/yuescript/yue_parser.cpp @@ -705,8 +705,8 @@ namespace Utils { void trim(std::string& str) { if (str.empty()) return; - str.erase(0, str.find_first_not_of(" \t\n")); - str.erase(str.find_last_not_of(" \t\n") + 1); + str.erase(0, str.find_first_not_of(" \t\r\n")); + str.erase(str.find_last_not_of(" \t\r\n") + 1); } } -- cgit v1.2.3-55-g6feb