diff options
| -rw-r--r-- | spec/inputs/syntax.yue | 4 | ||||
| -rw-r--r-- | spec/outputs/syntax.lua | 3 | ||||
| -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 |
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 | |||
| 538 | 538 | ||
| 539 | q = 1 --[[it's q]]; --[[got w]] w = 2; e = 3; print --[[param q]] q, w, e; --[[here]] -- line ends | 539 | q = 1 --[[it's q]]; --[[got w]] w = 2; e = 3; print --[[param q]] q, w, e; --[[here]] -- line ends |
| 540 | 540 | ||
| 541 | do | ||
| 542 | --[[abc]] --[[def]]--[[ dsdsd ]]--OK end | ||
| 543 | print 123 --[[one]] -- two | ||
| 544 | |||
| 541 | nil | 545 | nil |
| 542 | 546 | ||
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 | |||
| 520 | local w = 2 | 520 | local w = 2 |
| 521 | local e = 3 | 521 | local e = 3 |
| 522 | print(q, w, e) | 522 | print(q, w, e) |
| 523 | do | ||
| 524 | print(123) | ||
| 525 | end | ||
| 523 | return nil | 526 | 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 { | |||
| 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) { |
