diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-02-12 16:03:47 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-02-12 16:03:47 +0000 |
commit | afdcfb79b9697cec4812d262ffb58bffd5555761 (patch) | |
tree | 6dd13ecadd963031f447663d005da18877b55722 /crates/ra_syntax/src/syntax_node/builder.rs | |
parent | abc5d377e2957af962c33d565fd550eb504dbbee (diff) | |
parent | 4e91c23c796988e3934afabf619185333f85c116 (diff) |
Merge #808
808: rename yellow -> syntax_node r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_syntax/src/syntax_node/builder.rs')
-rw-r--r-- | crates/ra_syntax/src/syntax_node/builder.rs | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/crates/ra_syntax/src/syntax_node/builder.rs b/crates/ra_syntax/src/syntax_node/builder.rs new file mode 100644 index 000000000..8abd0f051 --- /dev/null +++ b/crates/ra_syntax/src/syntax_node/builder.rs | |||
@@ -0,0 +1,41 @@ | |||
1 | use crate::{ | ||
2 | parser_impl::Sink, | ||
3 | syntax_node::{GreenNode, RaTypes, SyntaxError}, | ||
4 | SmolStr, SyntaxKind, | ||
5 | }; | ||
6 | use rowan::GreenNodeBuilder; | ||
7 | |||
8 | pub(crate) struct GreenBuilder { | ||
9 | errors: Vec<SyntaxError>, | ||
10 | inner: GreenNodeBuilder<RaTypes>, | ||
11 | } | ||
12 | |||
13 | impl GreenBuilder { | ||
14 | pub(crate) fn new() -> GreenBuilder { | ||
15 | GreenBuilder { errors: Vec::new(), inner: GreenNodeBuilder::new() } | ||
16 | } | ||
17 | } | ||
18 | |||
19 | impl Sink for GreenBuilder { | ||
20 | type Tree = (GreenNode, Vec<SyntaxError>); | ||
21 | |||
22 | fn leaf(&mut self, kind: SyntaxKind, text: SmolStr) { | ||
23 | self.inner.leaf(kind, text); | ||
24 | } | ||
25 | |||
26 | fn start_branch(&mut self, kind: SyntaxKind) { | ||
27 | self.inner.start_internal(kind) | ||
28 | } | ||
29 | |||
30 | fn finish_branch(&mut self) { | ||
31 | self.inner.finish_internal(); | ||
32 | } | ||
33 | |||
34 | fn error(&mut self, error: SyntaxError) { | ||
35 | self.errors.push(error) | ||
36 | } | ||
37 | |||
38 | fn finish(self) -> (GreenNode, Vec<SyntaxError>) { | ||
39 | (self.inner.finish(), self.errors) | ||
40 | } | ||
41 | } | ||