From 8ab0038c09a79fa8401bb10b7a31d03ef5380417 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Fri, 17 Jul 2020 16:22:11 +0800 Subject: fixed a missed case for multiline string as table key. reporting use of global variable 'tostring' . --- CHANGELOG.md | 12 ++++++------ src/MoonP/moon_compiler.cpp | 17 +++++++++++++---- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3fe390d..0154124 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,11 @@ The implementation for original Moonscript language 0.5.0 can be found in the `0 -## v0.4.1 +## v0.4.4 + +### Fixed Issues + +* Fix issues when declaring table key with Lua multiline string and indexing expressions with Lua multiline string. ### Added Features @@ -39,9 +43,7 @@ The implementation for original Moonscript language 0.5.0 can be found in the `0 ### Fixed Issues * Fix issues of unary and binary operator "~". - * Fix Moonscript issue 416: ambiguous Lua output in some cases. - * Fix errors when explicitly declaring global or local variable initialized with table block. * Fix macro type mismatch issue. * Fix line break issue in macro, disable macro declaration outside the root scope. @@ -52,10 +54,8 @@ The implementation for original Moonscript language 0.5.0 can be found in the `0 ### Added Features -* Change operator precedence to 1 ^ 2 unary operators (not, #, -, ~) 3 |> 4 *, /, //, %, ... - +* Change operator precedence to (1) ^ (2) unary operators (not, #, -, ~) (3) |> (4) *, /, //, %, ... * Make back call operator use highest priority for operator precedence. - * Add existential operator support for `with` statement. * Add repeat until statement support. * Allow implicitly returning block macro. diff --git a/src/MoonP/moon_compiler.cpp b/src/MoonP/moon_compiler.cpp index 1283422..41d29df 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.3"sv; + return "0.4.4"sv; } // name of table stored in lua registry @@ -3814,7 +3814,7 @@ private: } case id(): transformExp(static_cast(key), 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(): transformDoubleString(static_cast(key), temp); @@ -3873,10 +3873,19 @@ private: temp.push_back(s("\""sv) + str + s("\""sv)); break; } - case id(): + case id(): { transformExp(static_cast(content), temp, ExpUsage::Closure); - temp.back() = s("tostring("sv) + temp.back() + s(")"sv); + std::string tostr("tostring"sv); + temp.back() = tostr + '(' + temp.back() + s(")"sv); + if (_config.lintGlobalVariable) { + if (!isDefined(tostr)) { + if (_globals.find(tostr) == _globals.end()) { + _globals[tostr] = {content->m_begin.m_line, content->m_begin.m_col}; + } + } + } break; + } default: assert(false); break; } } -- cgit v1.2.3-55-g6feb