24: Block Comments r=matklad a=CAD97

closes #7
This commit is contained in:
bors[bot] 2018-01-28 10:52:49 +00:00
commit 7a6fa6504c
3 changed files with 35 additions and 1 deletions

View file

@ -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)
}
}

View file

@ -0,0 +1,4 @@
/* */
/**/
/* /* */ */
/*

View file

@ -0,0 +1,7 @@
COMMENT 5 "/* */"
WHITESPACE 1 "\n"
COMMENT 4 "/**/"
WHITESPACE 1 "\n"
COMMENT 11 "/* /* */ */"
WHITESPACE 1 "\n"
COMMENT 3 "/*\n"