mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
Change macro to function
This commit is contained in:
parent
073cf42391
commit
db4839033c
1 changed files with 13 additions and 15 deletions
|
@ -12,9 +12,8 @@ pub struct Token {
|
||||||
pub len: TextUnit,
|
pub len: TextUnit,
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! match_literal_kind {
|
fn match_literal_kind(kind: ra_rustc_lexer::LiteralKind) -> SyntaxKind {
|
||||||
($kind:expr) => {
|
match kind {
|
||||||
match $kind {
|
|
||||||
ra_rustc_lexer::LiteralKind::Int { .. } => INT_NUMBER,
|
ra_rustc_lexer::LiteralKind::Int { .. } => INT_NUMBER,
|
||||||
ra_rustc_lexer::LiteralKind::Float { .. } => FLOAT_NUMBER,
|
ra_rustc_lexer::LiteralKind::Float { .. } => FLOAT_NUMBER,
|
||||||
ra_rustc_lexer::LiteralKind::Char { .. } => CHAR,
|
ra_rustc_lexer::LiteralKind::Char { .. } => CHAR,
|
||||||
|
@ -24,7 +23,6 @@ macro_rules! match_literal_kind {
|
||||||
ra_rustc_lexer::LiteralKind::RawStr { .. } => RAW_STRING,
|
ra_rustc_lexer::LiteralKind::RawStr { .. } => RAW_STRING,
|
||||||
ra_rustc_lexer::LiteralKind::RawByteStr { .. } => RAW_BYTE_STRING,
|
ra_rustc_lexer::LiteralKind::RawByteStr { .. } => RAW_BYTE_STRING,
|
||||||
}
|
}
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Break a string up into its component tokens
|
/// Break a string up into its component tokens
|
||||||
|
@ -68,7 +66,7 @@ pub fn tokenize(text: &str) -> Vec<Token> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ra_rustc_lexer::TokenKind::RawIdent => IDENT,
|
ra_rustc_lexer::TokenKind::RawIdent => IDENT,
|
||||||
ra_rustc_lexer::TokenKind::Literal { kind, .. } => match_literal_kind!(kind),
|
ra_rustc_lexer::TokenKind::Literal { kind, .. } => match_literal_kind(kind),
|
||||||
ra_rustc_lexer::TokenKind::Lifetime { .. } => LIFETIME,
|
ra_rustc_lexer::TokenKind::Lifetime { .. } => LIFETIME,
|
||||||
ra_rustc_lexer::TokenKind::Semi => SEMI,
|
ra_rustc_lexer::TokenKind::Semi => SEMI,
|
||||||
ra_rustc_lexer::TokenKind::Comma => COMMA,
|
ra_rustc_lexer::TokenKind::Comma => COMMA,
|
||||||
|
@ -137,7 +135,7 @@ pub fn classify_literal(text: &str) -> Option<Token> {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let kind = match t.kind {
|
let kind = match t.kind {
|
||||||
ra_rustc_lexer::TokenKind::Literal { kind, .. } => match_literal_kind!(kind),
|
ra_rustc_lexer::TokenKind::Literal { kind, .. } => match_literal_kind(kind),
|
||||||
_ => return None,
|
_ => return None,
|
||||||
};
|
};
|
||||||
Some(Token { kind, len: TextUnit::from_usize(t.len) })
|
Some(Token { kind, len: TextUnit::from_usize(t.len) })
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue