aboutsummaryrefslogtreecommitdiff
path: root/src/MoonP
diff options
context:
space:
mode:
Diffstat (limited to 'src/MoonP')
-rw-r--r--src/MoonP/moon_compiler.cpp16
-rw-r--r--src/MoonP/moon_parser.h7
2 files changed, 14 insertions, 9 deletions
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) {
53 return std::string(sv); 53 return std::string(sv);
54} 54}
55 55
56const std::string_view version = "0.4.24"sv; 56const std::string_view version = "0.4.26"sv;
57const std::string_view extension = "mp"sv; 57const std::string_view extension = "mp"sv;
58 58
59class MoonCompilerImpl { 59class MoonCompilerImpl {
@@ -1555,7 +1555,10 @@ private:
1555 if (assign) { 1555 if (assign) {
1556 auto exp = ifCondPairs.front().first->condition.get(); 1556 auto exp = ifCondPairs.front().first->condition.get();
1557 auto x = exp; 1557 auto x = exp;
1558 bool lintGlobal = _config.lintGlobalVariable;
1559 _config.lintGlobalVariable = false;
1558 auto var = singleVariableFrom(exp); 1560 auto var = singleVariableFrom(exp);
1561 _config.lintGlobalVariable = lintGlobal;
1559 if (var.empty()) { 1562 if (var.empty()) {
1560 storingValue = true; 1563 storingValue = true;
1561 auto desVar = getUnusedName("_des_"sv); 1564 auto desVar = getUnusedName("_des_"sv);
@@ -3234,6 +3237,7 @@ private:
3234 str_list localVars; 3237 str_list localVars;
3235 std::tie(type, codes, localVars) = expandMacroStr(chainValue); 3238 std::tie(type, codes, localVars) = expandMacroStr(chainValue);
3236 std::string targetType(usage != ExpUsage::Common || chainList.size() > 2 ? "expr"sv : "block"sv); 3239 std::string targetType(usage != ExpUsage::Common || chainList.size() > 2 ? "expr"sv : "block"sv);
3240 ParseInfo info;
3237 if (type == "lua"sv) { 3241 if (type == "lua"sv) {
3238 if (!allowBlockMacroReturn && targetType != "block"sv) { 3242 if (!allowBlockMacroReturn && targetType != "block"sv) {
3239 throw std::logic_error(_info.errorMessage("lua macro can only be placed where block macro is allowed"sv, x)); 3243 throw std::logic_error(_info.errorMessage("lua macro can only be placed where block macro is allowed"sv, x));
@@ -3252,9 +3256,14 @@ private:
3252 } 3256 }
3253 return {nullptr, nullptr, std::move(codes), std::move(localVars)}; 3257 return {nullptr, nullptr, std::move(codes), std::move(localVars)};
3254 } else if (!allowBlockMacroReturn && type != targetType) { 3258 } else if (!allowBlockMacroReturn && type != targetType) {
3255 throw std::logic_error(_info.errorMessage(s("macro type mismatch, "sv) + targetType + s(" expected, got "sv) + type, x)); 3259 if (!codes.empty() && targetType == "block") {
3260 info = _parser.parse<Block_t>(codes);
3261 }
3262 if (info.node) type = "block";
3263 else throw std::logic_error(_info.errorMessage(s("macro type mismatch, "sv) + targetType + s(" expected, got "sv) + type, x));
3256 } 3264 }
3257 ParseInfo info; 3265 BLOCK_START
3266 BREAK_IF(info.node);
3258 if (usage == ExpUsage::Common) { 3267 if (usage == ExpUsage::Common) {
3259 if (codes.empty()) { 3268 if (codes.empty()) {
3260 return {x->new_ptr<Block_t>().get(), std::move(info.codes), Empty, std::move(localVars)}; 3269 return {x->new_ptr<Block_t>().get(), std::move(info.codes), Empty, std::move(localVars)};
@@ -3273,6 +3282,7 @@ private:
3273 } else { 3282 } else {
3274 info = _parser.parse<Exp_t>(codes); 3283 info = _parser.parse<Exp_t>(codes);
3275 } 3284 }
3285 BLOCK_END
3276 if (!info.node) { 3286 if (!info.node) {
3277 info.error = info.error.substr(info.error.find(':') + 2); 3287 info.error = info.error.substr(info.error.find(':') + 2);
3278 throw std::logic_error(_info.errorMessage("failed to parse expanded codes: " + info.error, x)); 3288 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:
48 48
49 template<class AST> 49 template<class AST>
50 ParseInfo parse(std::string_view codes) { 50 ParseInfo parse(std::string_view codes) {
51 error_list errors; 51 return parse(codes, getRule<AST>());
52 auto res = parse(codes, getRule<AST>());
53 if (res.node.template is<AST>()) {
54 return res;
55 }
56 return res;
57 } 52 }
58 53
59 template <class AST> 54 template <class AST>