mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 21:05:02 +00:00
switch to upstream unescape
This commit is contained in:
parent
c79eea9fc1
commit
2473cb6a5c
4 changed files with 91 additions and 529 deletions
|
@ -1,16 +1,99 @@
|
|||
mod unescape;
|
||||
|
||||
mod block;
|
||||
mod field_expr;
|
||||
|
||||
use ra_rustc_lexer::unescape;
|
||||
|
||||
use crate::{
|
||||
algo::visit::{visitor_ctx, VisitorCtx},
|
||||
ast, SyntaxError,
|
||||
ast, SyntaxError, SyntaxErrorKind,
|
||||
SyntaxKind::{BYTE, BYTE_STRING, CHAR, STRING},
|
||||
SyntaxNode, TextUnit, T,
|
||||
};
|
||||
|
||||
pub(crate) use unescape::EscapeError;
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub enum EscapeError {
|
||||
ZeroChars,
|
||||
MoreThanOneChar,
|
||||
LoneSlash,
|
||||
InvalidEscape,
|
||||
BareCarriageReturn,
|
||||
EscapeOnlyChar,
|
||||
TooShortHexEscape,
|
||||
InvalidCharInHexEscape,
|
||||
OutOfRangeHexEscape,
|
||||
NoBraceInUnicodeEscape,
|
||||
InvalidCharInUnicodeEscape,
|
||||
EmptyUnicodeEscape,
|
||||
UnclosedUnicodeEscape,
|
||||
LeadingUnderscoreUnicodeEscape,
|
||||
OverlongUnicodeEscape,
|
||||
LoneSurrogateUnicodeEscape,
|
||||
OutOfRangeUnicodeEscape,
|
||||
UnicodeEscapeInByte,
|
||||
NonAsciiCharInByte,
|
||||
}
|
||||
|
||||
impl From<ra_rustc_lexer::unescape::EscapeError> for EscapeError {
|
||||
fn from(err: ra_rustc_lexer::unescape::EscapeError) -> Self {
|
||||
match err {
|
||||
ra_rustc_lexer::unescape::EscapeError::ZeroChars => EscapeError::ZeroChars,
|
||||
ra_rustc_lexer::unescape::EscapeError::MoreThanOneChar => EscapeError::MoreThanOneChar,
|
||||
ra_rustc_lexer::unescape::EscapeError::LoneSlash => EscapeError::LoneSlash,
|
||||
ra_rustc_lexer::unescape::EscapeError::InvalidEscape => EscapeError::InvalidEscape,
|
||||
ra_rustc_lexer::unescape::EscapeError::BareCarriageReturn
|
||||
| ra_rustc_lexer::unescape::EscapeError::BareCarriageReturnInRawString => {
|
||||
EscapeError::BareCarriageReturn
|
||||
}
|
||||
ra_rustc_lexer::unescape::EscapeError::EscapeOnlyChar => EscapeError::EscapeOnlyChar,
|
||||
ra_rustc_lexer::unescape::EscapeError::TooShortHexEscape => {
|
||||
EscapeError::TooShortHexEscape
|
||||
}
|
||||
ra_rustc_lexer::unescape::EscapeError::InvalidCharInHexEscape => {
|
||||
EscapeError::InvalidCharInHexEscape
|
||||
}
|
||||
ra_rustc_lexer::unescape::EscapeError::OutOfRangeHexEscape => {
|
||||
EscapeError::OutOfRangeHexEscape
|
||||
}
|
||||
ra_rustc_lexer::unescape::EscapeError::NoBraceInUnicodeEscape => {
|
||||
EscapeError::NoBraceInUnicodeEscape
|
||||
}
|
||||
ra_rustc_lexer::unescape::EscapeError::InvalidCharInUnicodeEscape => {
|
||||
EscapeError::InvalidCharInUnicodeEscape
|
||||
}
|
||||
ra_rustc_lexer::unescape::EscapeError::EmptyUnicodeEscape => {
|
||||
EscapeError::EmptyUnicodeEscape
|
||||
}
|
||||
ra_rustc_lexer::unescape::EscapeError::UnclosedUnicodeEscape => {
|
||||
EscapeError::UnclosedUnicodeEscape
|
||||
}
|
||||
ra_rustc_lexer::unescape::EscapeError::LeadingUnderscoreUnicodeEscape => {
|
||||
EscapeError::LeadingUnderscoreUnicodeEscape
|
||||
}
|
||||
ra_rustc_lexer::unescape::EscapeError::OverlongUnicodeEscape => {
|
||||
EscapeError::OverlongUnicodeEscape
|
||||
}
|
||||
ra_rustc_lexer::unescape::EscapeError::LoneSurrogateUnicodeEscape => {
|
||||
EscapeError::LoneSurrogateUnicodeEscape
|
||||
}
|
||||
ra_rustc_lexer::unescape::EscapeError::OutOfRangeUnicodeEscape => {
|
||||
EscapeError::OutOfRangeUnicodeEscape
|
||||
}
|
||||
ra_rustc_lexer::unescape::EscapeError::UnicodeEscapeInByte => {
|
||||
EscapeError::UnicodeEscapeInByte
|
||||
}
|
||||
ra_rustc_lexer::unescape::EscapeError::NonAsciiCharInByte
|
||||
| ra_rustc_lexer::unescape::EscapeError::NonAsciiCharInByteString => {
|
||||
EscapeError::NonAsciiCharInByte
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ra_rustc_lexer::unescape::EscapeError> for SyntaxErrorKind {
|
||||
fn from(err: ra_rustc_lexer::unescape::EscapeError) -> Self {
|
||||
SyntaxErrorKind::EscapeError(err.into())
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn validate(root: &SyntaxNode) -> Vec<SyntaxError> {
|
||||
let mut errors = Vec::new();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue