mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 21:13:37 +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
|
||||||
}
|
}
|
||||||
|
rustc_lexer::LiteralKind::Float { empty_exponent, base: _ } => {
|
||||||
LK::Float { empty_exponent: false, .. } => FLOAT_NUMBER,
|
if empty_exponent {
|
||||||
LK::Float { empty_exponent: true, .. } => {
|
err = "Missing digits after the exponent symbol";
|
||||||
return (FLOAT_NUMBER, Some("Missing digits after the exponent symbol"))
|
}
|
||||||
|
FLOAT_NUMBER
|
||||||
}
|
}
|
||||||
|
rustc_lexer::LiteralKind::Char { terminated } => {
|
||||||
LK::Char { terminated: true } => CHAR,
|
if !terminated {
|
||||||
LK::Char { terminated: false } => {
|
err = "Missing trailing `'` symbol to terminate the character literal";
|
||||||
return (CHAR, Some("Missing trailing `'` symbol to terminate the character literal"))
|
}
|
||||||
|
CHAR
|
||||||
}
|
}
|
||||||
|
rustc_lexer::LiteralKind::Byte { terminated } => {
|
||||||
LK::Byte { terminated: true } => BYTE,
|
if !terminated {
|
||||||
LK::Byte { terminated: false } => {
|
err = "Missing trailing `'` symbol to terminate the byte literal";
|
||||||
return (BYTE, Some("Missing trailing `'` symbol to terminate the byte literal"))
|
}
|
||||||
|
BYTE
|
||||||
}
|
}
|
||||||
|
rustc_lexer::LiteralKind::Str { terminated } => {
|
||||||
LK::Str { terminated: true } => STRING,
|
if !terminated {
|
||||||
LK::Str { terminated: false } => {
|
err = "Missing trailing `\"` symbol to terminate the string literal";
|
||||||
return (STRING, Some("Missing trailing `\"` symbol to terminate the string literal"))
|
}
|
||||||
|
STRING
|
||||||
}
|
}
|
||||||
|
rustc_lexer::LiteralKind::ByteStr { terminated } => {
|
||||||
|
if !terminated {
|
||||||
LK::ByteStr { terminated: true } => BYTE_STRING,
|
err = "Missing trailing `\"` symbol to terminate the byte string literal";
|
||||||
LK::ByteStr { terminated: false } => {
|
}
|
||||||
return (BYTE_STRING, Some("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 {
|
||||||
|
"Missing trailing `\"` with `#` symbols to terminate the raw string literal"
|
||||||
|
},
|
||||||
|
RawStrError::TooManyDelimiters { .. } => "Too many `#` symbols: raw strings may be delimited by up to 65535 `#` symbols",
|
||||||
|
};
|
||||||
|
};
|
||||||
|
RAW_STRING
|
||||||
|
}
|
||||||
|
rustc_lexer::LiteralKind::RawByteStr { 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 byte string literal",
|
||||||
|
RawStrError::NoTerminator { expected, found, .. } => if expected == found {
|
||||||
|
"Missing trailing `\"` to terminate the raw byte string literal"
|
||||||
|
} else {
|
||||||
|
"Missing trailing `\"` with `#` symbols to terminate the raw byte string literal"
|
||||||
|
},
|
||||||
|
RawStrError::TooManyDelimiters { .. } => "Too many `#` symbols: raw byte strings may be delimited by up to 65535 `#` symbols",
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
LK::RawStr { err, .. } => match err {
|
RAW_BYTE_STRING
|
||||||
None => RAW_STRING,
|
}
|
||||||
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 {
|
|
||||||
return (RAW_STRING, Some("Missing trailing `\"` to terminate the raw string literal"))
|
|
||||||
} else {
|
|
||||||
return (RAW_STRING, Some("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")),
|
|
||||||
},
|
|
||||||
LK::RawByteStr { err, .. } => match err {
|
|
||||||
None => RAW_BYTE_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 {
|
|
||||||
return (RAW_BYTE_STRING, Some("Missing trailing `\"` to terminate the raw byte string literal"))
|
|
||||||
} else {
|
|
||||||
return (RAW_BYTE_STRING, Some("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")),
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
(syntax_kind, None)
|
let err = if err.is_empty() { None } else { Some(err) };
|
||||||
|
|
||||||
|
(syntax_kind, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue