mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-25 20:43:21 +00:00
Lexer: basic comments
This commit is contained in:
parent
cb6f076184
commit
98a58bf806
4 changed files with 37 additions and 2 deletions
|
@ -1,11 +1,36 @@
|
|||
use lexer::ptr::Ptr;
|
||||
|
||||
use {SyntaxKind};
|
||||
use syntax_kinds::*;
|
||||
|
||||
pub(crate) fn scan_shebang(ptr: &mut Ptr) -> bool {
|
||||
if ptr.next_is('!') && ptr.nnext_is('/') {
|
||||
ptr.bump();
|
||||
ptr.bump();
|
||||
bump_until_eol(ptr);
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn scan_comment(ptr: &mut Ptr) -> Option<SyntaxKind> {
|
||||
if ptr.next_is('/') {
|
||||
bump_until_eol(ptr);
|
||||
Some(COMMENT)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fn bump_until_eol(ptr: &mut Ptr) {
|
||||
loop {
|
||||
if ptr.next_is('\n') || ptr.next_is('\r') && ptr.nnext_is('\n') {
|
||||
return;
|
||||
}
|
||||
if ptr.bump().is_none() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
3
tests/data/lexer/0010_comments.rs
Normal file
3
tests/data/lexer/0010_comments.rs
Normal file
|
@ -0,0 +1,3 @@
|
|||
#!/usr/bin/env bash
|
||||
// hello
|
||||
//! World
|
6
tests/data/lexer/0010_comments.txt
Normal file
6
tests/data/lexer/0010_comments.txt
Normal file
|
@ -0,0 +1,6 @@
|
|||
SHEBANG 19 "#!/usr/bin/env bash"
|
||||
WHITESPACE 1 "\n"
|
||||
COMMENT 8 "// hello"
|
||||
WHITESPACE 1 "\n"
|
||||
COMMENT 9 "//! World"
|
||||
WHITESPACE 1 "\n"
|
|
@ -6,3 +6,4 @@ Fixmes:
|
|||
base, and are in range
|
||||
* Validation for unclosed char literal
|
||||
* Strings are completely wrong: more tests and comparison with libsyntax.
|
||||
* Comment lexing is completely wrong
|
||||
|
|
Loading…
Reference in a new issue