diff options
Diffstat (limited to 'crates/ra_syntax/src/parsing')
-rw-r--r-- | crates/ra_syntax/src/parsing/builder.rs | 19 | ||||
-rw-r--r-- | crates/ra_syntax/src/parsing/event.rs | 11 | ||||
-rw-r--r-- | crates/ra_syntax/src/parsing/parser.rs | 3 | ||||
-rw-r--r-- | crates/ra_syntax/src/parsing/reparsing.rs | 2 |
4 files changed, 17 insertions, 18 deletions
diff --git a/crates/ra_syntax/src/parsing/builder.rs b/crates/ra_syntax/src/parsing/builder.rs index a05e7f84b..ee0e2cce7 100644 --- a/crates/ra_syntax/src/parsing/builder.rs +++ b/crates/ra_syntax/src/parsing/builder.rs | |||
@@ -1,19 +1,24 @@ | |||
1 | use crate::{ | 1 | use crate::{ |
2 | parsing::TreeSink, | 2 | SmolStr, SyntaxKind, SyntaxError, SyntaxErrorKind, TextUnit, |
3 | parsing::{TreeSink, ParseError}, | ||
3 | syntax_node::{GreenNode, RaTypes}, | 4 | syntax_node::{GreenNode, RaTypes}, |
4 | SmolStr, SyntaxKind, SyntaxError, | ||
5 | }; | 5 | }; |
6 | 6 | ||
7 | use rowan::GreenNodeBuilder; | 7 | use rowan::GreenNodeBuilder; |
8 | 8 | ||
9 | pub(crate) struct GreenBuilder { | 9 | pub(crate) struct GreenBuilder { |
10 | text_pos: TextUnit, | ||
10 | errors: Vec<SyntaxError>, | 11 | errors: Vec<SyntaxError>, |
11 | inner: GreenNodeBuilder<RaTypes>, | 12 | inner: GreenNodeBuilder<RaTypes>, |
12 | } | 13 | } |
13 | 14 | ||
14 | impl GreenBuilder { | 15 | impl Default for GreenBuilder { |
15 | pub(crate) fn new() -> GreenBuilder { | 16 | fn default() -> GreenBuilder { |
16 | GreenBuilder { errors: Vec::new(), inner: GreenNodeBuilder::new() } | 17 | GreenBuilder { |
18 | text_pos: TextUnit::default(), | ||
19 | errors: Vec::new(), | ||
20 | inner: GreenNodeBuilder::new(), | ||
21 | } | ||
17 | } | 22 | } |
18 | } | 23 | } |
19 | 24 | ||
@@ -21,6 +26,7 @@ impl TreeSink for GreenBuilder { | |||
21 | type Tree = (GreenNode, Vec<SyntaxError>); | 26 | type Tree = (GreenNode, Vec<SyntaxError>); |
22 | 27 | ||
23 | fn leaf(&mut self, kind: SyntaxKind, text: SmolStr) { | 28 | fn leaf(&mut self, kind: SyntaxKind, text: SmolStr) { |
29 | self.text_pos += TextUnit::of_str(text.as_str()); | ||
24 | self.inner.leaf(kind, text); | 30 | self.inner.leaf(kind, text); |
25 | } | 31 | } |
26 | 32 | ||
@@ -32,7 +38,8 @@ impl TreeSink for GreenBuilder { | |||
32 | self.inner.finish_internal(); | 38 | self.inner.finish_internal(); |
33 | } | 39 | } |
34 | 40 | ||
35 | fn error(&mut self, error: SyntaxError) { | 41 | fn error(&mut self, error: ParseError) { |
42 | let error = SyntaxError::new(SyntaxErrorKind::ParseError(error), self.text_pos); | ||
36 | self.errors.push(error) | 43 | self.errors.push(error) |
37 | } | 44 | } |
38 | 45 | ||
diff --git a/crates/ra_syntax/src/parsing/event.rs b/crates/ra_syntax/src/parsing/event.rs index 893a42e9a..f6f020eab 100644 --- a/crates/ra_syntax/src/parsing/event.rs +++ b/crates/ra_syntax/src/parsing/event.rs | |||
@@ -13,14 +13,9 @@ use crate::{ | |||
13 | SmolStr, | 13 | SmolStr, |
14 | SyntaxKind::{self, *}, | 14 | SyntaxKind::{self, *}, |
15 | TextRange, TextUnit, | 15 | TextRange, TextUnit, |
16 | syntax_error::{ | ||
17 | ParseError, | ||
18 | SyntaxError, | ||
19 | SyntaxErrorKind, | ||
20 | }, | ||
21 | parsing::{ | 16 | parsing::{ |
17 | ParseError, TreeSink, | ||
22 | lexer::Token, | 18 | lexer::Token, |
23 | TreeSink, | ||
24 | }, | 19 | }, |
25 | }; | 20 | }; |
26 | 21 | ||
@@ -159,9 +154,7 @@ impl<'a, S: TreeSink> EventProcessor<'a, S> { | |||
159 | .sum::<TextUnit>(); | 154 | .sum::<TextUnit>(); |
160 | self.leaf(kind, len, n_raw_tokens); | 155 | self.leaf(kind, len, n_raw_tokens); |
161 | } | 156 | } |
162 | Event::Error { msg } => self | 157 | Event::Error { msg } => self.sink.error(msg), |
163 | .sink | ||
164 | .error(SyntaxError::new(SyntaxErrorKind::ParseError(msg), self.text_pos)), | ||
165 | } | 158 | } |
166 | } | 159 | } |
167 | self.sink | 160 | self.sink |
diff --git a/crates/ra_syntax/src/parsing/parser.rs b/crates/ra_syntax/src/parsing/parser.rs index 988fcb518..923b0f2b2 100644 --- a/crates/ra_syntax/src/parsing/parser.rs +++ b/crates/ra_syntax/src/parsing/parser.rs | |||
@@ -3,10 +3,9 @@ use std::cell::Cell; | |||
3 | use drop_bomb::DropBomb; | 3 | use drop_bomb::DropBomb; |
4 | 4 | ||
5 | use crate::{ | 5 | use crate::{ |
6 | syntax_error::ParseError, | ||
7 | SyntaxKind::{self, ERROR, EOF, TOMBSTONE}, | 6 | SyntaxKind::{self, ERROR, EOF, TOMBSTONE}, |
8 | parsing::{ | 7 | parsing::{ |
9 | TokenSource, | 8 | TokenSource, ParseError, |
10 | token_set::TokenSet, | 9 | token_set::TokenSet, |
11 | event::Event, | 10 | event::Event, |
12 | }, | 11 | }, |
diff --git a/crates/ra_syntax/src/parsing/reparsing.rs b/crates/ra_syntax/src/parsing/reparsing.rs index 674b15f9a..f2d218ab9 100644 --- a/crates/ra_syntax/src/parsing/reparsing.rs +++ b/crates/ra_syntax/src/parsing/reparsing.rs | |||
@@ -61,7 +61,7 @@ fn reparse_block<'node>( | |||
61 | if !is_balanced(&tokens) { | 61 | if !is_balanced(&tokens) { |
62 | return None; | 62 | return None; |
63 | } | 63 | } |
64 | let (green, new_errors) = parse_with(GreenBuilder::new(), &text, &tokens, reparser); | 64 | let (green, new_errors) = parse_with(GreenBuilder::default(), &text, &tokens, reparser); |
65 | Some((node, green, new_errors)) | 65 | Some((node, green, new_errors)) |
66 | } | 66 | } |
67 | 67 | ||