diff options
| author | Li Jin <dragon-fly@qq.com> | 2026-02-19 13:38:22 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2026-02-19 13:38:22 +0800 |
| commit | 81d306ef60b145ccd118ac9809905eac7e1f7d15 (patch) | |
| tree | 7c0acb5efb49daac67b53620e2db9815dc05b22d | |
| parent | e47dd22aa270d9a7bd7dd9a6cc312db17815f6f1 (diff) | |
| download | yuescript-81d306ef60b145ccd118ac9809905eac7e1f7d15.tar.gz yuescript-81d306ef60b145ccd118ac9809905eac7e1f7d15.tar.bz2 yuescript-81d306ef60b145ccd118ac9809905eac7e1f7d15.zip | |
feat(parser): preserve TableBlock comment lines in AST
| -rw-r--r-- | src/yuescript/yue_ast.h | 5 | ||||
| -rw-r--r-- | src/yuescript/yue_compiler.cpp | 2 | ||||
| -rw-r--r-- | src/yuescript/yue_parser.cpp | 16 |
3 files changed, 14 insertions, 9 deletions
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) | |||
| 729 | ast_ptr<true, Seperator_t> sep; | 729 | ast_ptr<true, Seperator_t> sep; |
| 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> values; | 732 | MetaVariablePair_t, MetaNormalPair_t, |
| 733 | YueComment_t> values; | ||
| 733 | AST_MEMBER(TableBlockIndent, &sep, &values) | 734 | AST_MEMBER(TableBlockIndent, &sep, &values) |
| 734 | AST_END(TableBlockIndent) | 735 | AST_END(TableBlockIndent) |
| 735 | 736 | ||
| 736 | AST_NODE(TableBlock) | 737 | AST_NODE(TableBlock) |
| 737 | ast_ptr<true, Seperator_t> sep; | 738 | ast_ptr<true, Seperator_t> sep; |
| 738 | ast_sel_list<false, VariablePair_t, NormalPair_t, TableBlockIndent_t, Exp_t, TableBlock_t, SpreadExp_t, MetaVariablePair_t, MetaNormalPair_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> values; |
| 739 | AST_MEMBER(TableBlock, &sep, &values) | 740 | AST_MEMBER(TableBlock, &sep, &values) |
| 740 | AST_END(TableBlock) | 741 | AST_END(TableBlock) |
| 741 | 742 | ||
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: | |||
| 733 | auto pair = static_cast<MetaVariablePair_t*>(item); | 733 | auto pair = static_cast<MetaVariablePair_t*>(item); |
| 734 | return isLocal(variableToString(pair->name)); | 734 | return isLocal(variableToString(pair->name)); |
| 735 | } | 735 | } |
| 736 | case id<YueComment_t>(): | ||
| 737 | return true; | ||
| 736 | case id<MetaNormalPair_t>(): { | 738 | case id<MetaNormalPair_t>(): { |
| 737 | auto pair = static_cast<MetaNormalPair_t*>(item); | 739 | auto pair = static_cast<MetaNormalPair_t*>(item); |
| 738 | if (auto str = pair->key.as<String_t>()) { | 740 | if (auto str = pair->key.as<String_t>()) { |
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() { | |||
| 909 | white >> '}' | 909 | white >> '}' |
| 910 | ); | 910 | ); |
| 911 | 911 | ||
| 912 | table_block_inner = Seperator >> key_value_line >> *(+space_break >> key_value_line); | 912 | table_block_inner = Seperator >> key_value_line >> *(+(plain_space >> line_break) >> key_value_line); |
| 913 | TableBlock = +space_break >> advance_match >> ensure(table_block_inner, pop_indent); | 913 | TableBlock = +space_break >> 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 | -(+space_break >> advance_match >> space >> ensure(key_value_list >> -(space >> ',') >> *(+space_break >> 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), pop_indent))); |
| 917 | 917 | ||
| 918 | ClassMemberList = Seperator >> key_value >> *(space >> ',' >> space >> key_value); | 918 | ClassMemberList = Seperator >> key_value >> *(space >> ',' >> space >> key_value); |
| 919 | class_line = check_indent_match >> space >> (ClassMemberList | Statement) >> -(space >> ','); | 919 | class_line = check_indent_match >> space >> (ClassMemberList | Statement) >> -(space >> ','); |
| @@ -1017,11 +1017,13 @@ YueParser::YueParser() { | |||
| 1017 | MetaVariablePair | | 1017 | MetaVariablePair | |
| 1018 | MetaNormalPair; | 1018 | MetaNormalPair; |
| 1019 | key_value_list = key_value >> *(space >> ',' >> space >> key_value); | 1019 | key_value_list = key_value >> *(space >> ',' >> space >> key_value); |
| 1020 | key_value_line = check_indent_match >> space >> ( | 1020 | key_value_line = |
| 1021 | key_value_list >> -(space >> ',') | | 1021 | YueComment | |
| 1022 | TableBlockIndent | | 1022 | check_indent_match >> space >> ( |
| 1023 | ('*' | '-' >> space_one) >> space >> (SpreadExp | Exp | TableBlock) | 1023 | key_value_list >> -(space >> ',') | |
| 1024 | ); | 1024 | TableBlockIndent | |
| 1025 | ('*' | '-' >> space_one) >> space >> (SpreadExp | Exp | TableBlock) | ||
| 1026 | ); | ||
| 1025 | 1027 | ||
| 1026 | fn_arg_def_list = FnArgDef >> *(space >> ',' >> space >> FnArgDef); | 1028 | fn_arg_def_list = FnArgDef >> *(space >> ',' >> space >> FnArgDef); |
| 1027 | 1029 | ||
