diff options
Diffstat (limited to 'crates/ra_syntax/src/yellow')
-rw-r--r-- | crates/ra_syntax/src/yellow/builder.rs | 11 | ||||
-rw-r--r-- | crates/ra_syntax/src/yellow/mod.rs | 10 | ||||
-rw-r--r-- | crates/ra_syntax/src/yellow/syntax_error.rs | 42 |
3 files changed, 49 insertions, 14 deletions
diff --git a/crates/ra_syntax/src/yellow/builder.rs b/crates/ra_syntax/src/yellow/builder.rs index d64053409..dbe2df125 100644 --- a/crates/ra_syntax/src/yellow/builder.rs +++ b/crates/ra_syntax/src/yellow/builder.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | use crate::{ | 1 | use crate::{ |
2 | parser_impl::Sink, | 2 | parser_impl::Sink, |
3 | yellow::{GreenNode, RaTypes, SyntaxError}, | 3 | yellow::{GreenNode, RaTypes, SyntaxError, SyntaxErrorKind}, |
4 | SmolStr, SyntaxKind, TextUnit, | 4 | SmolStr, SyntaxKind, TextRange, |
5 | }; | 5 | }; |
6 | use rowan::GreenNodeBuilder; | 6 | use rowan::GreenNodeBuilder; |
7 | 7 | ||
@@ -34,11 +34,8 @@ impl Sink for GreenBuilder { | |||
34 | self.inner.finish_internal(); | 34 | self.inner.finish_internal(); |
35 | } | 35 | } |
36 | 36 | ||
37 | fn error(&mut self, message: String, offset: TextUnit) { | 37 | fn error(&mut self, kind: SyntaxErrorKind, range: TextRange) { |
38 | let error = SyntaxError { | 38 | let error = SyntaxError { kind, range }; |
39 | msg: message, | ||
40 | offset, | ||
41 | }; | ||
42 | self.errors.push(error) | 39 | self.errors.push(error) |
43 | } | 40 | } |
44 | 41 | ||
diff --git a/crates/ra_syntax/src/yellow/mod.rs b/crates/ra_syntax/src/yellow/mod.rs index 650917214..fd2b5bd33 100644 --- a/crates/ra_syntax/src/yellow/mod.rs +++ b/crates/ra_syntax/src/yellow/mod.rs | |||
@@ -1,8 +1,9 @@ | |||
1 | mod builder; | 1 | mod builder; |
2 | pub mod syntax_error; | ||
2 | mod syntax_text; | 3 | mod syntax_text; |
3 | 4 | ||
4 | use self::syntax_text::SyntaxText; | 5 | use self::syntax_text::SyntaxText; |
5 | use crate::{SmolStr, SyntaxKind, TextRange, TextUnit}; | 6 | use crate::{SmolStr, SyntaxKind, TextRange}; |
6 | use rowan::Types; | 7 | use rowan::Types; |
7 | use std::{ | 8 | use std::{ |
8 | fmt, | 9 | fmt, |
@@ -10,6 +11,7 @@ use std::{ | |||
10 | }; | 11 | }; |
11 | 12 | ||
12 | pub(crate) use self::builder::GreenBuilder; | 13 | pub(crate) use self::builder::GreenBuilder; |
14 | pub use self::syntax_error::{SyntaxError, SyntaxErrorKind}; | ||
13 | pub use rowan::{TreeRoot, WalkEvent}; | 15 | pub use rowan::{TreeRoot, WalkEvent}; |
14 | 16 | ||
15 | #[derive(Debug, Clone, Copy)] | 17 | #[derive(Debug, Clone, Copy)] |
@@ -24,12 +26,6 @@ pub type RefRoot<'a> = ::rowan::RefRoot<'a, RaTypes>; | |||
24 | 26 | ||
25 | pub type GreenNode = ::rowan::GreenNode<RaTypes>; | 27 | pub type GreenNode = ::rowan::GreenNode<RaTypes>; |
26 | 28 | ||
27 | #[derive(Debug, Clone, PartialEq, Eq, Hash, Ord, PartialOrd)] | ||
28 | pub struct SyntaxError { | ||
29 | pub msg: String, | ||
30 | pub offset: TextUnit, | ||
31 | } | ||
32 | |||
33 | #[derive(Clone, Copy)] | 29 | #[derive(Clone, Copy)] |
34 | pub struct SyntaxNode<R: TreeRoot<RaTypes> = OwnedRoot>(::rowan::SyntaxNode<RaTypes, R>); | 30 | pub struct SyntaxNode<R: TreeRoot<RaTypes> = OwnedRoot>(::rowan::SyntaxNode<RaTypes, R>); |
35 | pub type SyntaxNodeRef<'a> = SyntaxNode<RefRoot<'a>>; | 31 | pub type SyntaxNodeRef<'a> = SyntaxNode<RefRoot<'a>>; |
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 | } | ||