Correct consume comment groups in both parsers

This commit is contained in:
gingerBill
2025-07-11 18:41:40 +01:00
parent e647f560db
commit 38faec757d
2 changed files with 46 additions and 40 deletions
+6 -3
View File
@@ -348,13 +348,17 @@ consume_comment_group :: proc(p: ^Parser, n: int) -> (comments: ^ast.Comment_Gro
} }
consume_comment_groups :: proc(p: ^Parser, prev: tokenizer.Token) { consume_comment_groups :: proc(p: ^Parser, prev: tokenizer.Token) {
if p.curr_tok.kind == .Comment { if p.curr_tok.kind != .Comment {
return
}
comment: ^ast.Comment_Group comment: ^ast.Comment_Group
end_line := 0 end_line := 0
if p.curr_tok.pos.line == prev.pos.line { if p.curr_tok.pos.line == prev.pos.line {
comment, end_line = consume_comment_group(p, 0) comment, end_line = consume_comment_group(p, 0)
if p.curr_tok.pos.line != end_line || p.curr_tok.kind == .EOF { if p.curr_tok.pos.line != end_line ||
p.curr_tok.pos.line == prev.pos.line+1 ||
p.curr_tok.kind == .EOF {
p.line_comment = comment p.line_comment = comment
} }
} }
@@ -369,7 +373,6 @@ consume_comment_groups :: proc(p: ^Parser, prev: tokenizer.Token) {
assert(p.curr_tok.kind != .Comment) assert(p.curr_tok.kind != .Comment)
} }
}
advance_token :: proc(p: ^Parser) -> tokenizer.Token { advance_token :: proc(p: ^Parser) -> tokenizer.Token {
p.lead_comment = nil p.lead_comment = nil
+6 -3
View File
@@ -1436,13 +1436,17 @@ gb_internal CommentGroup *consume_comment_group(AstFile *f, isize n, isize *end_
} }
gb_internal void consume_comment_groups(AstFile *f, Token prev) { gb_internal void consume_comment_groups(AstFile *f, Token prev) {
if (f->curr_token.kind == Token_Comment) { if (f->curr_token.kind != Token_Comment) {
return;
}
CommentGroup *comment = nullptr; CommentGroup *comment = nullptr;
isize end_line = 0; isize end_line = 0;
if (f->curr_token.pos.line == prev.pos.line) { if (f->curr_token.pos.line == prev.pos.line) {
comment = consume_comment_group(f, 0, &end_line); comment = consume_comment_group(f, 0, &end_line);
if (f->curr_token.pos.line != end_line || f->curr_token.kind == Token_EOF) { if (f->curr_token.pos.line != end_line ||
f->curr_token.pos.line == prev.pos.line+1 ||
f->curr_token.kind == Token_EOF) {
f->line_comment = comment; f->line_comment = comment;
} }
} }
@@ -1457,7 +1461,6 @@ gb_internal void consume_comment_groups(AstFile *f, Token prev) {
GB_ASSERT(f->curr_token.kind != Token_Comment); GB_ASSERT(f->curr_token.kind != Token_Comment);
} }
}
gb_internal gb_inline bool ignore_newlines(AstFile *f) { gb_internal gb_inline bool ignore_newlines(AstFile *f) {
return f->expr_level > 0; return f->expr_level > 0;