Skip to content

Commit 7a6fa65

Browse files
committed
Merge #24
24: Block Comments r=matklad a=CAD97 closes #7
2 parents 37ee4c4 + 5982e6d commit 7a6fa65

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

src/lexer/comments.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,35 @@ pub(crate) fn scan_shebang(ptr: &mut Ptr) -> bool {
1414
}
1515
}
1616

17+
fn scan_block_comment(ptr: &mut Ptr) -> Option<SyntaxKind> {
18+
if ptr.next_is('*') {
19+
ptr.bump();
20+
let mut depth: u32 = 1;
21+
while depth > 0 {
22+
if ptr.next_is('*') && ptr.nnext_is('/') {
23+
depth -= 1;
24+
ptr.bump();
25+
ptr.bump();
26+
} else if ptr.next_is('/') && ptr.nnext_is('*') {
27+
depth += 1;
28+
ptr.bump();
29+
ptr.bump();
30+
} else if ptr.bump().is_none() {
31+
break;
32+
}
33+
}
34+
Some(COMMENT)
35+
} else {
36+
None
37+
}
38+
}
39+
1740
pub(crate) fn scan_comment(ptr: &mut Ptr) -> Option<SyntaxKind> {
1841
if ptr.next_is('/') {
1942
bump_until_eol(ptr);
2043
Some(COMMENT)
2144
} else {
22-
None
45+
scan_block_comment(ptr)
2346
}
2447
}
2548

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/* */
2+
/**/
3+
/* /* */ */
4+
/*
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
COMMENT 5 "/* */"
2+
WHITESPACE 1 "\n"
3+
COMMENT 4 "/**/"
4+
WHITESPACE 1 "\n"
5+
COMMENT 11 "/* /* */ */"
6+
WHITESPACE 1 "\n"
7+
COMMENT 3 "/*\n"

0 commit comments

Comments
 (0)