mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 13:25:09 +00:00
Introduce SyntaxErrorKind and TextRange in SyntaxError
This commit is contained in:
parent
576b9a0727
commit
3b42ddae60
10 changed files with 159 additions and 68 deletions
42
crates/ra_syntax/src/yellow/syntax_error.rs
Normal file
42
crates/ra_syntax/src/yellow/syntax_error.rs
Normal file
|
@ -0,0 +1,42 @@
|
|||
use std::fmt;
|
||||
|
||||
use crate::TextRange;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct SyntaxError {
|
||||
pub kind: SyntaxErrorKind,
|
||||
pub range: TextRange,
|
||||
}
|
||||
|
||||
impl SyntaxError {
|
||||
pub fn new(kind: SyntaxErrorKind, range: TextRange) -> SyntaxError {
|
||||
SyntaxError { kind, range }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub enum SyntaxErrorKind {
|
||||
ParseError(ParseError),
|
||||
EmptyChar,
|
||||
UnclosedChar,
|
||||
LongChar,
|
||||
EmptyAsciiEscape,
|
||||
InvalidAsciiEscape,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct ParseError(pub String);
|
||||
|
||||
impl fmt::Display for SyntaxErrorKind {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
use self::SyntaxErrorKind::*;
|
||||
match self {
|
||||
EmptyAsciiEscape => write!(f, "Empty escape sequence"),
|
||||
InvalidAsciiEscape => write!(f, "Invalid escape sequence"),
|
||||
EmptyChar => write!(f, "Empty char literal"),
|
||||
UnclosedChar => write!(f, "Unclosed char literal"),
|
||||
LongChar => write!(f, "Char literal should be one character long"),
|
||||
ParseError(msg) => write!(f, "{}", msg.0),
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue