aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2026-02-19 19:03:07 +0800
committerLi Jin <dragon-fly@qq.com>2026-02-19 19:03:07 +0800
commit9ed05ef421bdc19f2f931544a24298e080a5ed30 (patch)
treef5a3659aa606ac07ac2298a8576e59042f5e0841
parent0ada9d56ae41d07860d61a5ee46bbe67d1424d6f (diff)
downloadyuescript-9ed05ef421bdc19f2f931544a24298e080a5ed30.tar.gz
yuescript-9ed05ef421bdc19f2f931544a24298e080a5ed30.tar.bz2
yuescript-9ed05ef421bdc19f2f931544a24298e080a5ed30.zip
Preserve blank lines between table comments with reserve-commentsHEADmain
-rw-r--r--src/yuescript/yue_ast.h4
-rw-r--r--src/yuescript/yue_compiler.cpp8
-rw-r--r--src/yuescript/yue_parser.cpp5
3 files changed, 13 insertions, 4 deletions
diff --git a/src/yuescript/yue_ast.h b/src/yuescript/yue_ast.h
index d44815e..3236b5a 100644
--- a/src/yuescript/yue_ast.h
+++ b/src/yuescript/yue_ast.h
@@ -730,13 +730,13 @@ AST_NODE(TableBlockIndent)
730 ast_sel_list<false, 730 ast_sel_list<false,
731 VariablePair_t, NormalPair_t, Exp_t, TableBlockIndent_t, 731 VariablePair_t, NormalPair_t, Exp_t, TableBlockIndent_t,
732 MetaVariablePair_t, MetaNormalPair_t, 732 MetaVariablePair_t, MetaNormalPair_t,
733 YueComment_t> values; 733 YueComment_t, EmptyLine_t> values;
734 AST_MEMBER(TableBlockIndent, &sep, &values) 734 AST_MEMBER(TableBlockIndent, &sep, &values)
735AST_END(TableBlockIndent) 735AST_END(TableBlockIndent)
736 736
737AST_NODE(TableBlock) 737AST_NODE(TableBlock)
738 ast_ptr<true, Seperator_t> sep; 738 ast_ptr<true, Seperator_t> sep;
739 ast_sel_list<false, VariablePair_t, NormalPair_t, TableBlockIndent_t, Exp_t, TableBlock_t, SpreadExp_t, MetaVariablePair_t, MetaNormalPair_t, YueComment_t> values; 739 ast_sel_list<false, VariablePair_t, NormalPair_t, TableBlockIndent_t, Exp_t, TableBlock_t, SpreadExp_t, MetaVariablePair_t, MetaNormalPair_t, YueComment_t, EmptyLine_t> values;
740 AST_MEMBER(TableBlock, &sep, &values) 740 AST_MEMBER(TableBlock, &sep, &values)
741AST_END(TableBlock) 741AST_END(TableBlock)
742 742
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp
index f67e921..38e9fbb 100644
--- a/src/yuescript/yue_compiler.cpp
+++ b/src/yuescript/yue_compiler.cpp
@@ -734,6 +734,7 @@ private:
734 return isLocal(variableToString(pair->name)); 734 return isLocal(variableToString(pair->name));
735 } 735 }
736 case id<YueComment_t>(): 736 case id<YueComment_t>():
737 case id<EmptyLine_t>():
737 return true; 738 return true;
738 case id<MetaNormalPair_t>(): { 739 case id<MetaNormalPair_t>(): {
739 auto pair = static_cast<MetaNormalPair_t*>(item); 740 auto pair = static_cast<MetaNormalPair_t*>(item);
@@ -8219,6 +8220,8 @@ private:
8219 auto metatable = x->new_ptr<SimpleTable_t>(); 8220 auto metatable = x->new_ptr<SimpleTable_t>();
8220 ast_sel<false, Exp_t, TableBlock_t> metatableItem; 8221 ast_sel<false, Exp_t, TableBlock_t> metatableItem;
8221 ast_node* lastValueNode = values.back(); 8222 ast_node* lastValueNode = values.back();
8223 int lastValueLine = x->m_begin.m_line;
8224 bool prevWasEmptyLine = false;
8222 if (!_config.reserveComment) { 8225 if (!_config.reserveComment) {
8223 for (auto it = values.rbegin(); it != values.rend(); ++it) { 8226 for (auto it = values.rbegin(); it != values.rend(); ++it) {
8224 auto node = *it; 8227 auto node = *it;
@@ -8280,6 +8283,9 @@ private:
8280 switch (item->get_id()) { 8283 switch (item->get_id()) {
8281 case id<Exp_t>(): transformExp(static_cast<Exp_t*>(item), temp, ExpUsage::Closure); break; 8284 case id<Exp_t>(): transformExp(static_cast<Exp_t*>(item), temp, ExpUsage::Closure); break;
8282 case id<YueComment_t>(): { 8285 case id<YueComment_t>(): {
8286 if (_config.reserveComment && !prevWasEmptyLine && value->m_begin.m_line > lastValueLine + 1) {
8287 temp.emplace_back(Empty);
8288 }
8283 auto comment = static_cast<YueComment_t*>(item); 8289 auto comment = static_cast<YueComment_t*>(item);
8284 temp.emplace_back(comment->to_string(&_config)); 8290 temp.emplace_back(comment->to_string(&_config));
8285 skipComma = true; 8291 skipComma = true;
@@ -8352,6 +8358,8 @@ private:
8352 temp.back() = indent() + (value == lastValueNode ? temp.back() : temp.back() + ',') + nl(value); 8358 temp.back() = indent() + (value == lastValueNode ? temp.back() : temp.back() + ',') + nl(value);
8353 } 8359 }
8354 } 8360 }
8361 lastValueLine = value->m_end.m_line;
8362 prevWasEmptyLine = ast_is<EmptyLine_t>(value);
8355 } 8363 }
8356 if (metatable->pairs.empty() && !metatableItem) { 8364 if (metatable->pairs.empty() && !metatableItem) {
8357 out.push_back('{' + nl(x) + join(temp)); 8365 out.push_back('{' + nl(x) + join(temp));
diff --git a/src/yuescript/yue_parser.cpp b/src/yuescript/yue_parser.cpp
index 21f19a3..ffe3ad2 100644
--- a/src/yuescript/yue_parser.cpp
+++ b/src/yuescript/yue_parser.cpp
@@ -909,11 +909,11 @@ YueParser::YueParser() {
909 white >> '}' 909 white >> '}'
910 ); 910 );
911 911
912 table_block_inner = Seperator >> key_value_line >> *((+(plain_space >> line_break) >> key_value_line) | (+space_break >> not_(expr("--")) >> key_value_line)); 912 table_block_inner = Seperator >> key_value_line >> *(((plain_space >> line_break) >> key_value_line) | (+space_break >> not_(expr("--")) >> key_value_line));
913 TableBlock = ((+(plain_space >> line_break)) | (+space_break >> not_(expr("--")))) >> advance_match >> ensure(table_block_inner, pop_indent); 913 TableBlock = ((+(plain_space >> line_break)) | (+space_break >> not_(expr("--")))) >> advance_match >> ensure(table_block_inner, pop_indent);
914 TableBlockIndent = ('*' | '-' >> space_one) >> Seperator >> disable_arg_table_block_rule( 914 TableBlockIndent = ('*' | '-' >> space_one) >> Seperator >> disable_arg_table_block_rule(
915 space >> key_value_list >> -(space >> ',') >> 915 space >> key_value_list >> -(space >> ',') >>
916 -((plain_space >> line_break >> advance_match >> space >> ensure(key_value_list >> -(space >> ',') >> *((+(plain_space >> line_break) >> key_value_line) | (+space_break >> not_(expr("--")) >> key_value_line)), pop_indent)) | 916 -((plain_space >> line_break >> advance_match >> space >> ensure(key_value_list >> -(space >> ',') >> *(((plain_space >> line_break) >> key_value_line) | (+space_break >> not_(expr("--")) >> key_value_line)), pop_indent)) |
917 (+space_break >> advance_match >> space >> ensure(key_value_list >> -(space >> ',') >> *(+space_break >> key_value_line), pop_indent)))); 917 (+space_break >> advance_match >> space >> ensure(key_value_list >> -(space >> ',') >> *(+space_break >> key_value_line), pop_indent))));
918 918
919 ClassMemberList = Seperator >> key_value >> *(space >> ',' >> space >> key_value); 919 ClassMemberList = Seperator >> key_value >> *(space >> ',' >> space >> key_value);
@@ -1019,6 +1019,7 @@ YueParser::YueParser() {
1019 MetaNormalPair; 1019 MetaNormalPair;
1020 key_value_list = key_value >> *(space >> ',' >> space >> key_value); 1020 key_value_list = key_value >> *(space >> ',' >> space >> key_value);
1021 key_value_line = 1021 key_value_line =
1022 (EmptyLine >> YueComment) |
1022 YueComment | 1023 YueComment |
1023 check_indent_match >> space >> ( 1024 check_indent_match >> space >> (
1024 key_value_list >> -(space >> ',') | 1025 key_value_list >> -(space >> ',') |