diff options
Diffstat (limited to 'crates/ra_syntax/src/yellow/syntax_error.rs')
-rw-r--r-- | crates/ra_syntax/src/yellow/syntax_error.rs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/crates/ra_syntax/src/yellow/syntax_error.rs b/crates/ra_syntax/src/yellow/syntax_error.rs new file mode 100644 index 000000000..e8c818dc6 --- /dev/null +++ b/crates/ra_syntax/src/yellow/syntax_error.rs | |||
@@ -0,0 +1,42 @@ | |||
1 | use std::fmt; | ||
2 | |||
3 | use crate::TextRange; | ||
4 | |||
5 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
6 | pub struct SyntaxError { | ||
7 | pub kind: SyntaxErrorKind, | ||
8 | pub range: TextRange, | ||
9 | } | ||
10 | |||
11 | impl SyntaxError { | ||
12 | pub fn new(kind: SyntaxErrorKind, range: TextRange) -> SyntaxError { | ||
13 | SyntaxError { kind, range } | ||
14 | } | ||
15 | } | ||
16 | |||
17 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
18 | pub enum SyntaxErrorKind { | ||
19 | ParseError(ParseError), | ||
20 | EmptyChar, | ||
21 | UnclosedChar, | ||
22 | LongChar, | ||
23 | EmptyAsciiEscape, | ||
24 | InvalidAsciiEscape, | ||
25 | } | ||
26 | |||
27 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
28 | pub struct ParseError(pub String); | ||
29 | |||
30 | impl fmt::Display for SyntaxErrorKind { | ||
31 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
32 | use self::SyntaxErrorKind::*; | ||
33 | match self { | ||
34 | EmptyAsciiEscape => write!(f, "Empty escape sequence"), | ||
35 | InvalidAsciiEscape => write!(f, "Invalid escape sequence"), | ||
36 | EmptyChar => write!(f, "Empty char literal"), | ||
37 | UnclosedChar => write!(f, "Unclosed char literal"), | ||
38 | LongChar => write!(f, "Char literal should be one character long"), | ||
39 | ParseError(msg) => write!(f, "{}", msg.0), | ||
40 | } | ||
41 | } | ||
42 | } | ||