mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-25 12:33:33 +00:00
commit
7a6fa6504c
3 changed files with 35 additions and 1 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
4
tests/data/lexer/00012_block_comment.rs
Normal file
4
tests/data/lexer/00012_block_comment.rs
Normal file
|
@ -0,0 +1,4 @@
|
|||
/* */
|
||||
/**/
|
||||
/* /* */ */
|
||||
/*
|
7
tests/data/lexer/00012_block_comment.txt
Normal file
7
tests/data/lexer/00012_block_comment.txt
Normal file
|
@ -0,0 +1,7 @@
|
|||
COMMENT 5 "/* */"
|
||||
WHITESPACE 1 "\n"
|
||||
COMMENT 4 "/**/"
|
||||
WHITESPACE 1 "\n"
|
||||
COMMENT 11 "/* /* */ */"
|
||||
WHITESPACE 1 "\n"
|
||||
COMMENT 3 "/*\n"
|
Loading…
Reference in a new issue