diff options
| author | Li Jin <dragon-fly@qq.com> | 2026-02-20 09:08:26 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2026-02-20 09:08:26 +0800 |
| commit | 3d1d5aad072034a7fe7dd8833835f52e7ef3e404 (patch) | |
| tree | 9858743d762815c06ea2d8b8cff3c92ae76891b4 | |
| parent | 9ed05ef421bdc19f2f931544a24298e080a5ed30 (diff) | |
| download | yuescript-codex/add-blank-line-handling-to-classblock.tar.gz yuescript-codex/add-blank-line-handling-to-classblock.tar.bz2 yuescript-codex/add-blank-line-handling-to-classblock.zip | |
Support comments and empty lines in class blockscodex/add-blank-line-handling-to-classblock
Diffstat (limited to '')
| -rw-r--r-- | src/yuescript/yue_ast.cpp | 15 | ||||
| -rw-r--r-- | src/yuescript/yue_ast.h | 2 | ||||
| -rw-r--r-- | src/yuescript/yue_compiler.cpp | 5 | ||||
| -rw-r--r-- | src/yuescript/yue_parser.cpp | 5 |
4 files changed, 20 insertions, 7 deletions
diff --git a/src/yuescript/yue_ast.cpp b/src/yuescript/yue_ast.cpp index 4d62d05..e5f8d12 100644 --- a/src/yuescript/yue_ast.cpp +++ b/src/yuescript/yue_ast.cpp | |||
| @@ -1242,10 +1242,17 @@ std::string ClassBlock_t::to_string(void* ud) const { | |||
| 1242 | str_list temp; | 1242 | str_list temp; |
| 1243 | info->pushScope(); | 1243 | info->pushScope(); |
| 1244 | for (auto content : contents.objects()) { | 1244 | for (auto content : contents.objects()) { |
| 1245 | if (ast_is<Statement_t>(content)) { | 1245 | switch (content->get_id()) { |
| 1246 | temp.emplace_back(info->ind() + content->to_string(ud)); | 1246 | case id<Statement_t>(): |
| 1247 | } else { | 1247 | case id<YueComment_t>(): |
| 1248 | temp.emplace_back(content->to_string(ud)); | 1248 | temp.emplace_back(info->ind() + content->to_string(ud)); |
| 1249 | break; | ||
| 1250 | case id<EmptyLine_t>(): | ||
| 1251 | temp.emplace_back(""s); | ||
| 1252 | break; | ||
| 1253 | default: | ||
| 1254 | temp.emplace_back(content->to_string(ud)); | ||
| 1255 | break; | ||
| 1249 | } | 1256 | } |
| 1250 | } | 1257 | } |
| 1251 | info->popScope(); | 1258 | info->popScope(); |
diff --git a/src/yuescript/yue_ast.h b/src/yuescript/yue_ast.h index 3236b5a..6919f7a 100644 --- a/src/yuescript/yue_ast.h +++ b/src/yuescript/yue_ast.h | |||
| @@ -748,7 +748,7 @@ AST_END(ClassMemberList) | |||
| 748 | 748 | ||
| 749 | AST_NODE(ClassBlock) | 749 | AST_NODE(ClassBlock) |
| 750 | ast_ptr<true, Seperator_t> sep; | 750 | ast_ptr<true, Seperator_t> sep; |
| 751 | ast_sel_list<true, ClassMemberList_t, Statement_t> contents; | 751 | ast_sel_list<true, ClassMemberList_t, Statement_t, YueComment_t, EmptyLine_t> contents; |
| 752 | AST_MEMBER(ClassBlock, &sep, &contents) | 752 | AST_MEMBER(ClassBlock, &sep, &contents) |
| 753 | AST_END(ClassBlock) | 753 | AST_END(ClassBlock) |
| 754 | 754 | ||
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index 38e9fbb..1abd662 100644 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp | |||
| @@ -9976,7 +9976,10 @@ private: | |||
| 9976 | } | 9976 | } |
| 9977 | break; | 9977 | break; |
| 9978 | } | 9978 | } |
| 9979 | case id<Statement_t>(): break; | 9979 | case id<Statement_t>(): |
| 9980 | case id<YueComment_t>(): | ||
| 9981 | case id<EmptyLine_t>(): | ||
| 9982 | break; | ||
| 9980 | default: YUEE("AST node mismatch", content); break; | 9983 | default: YUEE("AST node mismatch", content); break; |
| 9981 | } | 9984 | } |
| 9982 | } | 9985 | } |
diff --git a/src/yuescript/yue_parser.cpp b/src/yuescript/yue_parser.cpp index ffe3ad2..3772af0 100644 --- a/src/yuescript/yue_parser.cpp +++ b/src/yuescript/yue_parser.cpp | |||
| @@ -917,7 +917,10 @@ YueParser::YueParser() { | |||
| 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); |
| 920 | class_line = check_indent_match >> space >> (ClassMemberList | Statement) >> -(space >> ','); | 920 | class_line = |
| 921 | (EmptyLine >> YueComment) | | ||
| 922 | YueComment | | ||
| 923 | check_indent_match >> space >> (ClassMemberList | Statement) >> -(space >> ','); | ||
| 921 | ClassBlock = | 924 | ClassBlock = |
| 922 | +space_break >> | 925 | +space_break >> |
| 923 | advance_match >> Seperator >> | 926 | advance_match >> Seperator >> |
