From 542c0d9f7db54b47d9372115bfc3d1548a0d8504 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Thu, 5 Feb 2026 16:22:00 +0800 Subject: Fixed issue #227. --- spec/inputs/syntax.yue | 4 ++++ spec/outputs/syntax.lua | 3 +++ src/yuescript/yue_ast.cpp | 8 ++++---- src/yuescript/yue_ast.h | 4 ++-- src/yuescript/yue_compiler.cpp | 29 ++++++++++++++++------------- 5 files changed, 29 insertions(+), 19 deletions(-) diff --git a/spec/inputs/syntax.yue b/spec/inputs/syntax.yue index ccf8b01..9f5aed1 100644 --- a/spec/inputs/syntax.yue +++ b/spec/inputs/syntax.yue @@ -538,5 +538,9 @@ do q = 1 --[[it's q]]; --[[got w]] w = 2; e = 3; print --[[param q]] q, w, e; --[[here]] -- line ends +do + --[[abc]] --[[def]]--[[ dsdsd ]]--OK end + print 123 --[[one]] -- two + nil diff --git a/spec/outputs/syntax.lua b/spec/outputs/syntax.lua index eb4543c..35b1e32 100644 --- a/spec/outputs/syntax.lua +++ b/spec/outputs/syntax.lua @@ -520,4 +520,7 @@ local q = 1 local w = 2 local e = 3 print(q, w, e) +do + print(123) +end return nil diff --git a/src/yuescript/yue_ast.cpp b/src/yuescript/yue_ast.cpp index 89b8d3f..2fccd35 100644 --- a/src/yuescript/yue_ast.cpp +++ b/src/yuescript/yue_ast.cpp @@ -215,11 +215,11 @@ std::string YueMultilineComment_t::to_string(void* ud) const { return "--[["s + info->convert(this) + "]]"s; } std::string YueComment_t::to_string(void* ud) const { - if (comment) { - return comment->to_string(ud); - } else { - return {}; + str_list coms; + for (auto comment : comments.objects()) { + coms.emplace_back(comment->to_string(ud)); } + return join(coms, " "sv); } std::string Variable_t::to_string(void* ud) const { return name->to_string(ud); diff --git a/src/yuescript/yue_ast.h b/src/yuescript/yue_ast.h index 5faeed5..98f9014 100644 --- a/src/yuescript/yue_ast.h +++ b/src/yuescript/yue_ast.h @@ -940,8 +940,8 @@ AST_LEAF(YueMultilineComment) AST_END(YueMultilineComment) AST_NODE(YueComment) - ast_sel comment; - AST_MEMBER(YueComment, &comment) + ast_sel_list comments; + AST_MEMBER(YueComment, &comments) AST_END(YueComment) AST_LEAF(EmptyLine) diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index 6aa7cfd..bcc44d2 100644 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp @@ -78,7 +78,7 @@ static std::unordered_set Metamethods = { "close"s // Lua 5.4 }; -const std::string_view version = "0.32.7"sv; +const std::string_view version = "0.32.8"sv; const std::string_view extension = "yue"sv; class CompileError : public std::logic_error { @@ -1742,23 +1742,26 @@ private: if (!_config.reserveComment) { return; } - auto node = comment->comment.get(); - if (!node) { + if (comment->comments.empty()) { out.push_back("\n"s); return; } - switch (node->get_id()) { - case id(): { - auto content = static_cast(node); - out.push_back(indent() + "--"s + _parser.toString(content) + '\n'); - break; - } - case id(): { - auto content = static_cast(node); - out.push_back(indent() + "--[["s + _parser.toString(content) + "]]\n"s); - break; + str_list temp; + for (auto node : comment->comments.objects()) { + switch (node->get_id()) { + case id(): { + auto content = static_cast(node); + temp.emplace_back(indent() + "--"s + _parser.toString(content)); + break; + } + case id(): { + auto content = static_cast(node); + temp.emplace_back(indent() + "--[["s + _parser.toString(content) + "]]"s); + break; + } } } + out.push_back(join(temp, " "sv) + '\n'); } void transformStatement(Statement_t* statement, str_list& out) { -- cgit v1.2.3-55-g6feb