diff options
author | Aleksey Kladov <[email protected]> | 2018-01-07 10:09:13 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-01-07 10:09:13 +0000 |
commit | 18f9e50b2d1aaf91992be9fd2f2a7e1866a943d3 (patch) | |
tree | e984c18fb8fa2e81950a582672077f966ce570e3 /src | |
parent | efcfaae34ac7a54e858aad82e6503a7c69d6c550 (diff) |
Error placement
Diffstat (limited to 'src')
-rw-r--r-- | src/tree/file_builder.rs | 4 | ||||
-rw-r--r-- | src/tree/mod.rs | 16 |
2 files changed, 18 insertions, 2 deletions
diff --git a/src/tree/file_builder.rs b/src/tree/file_builder.rs index ddb29a6b9..b07f4027b 100644 --- a/src/tree/file_builder.rs +++ b/src/tree/file_builder.rs | |||
@@ -156,7 +156,7 @@ impl<'f> ErrorBuilder<'f> { | |||
156 | 156 | ||
157 | pub fn emit(self) { | 157 | pub fn emit(self) { |
158 | let message = self.message.expect("Error message not set"); | 158 | let message = self.message.expect("Error message not set"); |
159 | let node = self.builder.current_id(); | 159 | let &(node, after_child) = self.builder.in_progress.last().unwrap(); |
160 | self.builder.errors.push(SyntaxErrorData { node, message }) | 160 | self.builder.errors.push(SyntaxErrorData { node, message, after_child }) |
161 | } | 161 | } |
162 | } | 162 | } |
diff --git a/src/tree/mod.rs b/src/tree/mod.rs index 3980b23ce..7f4d427ba 100644 --- a/src/tree/mod.rs +++ b/src/tree/mod.rs | |||
@@ -2,6 +2,7 @@ use text::{TextUnit, TextRange}; | |||
2 | use syntax_kinds::syntax_info; | 2 | use syntax_kinds::syntax_info; |
3 | 3 | ||
4 | use std::fmt; | 4 | use std::fmt; |
5 | use std::cmp; | ||
5 | 6 | ||
6 | mod file_builder; | 7 | mod file_builder; |
7 | pub use self::file_builder::{FileBuilder, Sink}; | 8 | pub use self::file_builder::{FileBuilder, Sink}; |
@@ -96,6 +97,15 @@ impl<'f> fmt::Debug for Node<'f> { | |||
96 | } | 97 | } |
97 | } | 98 | } |
98 | 99 | ||
100 | impl<'f> cmp::PartialEq<Node<'f>> for Node<'f> { | ||
101 | fn eq(&self, other: &Node<'f>) -> bool { | ||
102 | self.idx == other.idx && ::std::ptr::eq(self.file, other.file) | ||
103 | } | ||
104 | } | ||
105 | |||
106 | impl<'f> cmp::Eq for Node<'f> { | ||
107 | } | ||
108 | |||
99 | #[derive(Clone, Copy)] | 109 | #[derive(Clone, Copy)] |
100 | pub struct SyntaxError<'f> { | 110 | pub struct SyntaxError<'f> { |
101 | file: &'f File, | 111 | file: &'f File, |
@@ -107,6 +117,11 @@ impl<'f> SyntaxError<'f> { | |||
107 | self.data().message.as_str() | 117 | self.data().message.as_str() |
108 | } | 118 | } |
109 | 119 | ||
120 | pub fn after_child(&self) -> Option<Node<'f>> { | ||
121 | let idx = self.data().after_child?; | ||
122 | Some(Node { file: self.file, idx }) | ||
123 | } | ||
124 | |||
110 | fn data(&self) -> &'f SyntaxErrorData { | 125 | fn data(&self) -> &'f SyntaxErrorData { |
111 | &self.file.errors[self.idx] | 126 | &self.file.errors[self.idx] |
112 | } | 127 | } |
@@ -187,6 +202,7 @@ struct ErrorIdx(u32); | |||
187 | struct SyntaxErrorData { | 202 | struct SyntaxErrorData { |
188 | node: NodeIdx, | 203 | node: NodeIdx, |
189 | message: String, | 204 | message: String, |
205 | after_child: Option<NodeIdx>, | ||
190 | } | 206 | } |
191 | 207 | ||
192 | impl ::std::ops::Index<ErrorIdx> for Vec<SyntaxErrorData> { | 208 | impl ::std::ops::Index<ErrorIdx> for Vec<SyntaxErrorData> { |