mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-25 20:43:21 +00:00
Lexer: comments groundwork
This commit is contained in:
parent
9ccf339c17
commit
cb6f076184
4 changed files with 39 additions and 6 deletions
|
@ -48,5 +48,8 @@ Grammar(
|
||||||
"AMPERSAND",
|
"AMPERSAND",
|
||||||
"PIPE",
|
"PIPE",
|
||||||
"THIN_ARROW",
|
"THIN_ARROW",
|
||||||
|
"COMMENT",
|
||||||
|
"DOC_COMMENT",
|
||||||
|
"SHEBANG",
|
||||||
]
|
]
|
||||||
)
|
)
|
11
src/lexer/comments.rs
Normal file
11
src/lexer/comments.rs
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
use lexer::ptr::Ptr;
|
||||||
|
|
||||||
|
use {SyntaxKind};
|
||||||
|
|
||||||
|
pub(crate) fn scan_shebang(ptr: &mut Ptr) -> bool {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn scan_comment(ptr: &mut Ptr) -> Option<SyntaxKind> {
|
||||||
|
None
|
||||||
|
}
|
|
@ -13,6 +13,9 @@ use self::numbers::scan_number;
|
||||||
mod strings;
|
mod strings;
|
||||||
use self::strings::{is_string_literal_start, scan_char, scan_byte_char_or_string, scan_string, scan_raw_string};
|
use self::strings::{is_string_literal_start, scan_char, scan_byte_char_or_string, scan_string, scan_raw_string};
|
||||||
|
|
||||||
|
mod comments;
|
||||||
|
use self::comments::{scan_shebang, scan_comment};
|
||||||
|
|
||||||
pub fn next_token(text: &str) -> Token {
|
pub fn next_token(text: &str) -> Token {
|
||||||
assert!(!text.is_empty());
|
assert!(!text.is_empty());
|
||||||
let mut ptr = Ptr::new(text);
|
let mut ptr = Ptr::new(text);
|
||||||
|
@ -23,16 +26,26 @@ pub fn next_token(text: &str) -> Token {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn next_token_inner(c: char, ptr: &mut Ptr) -> SyntaxKind {
|
fn next_token_inner(c: char, ptr: &mut Ptr) -> SyntaxKind {
|
||||||
let ident_start = is_ident_start(c) && !is_string_literal_start(c, ptr.next(), ptr.nnext());
|
|
||||||
if ident_start {
|
|
||||||
return scan_ident(c, ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
if is_whitespace(c) {
|
if is_whitespace(c) {
|
||||||
ptr.bump_while(is_whitespace);
|
ptr.bump_while(is_whitespace);
|
||||||
return WHITESPACE;
|
return WHITESPACE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
match c {
|
||||||
|
'#' => if scan_shebang(ptr) {
|
||||||
|
return SHEBANG;
|
||||||
|
}
|
||||||
|
'/' => if let Some(kind) = scan_comment(ptr) {
|
||||||
|
return kind;
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
|
||||||
|
let ident_start = is_ident_start(c) && !is_string_literal_start(c, ptr.next(), ptr.nnext());
|
||||||
|
if ident_start {
|
||||||
|
return scan_ident(c, ptr);
|
||||||
|
}
|
||||||
|
|
||||||
if is_dec_digit(c) {
|
if is_dec_digit(c) {
|
||||||
let kind = scan_number(c, ptr);
|
let kind = scan_number(c, ptr);
|
||||||
scan_literal_suffix(ptr);
|
scan_literal_suffix(ptr);
|
||||||
|
|
|
@ -49,8 +49,11 @@ pub const PERCENT: SyntaxKind = SyntaxKind(44);
|
||||||
pub const AMPERSAND: SyntaxKind = SyntaxKind(45);
|
pub const AMPERSAND: SyntaxKind = SyntaxKind(45);
|
||||||
pub const PIPE: SyntaxKind = SyntaxKind(46);
|
pub const PIPE: SyntaxKind = SyntaxKind(46);
|
||||||
pub const THIN_ARROW: SyntaxKind = SyntaxKind(47);
|
pub const THIN_ARROW: SyntaxKind = SyntaxKind(47);
|
||||||
|
pub const COMMENT: SyntaxKind = SyntaxKind(48);
|
||||||
|
pub const DOC_COMMENT: SyntaxKind = SyntaxKind(49);
|
||||||
|
pub const SHEBANG: SyntaxKind = SyntaxKind(50);
|
||||||
|
|
||||||
static INFOS: [SyntaxInfo; 48] = [
|
static INFOS: [SyntaxInfo; 51] = [
|
||||||
SyntaxInfo { name: "ERROR" },
|
SyntaxInfo { name: "ERROR" },
|
||||||
SyntaxInfo { name: "IDENT" },
|
SyntaxInfo { name: "IDENT" },
|
||||||
SyntaxInfo { name: "UNDERSCORE" },
|
SyntaxInfo { name: "UNDERSCORE" },
|
||||||
|
@ -99,6 +102,9 @@ static INFOS: [SyntaxInfo; 48] = [
|
||||||
SyntaxInfo { name: "AMPERSAND" },
|
SyntaxInfo { name: "AMPERSAND" },
|
||||||
SyntaxInfo { name: "PIPE" },
|
SyntaxInfo { name: "PIPE" },
|
||||||
SyntaxInfo { name: "THIN_ARROW" },
|
SyntaxInfo { name: "THIN_ARROW" },
|
||||||
|
SyntaxInfo { name: "COMMENT" },
|
||||||
|
SyntaxInfo { name: "DOC_COMMENT" },
|
||||||
|
SyntaxInfo { name: "SHEBANG" },
|
||||||
];
|
];
|
||||||
|
|
||||||
pub(crate) fn syntax_info(kind: SyntaxKind) -> &'static SyntaxInfo {
|
pub(crate) fn syntax_info(kind: SyntaxKind) -> &'static SyntaxInfo {
|
||||||
|
|
Loading…
Reference in a new issue