diff options
Diffstat (limited to 'crates/ra_syntax/src/parsing/builder.rs')
-rw-r--r-- | crates/ra_syntax/src/parsing/builder.rs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/crates/ra_syntax/src/parsing/builder.rs b/crates/ra_syntax/src/parsing/builder.rs new file mode 100644 index 000000000..9090c60c2 --- /dev/null +++ b/crates/ra_syntax/src/parsing/builder.rs | |||
@@ -0,0 +1,42 @@ | |||
1 | use crate::{ | ||
2 | parsing::parser_impl::Sink, | ||
3 | syntax_node::{GreenNode, RaTypes}, | ||
4 | SmolStr, SyntaxKind, SyntaxError, | ||
5 | }; | ||
6 | |||
7 | use rowan::GreenNodeBuilder; | ||
8 | |||
9 | pub(crate) struct GreenBuilder { | ||
10 | errors: Vec<SyntaxError>, | ||
11 | inner: GreenNodeBuilder<RaTypes>, | ||
12 | } | ||
13 | |||
14 | impl GreenBuilder { | ||
15 | pub(crate) fn new() -> GreenBuilder { | ||
16 | GreenBuilder { errors: Vec::new(), inner: GreenNodeBuilder::new() } | ||
17 | } | ||
18 | } | ||
19 | |||
20 | impl Sink for GreenBuilder { | ||
21 | type Tree = (GreenNode, Vec<SyntaxError>); | ||
22 | |||
23 | fn leaf(&mut self, kind: SyntaxKind, text: SmolStr) { | ||
24 | self.inner.leaf(kind, text); | ||
25 | } | ||
26 | |||
27 | fn start_branch(&mut self, kind: SyntaxKind) { | ||
28 | self.inner.start_internal(kind) | ||
29 | } | ||
30 | |||
31 | fn finish_branch(&mut self) { | ||
32 | self.inner.finish_internal(); | ||
33 | } | ||
34 | |||
35 | fn error(&mut self, error: SyntaxError) { | ||
36 | self.errors.push(error) | ||
37 | } | ||
38 | |||
39 | fn finish(self) -> (GreenNode, Vec<SyntaxError>) { | ||
40 | (self.inner.finish(), self.errors) | ||
41 | } | ||
42 | } | ||