From f797c81155e9b7371b24801efac3fcbd236fc9ab Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 7 Jan 2018 12:13:01 +0300 Subject: Smart eof for blocks --- src/tree/file_builder.rs | 2 +- src/tree/mod.rs | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'src/tree') diff --git a/src/tree/file_builder.rs b/src/tree/file_builder.rs index a1b004892..ddb29a6b9 100644 --- a/src/tree/file_builder.rs +++ b/src/tree/file_builder.rs @@ -154,7 +154,7 @@ impl<'f> ErrorBuilder<'f> { self } - pub fn build(self) { + pub fn emit(self) { let message = self.message.expect("Error message not set"); let node = self.builder.current_id(); self.builder.errors.push(SyntaxErrorData { node, message }) diff --git a/src/tree/mod.rs b/src/tree/mod.rs index 00d33cbc7..3980b23ce 100644 --- a/src/tree/mod.rs +++ b/src/tree/mod.rs @@ -73,7 +73,7 @@ impl<'f> Node<'f> { Children { next: self.as_node(self.data().first_child) } } - pub fn SyntaxErrors(&self) -> SyntaxErrors<'f> { + pub fn errors(&self) -> SyntaxErrors<'f> { let pos = self.file.errors.iter().position(|e| e.node == self.idx); let next = pos .map(|i| ErrorIdx(i as u32)) @@ -112,12 +112,13 @@ impl<'f> SyntaxError<'f> { } fn next(&self) -> Option> { - if self.file.errors.len() == self.idx.0 as usize { + let next_idx = self.idx.0 + 1; + if !((next_idx as usize) < self.file.errors.len()) { return None; } let result = SyntaxError { file: self.file, - idx: ErrorIdx(self.idx.0 + 1) + idx: ErrorIdx(next_idx) }; if result.data().node != self.data().node { return None; -- cgit v1.2.3