From e96308912e2e04535836a2c282b0a7300d2d81fd Mon Sep 17 00:00:00 2001 From: Li Jin Date: Fri, 11 Apr 2025 17:33:12 +0800 Subject: Fixing issue #206. --- src/yuescript/yue_ast.h | 1 + src/yuescript/yue_compiler.cpp | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/yuescript/yue_ast.h b/src/yuescript/yue_ast.h index e670126..5e70645 100644 --- a/src/yuescript/yue_ast.h +++ b/src/yuescript/yue_ast.h @@ -620,6 +620,7 @@ AST_END(Slice) AST_NODE(Parens) ast_ptr expr; + bool extra = false; AST_MEMBER(Parens, &expr) AST_END(Parens) diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index a2a1864..68ce9b5 100644 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp @@ -75,7 +75,7 @@ static std::unordered_set Metamethods = { "close"s // Lua 5.4 }; -const std::string_view version = "0.27.3"sv; +const std::string_view version = "0.27.4"sv; const std::string_view extension = "yue"sv; class CompileError : public std::logic_error { @@ -1080,8 +1080,8 @@ private: if (unary->ops.empty()) { Value_t* value = static_cast(unary->expos.back()); if (auto chain = ast_cast(value->item); chain && chain->items.size() == 1) { - if (auto exp = chain->get_by_path()) { - if (auto insideValue = singleValueFrom(exp)) { + if (auto parens = chain->get_by_path(); parens && parens->extra) { + if (auto insideValue = singleValueFrom(parens->expr)) { return insideValue; } } @@ -3262,6 +3262,7 @@ private: } else if (destruct.items.size() == 1 && !singleValueFrom(*j)) { auto p = destruct.value.get(); auto parens = p->new_ptr(); + parens->extra = true; if (auto tableBlock = ast_cast(p)) { auto tableLit = p->new_ptr(); tableLit->values.dup(tableBlock->values); @@ -4750,6 +4751,7 @@ private: newSimpleValue->value.set(funLit); auto newExpInParens = newExp(newSimpleValue, x); auto newParens = x->new_ptr(); + newParens->extra = true; newParens->expr.set(newExpInParens); auto newCallable = x->new_ptr(); newCallable->item.set(newParens); @@ -5570,6 +5572,7 @@ private: auto x = chainList.front(); if (ast_is(chainList.back())) { auto parens = x->new_ptr(); + parens->extra = true; { auto chainValue = x->new_ptr(); for (auto item : chainList) { @@ -6163,6 +6166,7 @@ private: ++next; if (next != chainList.end()) { auto paren = x->new_ptr(); + paren->extra = true; paren->expr.set(newExp(chainValue, x)); auto ncallable = x->new_ptr(); ncallable->item.set(paren); @@ -6215,6 +6219,7 @@ private: simpleValue->value.set(funLit); auto exp = newExp(simpleValue, x); auto paren = x->new_ptr(); + paren->extra = true; paren->expr.set(exp); auto callable = x->new_ptr(); callable->item.set(paren); @@ -6631,6 +6636,7 @@ private: exp.set(info.node); if (!exp->opValues.empty() || (chainList.size() > 2 || (chainList.size() == 2 && !ast_is(chainList.back())))) { auto paren = x->new_ptr(); + paren->extra = true; paren->expr.set(exp); auto callable = x->new_ptr(); callable->item.set(paren); -- cgit v1.2.3-55-g6feb