From cbcbefaa218a02389b6385ab83c501cd3d03bde8 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Tue, 25 Jul 2023 16:18:54 +0800 Subject: added a missing Yuescript code formating case. --- CHANGELOG.md | 10 +++++++++- src/yuescript/yue_ast.cpp | 10 +++------- src/yuescript/yue_compiler.cpp | 2 +- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ac9811..95ae614 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ The implementation for the original Moonscript language 0.5.0 can be found in the `0.5.0` branch of Yuescript. The Moonscript with fixes and new features is in the main branch of Yuescript. Here are the changelogs for each Yuescript version. -## v0.17.0 +## v0.17.10 ### Added Features @@ -14,13 +14,21 @@ The implementation for the original Moonscript language 0.5.0 can be found in th switch a when not in [1, 10] print "not (1 <= a <= 10)" + + if item in list + print "item existed in a list" ``` * Added metamethod name checking for chain expression. +* Added feature to reformat the expressions passed as macro function arguments to the formated code strings. +* Added -r option to rewrite compiled Lua code output to match original Yuescript code line numbers. ### Fixed Issues * Fixed a LuaJIT module loading issue. * Fixed built-in $FILE macro does not escape backslash on Windows. +* Fixed more ambiguous Lua codes generation cases. +* Fixed syntax error should throw for invalid interpolation. +* Fixed an AST object life expired before accessing issue. ## v0.16.4 diff --git a/src/yuescript/yue_ast.cpp b/src/yuescript/yue_ast.cpp index f243d24..fee15af 100644 --- a/src/yuescript/yue_ast.cpp +++ b/src/yuescript/yue_ast.cpp @@ -1156,21 +1156,17 @@ std::string UnaryExp_t::to_string(void* ud) const { } std::string InRange_t::to_string(void* ud) const { auto valueStr = openValue->to_string(ud); - return "in "s + (open.is() ? "("s : "["s + (valueStr[0] == '[' ? " "s : ""s)) + valueStr + ", "s + closeValue->to_string(ud) + (close.is() ? ')' : ']'); + return (open.is() ? "("s : "["s + (valueStr[0] == '[' ? " "s : ""s)) + valueStr + ", "s + closeValue->to_string(ud) + (close.is() ? ')' : ']'); } std::string InDiscrete_t::to_string(void* ud) const { str_list temp; for (auto value : values.objects()) { temp.emplace_back(value->to_string(ud)); } - return "in "s + '{' + join(temp, ", "sv) + '}'; + return '{' + join(temp, ", "sv) + '}'; } std::string In_t::to_string(void* ud) const { - if (not_) { - return "not "s + item->to_string(ud); - } else { - return item->to_string(ud); - } + return (not_ ? "not "s : ""s) + "in "s + item->to_string(ud); } std::string ExpListAssign_t::to_string(void* ud) const { if (action) { diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index f4e1102..0b9889d 100644 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp @@ -72,7 +72,7 @@ static std::unordered_set Metamethods = { "close"s // Lua 5.4 }; -const std::string_view version = "0.17.9"sv; +const std::string_view version = "0.17.10"sv; const std::string_view extension = "yue"sv; class CompileError : public std::logic_error { -- cgit v1.2.3-55-g6feb