mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 05:23:24 +00:00
Minor, cleanup style
This commit is contained in:
parent
1faa9559fe
commit
6725dcf847
1 changed files with 63 additions and 49 deletions
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
|
|
||||||
use rustc_lexer::{LiteralKind as LK, RawStrError};
|
use rustc_lexer::RawStrError;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
SyntaxError,
|
SyntaxError,
|
||||||
|
@ -185,63 +185,77 @@ fn rustc_token_kind_to_syntax_kind(
|
||||||
return (syntax_kind, None);
|
return (syntax_kind, None);
|
||||||
|
|
||||||
fn match_literal_kind(kind: &rustc_lexer::LiteralKind) -> (SyntaxKind, Option<&'static str>) {
|
fn match_literal_kind(kind: &rustc_lexer::LiteralKind) -> (SyntaxKind, Option<&'static str>) {
|
||||||
#[rustfmt::skip]
|
let mut err = "";
|
||||||
let syntax_kind = match *kind {
|
let syntax_kind = match *kind {
|
||||||
LK::Int { empty_int: false, .. } => INT_NUMBER,
|
rustc_lexer::LiteralKind::Int { empty_int, base: _ } => {
|
||||||
LK::Int { empty_int: true, .. } => {
|
if empty_int {
|
||||||
return (INT_NUMBER, Some("Missing digits after the integer base prefix"))
|
err = "Missing digits after the integer base prefix";
|
||||||
}
|
}
|
||||||
|
INT_NUMBER
|
||||||
LK::Float { empty_exponent: false, .. } => FLOAT_NUMBER,
|
|
||||||
LK::Float { empty_exponent: true, .. } => {
|
|
||||||
return (FLOAT_NUMBER, Some("Missing digits after the exponent symbol"))
|
|
||||||
}
|
}
|
||||||
|
rustc_lexer::LiteralKind::Float { empty_exponent, base: _ } => {
|
||||||
LK::Char { terminated: true } => CHAR,
|
if empty_exponent {
|
||||||
LK::Char { terminated: false } => {
|
err = "Missing digits after the exponent symbol";
|
||||||
return (CHAR, Some("Missing trailing `'` symbol to terminate the character literal"))
|
|
||||||
}
|
}
|
||||||
|
FLOAT_NUMBER
|
||||||
LK::Byte { terminated: true } => BYTE,
|
|
||||||
LK::Byte { terminated: false } => {
|
|
||||||
return (BYTE, Some("Missing trailing `'` symbol to terminate the byte literal"))
|
|
||||||
}
|
}
|
||||||
|
rustc_lexer::LiteralKind::Char { terminated } => {
|
||||||
LK::Str { terminated: true } => STRING,
|
if !terminated {
|
||||||
LK::Str { terminated: false } => {
|
err = "Missing trailing `'` symbol to terminate the character literal";
|
||||||
return (STRING, Some("Missing trailing `\"` symbol to terminate the string literal"))
|
|
||||||
}
|
}
|
||||||
|
CHAR
|
||||||
|
|
||||||
LK::ByteStr { terminated: true } => BYTE_STRING,
|
|
||||||
LK::ByteStr { terminated: false } => {
|
|
||||||
return (BYTE_STRING, Some("Missing trailing `\"` symbol to terminate the byte string literal"))
|
|
||||||
}
|
}
|
||||||
|
rustc_lexer::LiteralKind::Byte { terminated } => {
|
||||||
LK::RawStr { err, .. } => match err {
|
if !terminated {
|
||||||
None => RAW_STRING,
|
err = "Missing trailing `'` symbol to terminate the byte literal";
|
||||||
Some(RawStrError::InvalidStarter { .. }) => return (RAW_STRING, Some("Missing `\"` symbol after `#` symbols to begin the raw string literal")),
|
}
|
||||||
Some(RawStrError::NoTerminator { expected, found, .. }) => if expected == found {
|
BYTE
|
||||||
return (RAW_STRING, Some("Missing trailing `\"` to terminate the raw string literal"))
|
}
|
||||||
|
rustc_lexer::LiteralKind::Str { terminated } => {
|
||||||
|
if !terminated {
|
||||||
|
err = "Missing trailing `\"` symbol to terminate the string literal";
|
||||||
|
}
|
||||||
|
STRING
|
||||||
|
}
|
||||||
|
rustc_lexer::LiteralKind::ByteStr { terminated } => {
|
||||||
|
if !terminated {
|
||||||
|
err = "Missing trailing `\"` symbol to terminate the byte string literal";
|
||||||
|
}
|
||||||
|
BYTE_STRING
|
||||||
|
}
|
||||||
|
rustc_lexer::LiteralKind::RawStr { err: raw_str_err, .. } => {
|
||||||
|
if let Some(raw_str_err) = raw_str_err {
|
||||||
|
err = match raw_str_err {
|
||||||
|
RawStrError::InvalidStarter { .. } => "Missing `\"` symbol after `#` symbols to begin the raw string literal",
|
||||||
|
RawStrError::NoTerminator { expected, found, .. } => if expected == found {
|
||||||
|
"Missing trailing `\"` to terminate the raw string literal"
|
||||||
} else {
|
} else {
|
||||||
return (RAW_STRING, Some("Missing trailing `\"` with `#` symbols to terminate the raw string literal"))
|
"Missing trailing `\"` with `#` symbols to terminate the raw string literal"
|
||||||
|
|
||||||
},
|
},
|
||||||
Some(RawStrError::TooManyDelimiters { .. }) => return (RAW_STRING, Some("Too many `#` symbols: raw strings may be delimited by up to 65535 `#` symbols")),
|
RawStrError::TooManyDelimiters { .. } => "Too many `#` symbols: raw strings may be delimited by up to 65535 `#` symbols",
|
||||||
},
|
};
|
||||||
LK::RawByteStr { err, .. } => match err {
|
};
|
||||||
None => RAW_BYTE_STRING,
|
RAW_STRING
|
||||||
Some(RawStrError::InvalidStarter { .. }) => return (RAW_BYTE_STRING, Some("Missing `\"` symbol after `#` symbols to begin the raw byte string literal")),
|
}
|
||||||
Some(RawStrError::NoTerminator { expected, found, .. }) => if expected == found {
|
rustc_lexer::LiteralKind::RawByteStr { err: raw_str_err, .. } => {
|
||||||
return (RAW_BYTE_STRING, Some("Missing trailing `\"` to terminate the raw byte string literal"))
|
if let Some(raw_str_err) = raw_str_err {
|
||||||
|
err = match raw_str_err {
|
||||||
|
RawStrError::InvalidStarter { .. } => "Missing `\"` symbol after `#` symbols to begin the raw byte string literal",
|
||||||
|
RawStrError::NoTerminator { expected, found, .. } => if expected == found {
|
||||||
|
"Missing trailing `\"` to terminate the raw byte string literal"
|
||||||
} else {
|
} else {
|
||||||
return (RAW_BYTE_STRING, Some("Missing trailing `\"` with `#` symbols to terminate the raw byte string literal"))
|
"Missing trailing `\"` with `#` symbols to terminate the raw byte string literal"
|
||||||
|
|
||||||
},
|
|
||||||
Some(RawStrError::TooManyDelimiters { .. }) => return (RAW_BYTE_STRING, Some("Too many `#` symbols: raw byte strings may be delimited by up to 65535 `#` symbols")),
|
|
||||||
},
|
},
|
||||||
|
RawStrError::TooManyDelimiters { .. } => "Too many `#` symbols: raw byte strings may be delimited by up to 65535 `#` symbols",
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
(syntax_kind, None)
|
RAW_BYTE_STRING
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let err = if err.is_empty() { None } else { Some(err) };
|
||||||
|
|
||||||
|
(syntax_kind, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue