diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-02-09 19:56:18 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-02-09 19:56:18 +0000 |
commit | 419b9b7e5efd895249934551cb2588b27a956f58 (patch) | |
tree | 4d53f6d5e34a4244f0aaeb2039454e3594856324 /src/tree/file_builder.rs | |
parent | 550b17d7cf321c2aebff75d00b1654b55beca53c (diff) | |
parent | ac932df22a993f0b287e60aa42055405ef94a6ae (diff) |
Merge #44
44: Drop ErrorBuilder nonsense r=matklad a=matklad
Diffstat (limited to 'src/tree/file_builder.rs')
-rw-r--r-- | src/tree/file_builder.rs | 45 |
1 files changed, 13 insertions, 32 deletions
diff --git a/src/tree/file_builder.rs b/src/tree/file_builder.rs index 47038496d..3c7e2d7cf 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)] |
153 | pub struct ErrorBuilder<'f> { | 159 | pub(crate) struct ErrorMsg { |
154 | message: Option<String>, | 160 | pub(crate) message: String, |
155 | builder: &'f mut FileBuilder, | ||
156 | } | ||
157 | |||
158 | impl<'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 | } |