From 81d306ef60b145ccd118ac9809905eac7e1f7d15 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Thu, 19 Feb 2026 13:38:22 +0800 Subject: feat(parser): preserve TableBlock comment lines in AST --- src/yuescript/yue_ast.h | 5 +++-- src/yuescript/yue_compiler.cpp | 2 ++ src/yuescript/yue_parser.cpp | 16 +++++++++------- 3 files changed, 14 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/yuescript/yue_ast.h b/src/yuescript/yue_ast.h index 9d6d26e..d44815e 100644 --- a/src/yuescript/yue_ast.h +++ b/src/yuescript/yue_ast.h @@ -729,13 +729,14 @@ AST_NODE(TableBlockIndent) ast_ptr sep; ast_sel_list values; + MetaVariablePair_t, MetaNormalPair_t, + YueComment_t> values; AST_MEMBER(TableBlockIndent, &sep, &values) AST_END(TableBlockIndent) AST_NODE(TableBlock) ast_ptr sep; - ast_sel_list values; + ast_sel_list values; AST_MEMBER(TableBlock, &sep, &values) AST_END(TableBlock) diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index d85c92b..9891e79 100644 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp @@ -733,6 +733,8 @@ private: auto pair = static_cast(item); return isLocal(variableToString(pair->name)); } + case id(): + return true; case id(): { auto pair = static_cast(item); if (auto str = pair->key.as()) { diff --git a/src/yuescript/yue_parser.cpp b/src/yuescript/yue_parser.cpp index e3dc598..a43cdd7 100644 --- a/src/yuescript/yue_parser.cpp +++ b/src/yuescript/yue_parser.cpp @@ -909,11 +909,11 @@ YueParser::YueParser() { white >> '}' ); - table_block_inner = Seperator >> key_value_line >> *(+space_break >> key_value_line); + table_block_inner = Seperator >> key_value_line >> *(+(plain_space >> line_break) >> key_value_line); TableBlock = +space_break >> advance_match >> ensure(table_block_inner, pop_indent); TableBlockIndent = ('*' | '-' >> space_one) >> Seperator >> disable_arg_table_block_rule( space >> key_value_list >> -(space >> ',') >> - -(+space_break >> advance_match >> space >> ensure(key_value_list >> -(space >> ',') >> *(+space_break >> key_value_line), pop_indent))); + -(+(plain_space >> line_break) >> advance_match >> space >> ensure(key_value_list >> -(space >> ',') >> *(+(plain_space >> line_break) >> key_value_line), pop_indent))); ClassMemberList = Seperator >> key_value >> *(space >> ',' >> space >> key_value); class_line = check_indent_match >> space >> (ClassMemberList | Statement) >> -(space >> ','); @@ -1017,11 +1017,13 @@ YueParser::YueParser() { MetaVariablePair | MetaNormalPair; key_value_list = key_value >> *(space >> ',' >> space >> key_value); - key_value_line = check_indent_match >> space >> ( - key_value_list >> -(space >> ',') | - TableBlockIndent | - ('*' | '-' >> space_one) >> space >> (SpreadExp | Exp | TableBlock) - ); + key_value_line = + YueComment | + check_indent_match >> space >> ( + key_value_list >> -(space >> ',') | + TableBlockIndent | + ('*' | '-' >> space_one) >> space >> (SpreadExp | Exp | TableBlock) + ); fn_arg_def_list = FnArgDef >> *(space >> ',' >> space >> FnArgDef); -- cgit v1.2.3-55-g6feb