From 4ddb8b9f2fed247e068a434ff1d37753c6df1e33 Mon Sep 17 00:00:00 2001 From: Tad Hardesty Date: Sat, 7 Dec 2019 23:36:12 -0800 Subject: [PATCH] Remove HasLocation implementation from IndentProcessor --- src/dreammaker/indents.rs | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/dreammaker/indents.rs b/src/dreammaker/indents.rs index af096a5b..06261ae5 100644 --- a/src/dreammaker/indents.rs +++ b/src/dreammaker/indents.rs @@ -1,8 +1,8 @@ //! The indentation processor. use std::collections::VecDeque; -use super::{Location, HasLocation, Context}; -use super::lexer::{LocatedToken, Token, Punctuation}; +use crate::{Location, Context, DMError}; +use crate::lexer::{LocatedToken, Token, Punctuation}; /// Eliminates blank lines, parses and validates indentation, braces, and semicolons. /// @@ -23,12 +23,6 @@ pub struct IndentProcessor<'ctx, I> { eof_yielded: bool, } -impl<'ctx, I> HasLocation for IndentProcessor<'ctx, I> { - fn location(&self) -> Location { - self.last_input_loc - } -} - impl<'ctx, I> IndentProcessor<'ctx, I> where I: Iterator { @@ -122,10 +116,10 @@ impl<'ctx, I> IndentProcessor<'ctx, I> where // Register the error, but cross our fingers and // hope that truncating division will approximate // a sane situation. - self.context.register_error(self.error(format!( + DMError::new(self.last_input_loc, format!( "inconsistent indentation: {} % {} != 0", - spaces, spaces_per_indent - ))); + spaces, spaces_per_indent, + )).register(self.context) } new_indents = spaces / spaces_per_indent; self.current = Some((spaces_per_indent, new_indents)); @@ -138,10 +132,10 @@ impl<'ctx, I> IndentProcessor<'ctx, I> where self.push_eol(Token::Punct(Punctuation::LBrace)); } else if indents < new_indents { // multiple indent is an error, register it but let it work - self.context.register_error(self.error(format!( + DMError::new(self.last_input_loc, format!( "inconsistent multiple indentation: {} > 1", new_indents - indents, - ))); + )).register(self.context); for _ in indents..new_indents { self.push_eol(Token::Punct(Punctuation::LBrace)); } @@ -170,7 +164,7 @@ impl<'ctx, I> IndentProcessor<'ctx, I> where Token::Punct(Punctuation::RBrace) => { self.current = match self.current { None => { - self.context.register_error(self.error("unmatched right brace")); + DMError::new(self.last_input_loc, "unmatched right brace").register(self.context); None } Some((_, 1)) => None,