Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion src/lexer/comments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,35 @@ pub(crate) fn scan_shebang(ptr: &mut Ptr) -> bool {
}
}

fn scan_block_comment(ptr: &mut Ptr) -> Option<SyntaxKind> {
if ptr.next_is('*') {
ptr.bump();
let mut depth: u32 = 1;
while depth > 0 {
if ptr.next_is('*') && ptr.nnext_is('/') {
depth -= 1;
ptr.bump();
ptr.bump();
} else if ptr.next_is('/') && ptr.nnext_is('*') {
depth += 1;
ptr.bump();
ptr.bump();
} else if ptr.bump().is_none() {
break;
}
}
Some(COMMENT)
} else {
None
}
}

pub(crate) fn scan_comment(ptr: &mut Ptr) -> Option<SyntaxKind> {
if ptr.next_is('/') {
bump_until_eol(ptr);
Some(COMMENT)
} else {
None
scan_block_comment(ptr)
}
}

Expand Down
4 changes: 4 additions & 0 deletions tests/data/lexer/00012_block_comment.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* */
/**/
/* /* */ */
/*
7 changes: 7 additions & 0 deletions tests/data/lexer/00012_block_comment.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
COMMENT 5 "/* */"
WHITESPACE 1 "\n"
COMMENT 4 "/**/"
WHITESPACE 1 "\n"
COMMENT 11 "/* /* */ */"
WHITESPACE 1 "\n"
COMMENT 3 "/*\n"