diff options
| author | Li Jin <dragon-fly@qq.com> | 2026-02-05 16:22:00 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2026-02-05 16:22:00 +0800 |
| commit | 542c0d9f7db54b47d9372115bfc3d1548a0d8504 (patch) | |
| tree | 1293c32564a9bd505e1d9771caaaa8483bffa335 /src | |
| parent | 49513fc94f5a98cb1cc8436d3c2364bee0a75b89 (diff) | |
| download | yuescript-542c0d9f7db54b47d9372115bfc3d1548a0d8504.tar.gz yuescript-542c0d9f7db54b47d9372115bfc3d1548a0d8504.tar.bz2 yuescript-542c0d9f7db54b47d9372115bfc3d1548a0d8504.zip | |
Fixed issue #227.
Diffstat (limited to 'src')
| -rw-r--r-- | src/yuescript/yue_ast.cpp | 8 | ||||
| -rw-r--r-- | src/yuescript/yue_ast.h | 4 | ||||
| -rw-r--r-- | src/yuescript/yue_compiler.cpp | 29 |
3 files changed, 22 insertions, 19 deletions
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 { | |||
| 215 | return "--[["s + info->convert(this) + "]]"s; | 215 | return "--[["s + info->convert(this) + "]]"s; |
| 216 | } | 216 | } |
| 217 | std::string YueComment_t::to_string(void* ud) const { | 217 | std::string YueComment_t::to_string(void* ud) const { |
| 218 | if (comment) { | 218 | str_list coms; |
| 219 | return comment->to_string(ud); | 219 | for (auto comment : comments.objects()) { |
| 220 | } else { | 220 | coms.emplace_back(comment->to_string(ud)); |
| 221 | return {}; | ||
| 222 | } | 221 | } |
| 222 | return join(coms, " "sv); | ||
| 223 | } | 223 | } |
| 224 | std::string Variable_t::to_string(void* ud) const { | 224 | std::string Variable_t::to_string(void* ud) const { |
| 225 | return name->to_string(ud); | 225 | 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) | |||
| 940 | AST_END(YueMultilineComment) | 940 | AST_END(YueMultilineComment) |
| 941 | 941 | ||
| 942 | AST_NODE(YueComment) | 942 | AST_NODE(YueComment) |
| 943 | ast_sel<true, YueLineComment_t, YueMultilineComment_t> comment; | 943 | ast_sel_list<true, YueLineComment_t, YueMultilineComment_t> comments; |
| 944 | AST_MEMBER(YueComment, &comment) | 944 | AST_MEMBER(YueComment, &comments) |
| 945 | AST_END(YueComment) | 945 | AST_END(YueComment) |
| 946 | 946 | ||
| 947 | AST_LEAF(EmptyLine) | 947 | 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<std::string> Metamethods = { | |||
| 78 | "close"s // Lua 5.4 | 78 | "close"s // Lua 5.4 |
| 79 | }; | 79 | }; |
| 80 | 80 | ||
| 81 | const std::string_view version = "0.32.7"sv; | 81 | const std::string_view version = "0.32.8"sv; |
| 82 | const std::string_view extension = "yue"sv; | 82 | const std::string_view extension = "yue"sv; |
| 83 | 83 | ||
| 84 | class CompileError : public std::logic_error { | 84 | class CompileError : public std::logic_error { |
| @@ -1742,23 +1742,26 @@ private: | |||
| 1742 | if (!_config.reserveComment) { | 1742 | if (!_config.reserveComment) { |
| 1743 | return; | 1743 | return; |
| 1744 | } | 1744 | } |
| 1745 | auto node = comment->comment.get(); | 1745 | if (comment->comments.empty()) { |
| 1746 | if (!node) { | ||
| 1747 | out.push_back("\n"s); | 1746 | out.push_back("\n"s); |
| 1748 | return; | 1747 | return; |
| 1749 | } | 1748 | } |
| 1750 | switch (node->get_id()) { | 1749 | str_list temp; |
| 1751 | case id<YueLineComment_t>(): { | 1750 | for (auto node : comment->comments.objects()) { |
| 1752 | auto content = static_cast<YueLineComment_t*>(node); | 1751 | switch (node->get_id()) { |
| 1753 | out.push_back(indent() + "--"s + _parser.toString(content) + '\n'); | 1752 | case id<YueLineComment_t>(): { |
| 1754 | break; | 1753 | auto content = static_cast<YueLineComment_t*>(node); |
| 1755 | } | 1754 | temp.emplace_back(indent() + "--"s + _parser.toString(content)); |
| 1756 | case id<YueMultilineComment_t>(): { | 1755 | break; |
| 1757 | auto content = static_cast<YueMultilineComment_t*>(node); | 1756 | } |
| 1758 | out.push_back(indent() + "--[["s + _parser.toString(content) + "]]\n"s); | 1757 | case id<YueMultilineComment_t>(): { |
| 1759 | break; | 1758 | auto content = static_cast<YueMultilineComment_t*>(node); |
| 1759 | temp.emplace_back(indent() + "--[["s + _parser.toString(content) + "]]"s); | ||
| 1760 | break; | ||
| 1761 | } | ||
| 1760 | } | 1762 | } |
| 1761 | } | 1763 | } |
| 1764 | out.push_back(join(temp, " "sv) + '\n'); | ||
| 1762 | } | 1765 | } |
| 1763 | 1766 | ||
| 1764 | void transformStatement(Statement_t* statement, str_list& out) { | 1767 | void transformStatement(Statement_t* statement, str_list& out) { |
