diff options
author | Aleksey Kladov <[email protected]> | 2018-10-08 13:44:00 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-10-08 13:44:00 +0100 |
commit | 86a7ac2d31e97c42a9da8d8fd539b5a0de0fa795 (patch) | |
tree | 17d16374b28e3221cfb793340b32aabe2f4fd1dd /crates/ra_syntax/src/yellow | |
parent | 3c12d38a32f5c87e87d9dbced774453216086bab (diff) |
Simplify event processing
Diffstat (limited to 'crates/ra_syntax/src/yellow')
-rw-r--r-- | crates/ra_syntax/src/yellow/builder.rs | 32 |
1 files changed, 13 insertions, 19 deletions
diff --git a/crates/ra_syntax/src/yellow/builder.rs b/crates/ra_syntax/src/yellow/builder.rs index 35dbaec05..c307b2bd0 100644 --- a/crates/ra_syntax/src/yellow/builder.rs +++ b/crates/ra_syntax/src/yellow/builder.rs | |||
@@ -1,33 +1,29 @@ | |||
1 | use rowan::GreenNodeBuilder; | 1 | use rowan::GreenNodeBuilder; |
2 | use { | 2 | use { |
3 | TextUnit, SmolStr, | ||
3 | parser_impl::Sink, | 4 | parser_impl::Sink, |
4 | yellow::{GreenNode, SyntaxError, RaTypes}, | 5 | yellow::{GreenNode, SyntaxError, RaTypes}, |
5 | SyntaxKind, TextRange, TextUnit, | 6 | SyntaxKind, |
6 | }; | 7 | }; |
7 | 8 | ||
8 | pub(crate) struct GreenBuilder<'a> { | 9 | pub(crate) struct GreenBuilder { |
9 | text: &'a str, | ||
10 | pos: TextUnit, | ||
11 | errors: Vec<SyntaxError>, | 10 | errors: Vec<SyntaxError>, |
12 | inner: GreenNodeBuilder<RaTypes>, | 11 | inner: GreenNodeBuilder<RaTypes>, |
13 | } | 12 | } |
14 | 13 | ||
15 | impl<'a> Sink<'a> for GreenBuilder<'a> { | 14 | impl GreenBuilder { |
16 | type Tree = (GreenNode, Vec<SyntaxError>); | 15 | pub(crate) fn new() -> GreenBuilder { |
17 | |||
18 | fn new(text: &'a str) -> Self { | ||
19 | GreenBuilder { | 16 | GreenBuilder { |
20 | text, | ||
21 | pos: 0.into(), | ||
22 | errors: Vec::new(), | 17 | errors: Vec::new(), |
23 | inner: GreenNodeBuilder::new(), | 18 | inner: GreenNodeBuilder::new(), |
24 | } | 19 | } |
25 | } | 20 | } |
21 | } | ||
22 | |||
23 | impl Sink for GreenBuilder { | ||
24 | type Tree = (GreenNode, Vec<SyntaxError>); | ||
26 | 25 | ||
27 | fn leaf(&mut self, kind: SyntaxKind, len: TextUnit) { | 26 | fn leaf(&mut self, kind: SyntaxKind, text: SmolStr) { |
28 | let range = TextRange::offset_len(self.pos, len); | ||
29 | self.pos += len; | ||
30 | let text = self.text[range].into(); | ||
31 | self.inner.leaf(kind, text); | 27 | self.inner.leaf(kind, text); |
32 | } | 28 | } |
33 | 29 | ||
@@ -39,11 +35,9 @@ impl<'a> Sink<'a> for GreenBuilder<'a> { | |||
39 | self.inner.finish_internal(); | 35 | self.inner.finish_internal(); |
40 | } | 36 | } |
41 | 37 | ||
42 | fn error(&mut self, message: String) { | 38 | fn error(&mut self, message: String, offset: TextUnit) { |
43 | self.errors.push(SyntaxError { | 39 | let error = SyntaxError { msg: message, offset }; |
44 | msg: message, | 40 | self.errors.push(error) |
45 | offset: self.pos, | ||
46 | }) | ||
47 | } | 41 | } |
48 | 42 | ||
49 | fn finish(self) -> (GreenNode, Vec<SyntaxError>) { | 43 | fn finish(self) -> (GreenNode, Vec<SyntaxError>) { |