aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/yellow/syntax_error.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax/src/yellow/syntax_error.rs')
-rw-r--r--crates/ra_syntax/src/yellow/syntax_error.rs42
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 @@
1use std::fmt;
2
3use crate::TextRange;
4
5#[derive(Debug, Clone, PartialEq, Eq, Hash)]
6pub struct SyntaxError {
7 pub kind: SyntaxErrorKind,
8 pub range: TextRange,
9}
10
11impl SyntaxError {
12 pub fn new(kind: SyntaxErrorKind, range: TextRange) -> SyntaxError {
13 SyntaxError { kind, range }
14 }
15}
16
17#[derive(Debug, Clone, PartialEq, Eq, Hash)]
18pub enum SyntaxErrorKind {
19 ParseError(ParseError),
20 EmptyChar,
21 UnclosedChar,
22 LongChar,
23 EmptyAsciiEscape,
24 InvalidAsciiEscape,
25}
26
27#[derive(Debug, Clone, PartialEq, Eq, Hash)]
28pub struct ParseError(pub String);
29
30impl 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}