From 18f9e50b2d1aaf91992be9fd2f2a7e1866a943d3 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 7 Jan 2018 13:09:13 +0300 Subject: Error placement --- src/tree/mod.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/tree/mod.rs') 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}; use syntax_kinds::syntax_info; use std::fmt; +use std::cmp; mod file_builder; pub use self::file_builder::{FileBuilder, Sink}; @@ -96,6 +97,15 @@ impl<'f> fmt::Debug for Node<'f> { } } +impl<'f> cmp::PartialEq> for Node<'f> { + fn eq(&self, other: &Node<'f>) -> bool { + self.idx == other.idx && ::std::ptr::eq(self.file, other.file) + } +} + +impl<'f> cmp::Eq for Node<'f> { +} + #[derive(Clone, Copy)] pub struct SyntaxError<'f> { file: &'f File, @@ -107,6 +117,11 @@ impl<'f> SyntaxError<'f> { self.data().message.as_str() } + pub fn after_child(&self) -> Option> { + let idx = self.data().after_child?; + Some(Node { file: self.file, idx }) + } + fn data(&self) -> &'f SyntaxErrorData { &self.file.errors[self.idx] } @@ -187,6 +202,7 @@ struct ErrorIdx(u32); struct SyntaxErrorData { node: NodeIdx, message: String, + after_child: Option, } impl ::std::ops::Index for Vec { -- cgit v1.2.3