Block Comments

closes #7
This commit is contained in:
Christopher Durham 2018-01-28 05:08:25 -05:00
parent eafb9c3ab4
commit f4f79038d1
3 changed files with 35 additions and 1 deletions

View file

@ -14,12 +14,35 @@ pub(crate) fn scan_shebang(ptr: &mut Ptr) -> bool {
} }
} }
pub(crate) 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> { pub(crate) fn scan_comment(ptr: &mut Ptr) -> Option<SyntaxKind> {
if ptr.next_is('/') { if ptr.next_is('/') {
bump_until_eol(ptr); bump_until_eol(ptr);
Some(COMMENT) Some(COMMENT)
} else { } 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"