From 3d1d5aad072034a7fe7dd8833835f52e7ef3e404 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Fri, 20 Feb 2026 09:08:26 +0800 Subject: Support comments and empty lines in class blocks --- src/yuescript/yue_ast.cpp | 15 +++++++++++---- src/yuescript/yue_ast.h | 2 +- src/yuescript/yue_compiler.cpp | 5 ++++- src/yuescript/yue_parser.cpp | 5 ++++- 4 files changed, 20 insertions(+), 7 deletions(-) (limited to 'src') 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 { str_list temp; info->pushScope(); for (auto content : contents.objects()) { - if (ast_is(content)) { - temp.emplace_back(info->ind() + content->to_string(ud)); - } else { - temp.emplace_back(content->to_string(ud)); + switch (content->get_id()) { + case id(): + case id(): + temp.emplace_back(info->ind() + content->to_string(ud)); + break; + case id(): + temp.emplace_back(""s); + break; + default: + temp.emplace_back(content->to_string(ud)); + break; } } 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) AST_NODE(ClassBlock) ast_ptr sep; - ast_sel_list contents; + ast_sel_list contents; AST_MEMBER(ClassBlock, &sep, &contents) AST_END(ClassBlock) 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: } break; } - case id(): break; + case id(): + case id(): + case id(): + break; default: YUEE("AST node mismatch", content); break; } } 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() { (+space_break >> advance_match >> space >> ensure(key_value_list >> -(space >> ',') >> *(+space_break >> key_value_line), pop_indent)))); ClassMemberList = Seperator >> key_value >> *(space >> ',' >> space >> key_value); - class_line = check_indent_match >> space >> (ClassMemberList | Statement) >> -(space >> ','); + class_line = + (EmptyLine >> YueComment) | + YueComment | + check_indent_match >> space >> (ClassMemberList | Statement) >> -(space >> ','); ClassBlock = +space_break >> advance_match >> Seperator >> -- cgit v1.2.3-55-g6feb