diff options
author | Aleksey Kladov <[email protected]> | 2019-02-20 20:17:07 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-02-20 20:17:07 +0000 |
commit | 882c47f1870f15cb2aaad8871ccbad1c51520f49 (patch) | |
tree | e47aa900bcffffded370b68b2e50604199b491e3 /crates/ra_syntax/src/parsing/builder.rs | |
parent | 61992dc1cd4956038e3c15439c1203f21e05af06 (diff) |
move syntax error to parser
Diffstat (limited to 'crates/ra_syntax/src/parsing/builder.rs')
-rw-r--r-- | crates/ra_syntax/src/parsing/builder.rs | 19 |
1 files changed, 13 insertions, 6 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 | ||