aboutsummaryrefslogtreecommitdiff
path: root/src/tree
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-02-09 19:44:50 +0000
committerAleksey Kladov <[email protected]>2018-02-09 19:44:50 +0000
commit0ae26c344aa7477a18c2019cfa0062a9a745d70d (patch)
tree6a3659da778ee7c07f7a487694b09070c0451f45 /src/tree
parent351107d0b143e2c3497bd0f424f0d76bc51df0c0 (diff)
Drop ErrorBuilder nonsense
Diffstat (limited to 'src/tree')
-rw-r--r--src/tree/file_builder.rs45
-rw-r--r--src/tree/mod.rs2
2 files changed, 14 insertions, 33 deletions
diff --git a/src/tree/file_builder.rs b/src/tree/file_builder.rs
index 47038496d..81702b83e 100644
--- a/src/tree/file_builder.rs
+++ b/src/tree/file_builder.rs
@@ -14,7 +14,7 @@ pub(crate) trait Sink {
14 fn leaf(&mut self, kind: SyntaxKind, len: TextUnit); 14 fn leaf(&mut self, kind: SyntaxKind, len: TextUnit);
15 fn start_internal(&mut self, kind: SyntaxKind); 15 fn start_internal(&mut self, kind: SyntaxKind);
16 fn finish_internal(&mut self); 16 fn finish_internal(&mut self);
17 fn error(&mut self) -> ErrorBuilder; 17 fn error(&mut self, err: ErrorMsg);
18} 18}
19 19
20#[derive(Debug)] 20#[derive(Debug)]
@@ -22,7 +22,8 @@ pub(crate) struct FileBuilder {
22 text: String, 22 text: String,
23 nodes: Vec<NodeData>, 23 nodes: Vec<NodeData>,
24 errors: Vec<SyntaxErrorData>, 24 errors: Vec<SyntaxErrorData>,
25 in_progress: Vec<(NodeIdx, Option<NodeIdx>)>, // (parent, last_child) 25 in_progress: Vec<(NodeIdx, Option<NodeIdx>)>,
26 // (parent, last_child)
26 pos: TextUnit, 27 pos: TextUnit,
27} 28}
28 29
@@ -65,8 +66,13 @@ impl Sink for FileBuilder {
65 } 66 }
66 } 67 }
67 68
68 fn error(&mut self) -> ErrorBuilder { 69 fn error(&mut self, err: ErrorMsg) {
69 ErrorBuilder::new(self) 70 let &(node, after_child) = self.in_progress.last().unwrap();
71 self.errors.push(SyntaxErrorData {
72 node,
73 message: err.message,
74 after_child,
75 })
70 } 76 }
71} 77}
72 78
@@ -149,32 +155,7 @@ fn grow(left: &mut TextRange, right: TextRange) {
149 *left = TextRange::from_to(left.start(), right.end()) 155 *left = TextRange::from_to(left.start(), right.end())
150} 156}
151 157
152#[derive(Debug)] 158#[derive(Default)]
153pub struct ErrorBuilder<'f> { 159pub(crate) struct ErrorMsg {
154 message: Option<String>, 160 pub(crate) message: String
155 builder: &'f mut FileBuilder,
156}
157
158impl<'f> ErrorBuilder<'f> {
159 fn new(builder: &'f mut FileBuilder) -> Self {
160 ErrorBuilder {
161 message: None,
162 builder,
163 }
164 }
165
166 pub fn message<M: Into<String>>(mut self, m: M) -> Self {
167 self.message = Some(m.into());
168 self
169 }
170
171 pub fn emit(self) {
172 let message = self.message.expect("Error message not set");
173 let &(node, after_child) = self.builder.in_progress.last().unwrap();
174 self.builder.errors.push(SyntaxErrorData {
175 node,
176 message,
177 after_child,
178 })
179 }
180} 161}
diff --git a/src/tree/mod.rs b/src/tree/mod.rs
index 9ed0504c7..b7ed59793 100644
--- a/src/tree/mod.rs
+++ b/src/tree/mod.rs
@@ -4,7 +4,7 @@ use std::fmt;
4use std::cmp; 4use std::cmp;
5 5
6mod file_builder; 6mod file_builder;
7pub(crate) use self::file_builder::{FileBuilder, Sink}; 7pub(crate) use self::file_builder::{FileBuilder, Sink, ErrorMsg};
8 8
9pub use syntax_kinds::SyntaxKind; 9pub use syntax_kinds::SyntaxKind;
10 10