diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-02-20 20:33:40 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-02-20 20:33:40 +0000 |
commit | c84561bb624280b84eb2fe6c6b2a6b9fe3f1dbf7 (patch) | |
tree | e47aa900bcffffded370b68b2e50604199b491e3 /crates/ra_syntax/src/parsing/builder.rs | |
parent | 96899f8278b787280bd07d9ac9dce29a610ce40d (diff) | |
parent | 882c47f1870f15cb2aaad8871ccbad1c51520f49 (diff) |
Merge #863
863: Token source r=matklad a=matklad
Some reshuffling of parser's API with the eye towards extracting parse **without** syntax tree into a separate crate, to be used with macro expansion
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_syntax/src/parsing/builder.rs')
-rw-r--r-- | crates/ra_syntax/src/parsing/builder.rs | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/crates/ra_syntax/src/parsing/builder.rs b/crates/ra_syntax/src/parsing/builder.rs index 9090c60c2..ee0e2cce7 100644 --- a/crates/ra_syntax/src/parsing/builder.rs +++ b/crates/ra_syntax/src/parsing/builder.rs | |||
@@ -1,26 +1,32 @@ | |||
1 | use crate::{ | 1 | use crate::{ |
2 | parsing::parser_impl::Sink, | 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 | ||
20 | impl Sink for GreenBuilder { | 25 | 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 Sink 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 | ||