aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/parsing/builder.rs
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-02-20 13:50:29 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-02-20 13:50:29 +0000
commit96899f8278b787280bd07d9ac9dce29a610ce40d (patch)
treed02a22f02908fd3c89e50845a06a89b997220fc2 /crates/ra_syntax/src/parsing/builder.rs
parent5b617e3bf8252887a3eb1ce76d4b62cbee74e551 (diff)
parent86a67dce25f11ba9803a5727f77c02fd1f49e2c0 (diff)
Merge #861
861: Move parsing to a separate module r=matklad a=matklad 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.rs42
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 @@
1use crate::{
2 parsing::parser_impl::Sink,
3 syntax_node::{GreenNode, RaTypes},
4 SmolStr, SyntaxKind, SyntaxError,
5};
6
7use rowan::GreenNodeBuilder;
8
9pub(crate) struct GreenBuilder {
10 errors: Vec<SyntaxError>,
11 inner: GreenNodeBuilder<RaTypes>,
12}
13
14impl GreenBuilder {
15 pub(crate) fn new() -> GreenBuilder {
16 GreenBuilder { errors: Vec::new(), inner: GreenNodeBuilder::new() }
17 }
18}
19
20impl 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}