From 32651cccb380bf4682fa8f6d3e70d74952171f7b Mon Sep 17 00:00:00 2001 From: Li Jin Date: Sat, 6 Feb 2021 10:41:30 +0800 Subject: fix #38 --- src/MoonP/moon_compiler.cpp | 16 +++++++++++++--- src/MoonP/moon_parser.h | 7 +------ 2 files changed, 14 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/MoonP/moon_compiler.cpp b/src/MoonP/moon_compiler.cpp index fcdde59..4812cf4 100644 --- a/src/MoonP/moon_compiler.cpp +++ b/src/MoonP/moon_compiler.cpp @@ -53,7 +53,7 @@ inline std::string s(std::string_view sv) { return std::string(sv); } -const std::string_view version = "0.4.24"sv; +const std::string_view version = "0.4.26"sv; const std::string_view extension = "mp"sv; class MoonCompilerImpl { @@ -1555,7 +1555,10 @@ private: if (assign) { auto exp = ifCondPairs.front().first->condition.get(); auto x = exp; + bool lintGlobal = _config.lintGlobalVariable; + _config.lintGlobalVariable = false; auto var = singleVariableFrom(exp); + _config.lintGlobalVariable = lintGlobal; if (var.empty()) { storingValue = true; auto desVar = getUnusedName("_des_"sv); @@ -3234,6 +3237,7 @@ private: str_list localVars; std::tie(type, codes, localVars) = expandMacroStr(chainValue); std::string targetType(usage != ExpUsage::Common || chainList.size() > 2 ? "expr"sv : "block"sv); + ParseInfo info; if (type == "lua"sv) { if (!allowBlockMacroReturn && targetType != "block"sv) { throw std::logic_error(_info.errorMessage("lua macro can only be placed where block macro is allowed"sv, x)); @@ -3252,9 +3256,14 @@ private: } return {nullptr, nullptr, std::move(codes), std::move(localVars)}; } else if (!allowBlockMacroReturn && type != targetType) { - throw std::logic_error(_info.errorMessage(s("macro type mismatch, "sv) + targetType + s(" expected, got "sv) + type, x)); + if (!codes.empty() && targetType == "block") { + info = _parser.parse(codes); + } + if (info.node) type = "block"; + else throw std::logic_error(_info.errorMessage(s("macro type mismatch, "sv) + targetType + s(" expected, got "sv) + type, x)); } - ParseInfo info; + BLOCK_START + BREAK_IF(info.node); if (usage == ExpUsage::Common) { if (codes.empty()) { return {x->new_ptr().get(), std::move(info.codes), Empty, std::move(localVars)}; @@ -3273,6 +3282,7 @@ private: } else { info = _parser.parse(codes); } + BLOCK_END if (!info.node) { info.error = info.error.substr(info.error.find(':') + 2); throw std::logic_error(_info.errorMessage("failed to parse expanded codes: " + info.error, x)); diff --git a/src/MoonP/moon_parser.h b/src/MoonP/moon_parser.h index 832d39d..d965d87 100644 --- a/src/MoonP/moon_parser.h +++ b/src/MoonP/moon_parser.h @@ -48,12 +48,7 @@ public: template ParseInfo parse(std::string_view codes) { - error_list errors; - auto res = parse(codes, getRule()); - if (res.node.template is()) { - return res; - } - return res; + return parse(codes, getRule()); } template -- cgit v1.2.3-55-g6feb