aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/parsing/builder.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax/src/parsing/builder.rs')
-rw-r--r--crates/ra_syntax/src/parsing/builder.rs41
1 files changed, 41 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..9d7ad06fe
--- /dev/null
+++ b/crates/ra_syntax/src/parsing/builder.rs
@@ -0,0 +1,41 @@
1use crate::{
2 parsing::parser_impl::Sink,
3 syntax_node::{GreenNode, RaTypes, SyntaxError},
4 SmolStr, SyntaxKind,
5};
6use rowan::GreenNodeBuilder;
7
8pub(crate) struct GreenBuilder {
9 errors: Vec<SyntaxError>,
10 inner: GreenNodeBuilder<RaTypes>,
11}
12
13impl GreenBuilder {
14 pub(crate) fn new() -> GreenBuilder {
15 GreenBuilder { errors: Vec::new(), inner: GreenNodeBuilder::new() }
16 }
17}
18
19impl 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}