Skip to content

Commit

Permalink
fix(parser): Give correct location information for unindentation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Marwes committed Jul 1, 2017
1 parent 026c369 commit 30541c1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions parser/src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ impl Contexts {
self.stack.pop()
}

fn push(&mut self, offside: Offside) -> Result<(), Error> {
fn push(&mut self, offside: Offside) -> Result<(), Spanned<Error, BytePos>> {
self.check_unindentation_limit(offside)?;
self.stack.push(offside);
Ok(())
}

fn check_unindentation_limit(&mut self, offside: Offside) -> Result<(), Error> {
fn check_unindentation_limit(&mut self, offside: Offside) -> Result<(), Spanned<Error, BytePos>> {
let mut skip_block = false;
for other_offside in self.stack.iter().rev() {
match other_offside.context {
Expand All @@ -96,7 +96,7 @@ impl Contexts {
_ => continue,
}
debug!("Unindentation error: {:?} < {:?}", offside, other_offside);
return Err(Error::UnindentedTooFar);
return Err(pos::spanned2(offside.location.absolute, offside.location.absolute, Error::UnindentedTooFar));
}
Ok(())
}
Expand Down Expand Up @@ -146,7 +146,7 @@ impl<'input, Tokens> Layout<'input, Tokens>
pos::spanned(span, layout_token)
}

fn scan_for_next_block(&mut self, context: Context) -> Result<(), Error> {
fn scan_for_next_block(&mut self, context: Context) -> Result<(), Spanned<Error, BytePos>> {
let next = self.next_token();
let span = next.span;
self.unprocessed_tokens.push(next);
Expand All @@ -158,7 +158,7 @@ impl<'input, Tokens> Layout<'input, Tokens>
.push(Offside::new(span.start, context))
}

fn layout_next_token(&mut self) -> Result<SpannedToken<'input>, Error> {
fn layout_next_token(&mut self) -> Result<SpannedToken<'input>, Spanned<Error, BytePos>> {
use std::cmp::Ordering;

let mut token = self.next_token();
Expand Down Expand Up @@ -436,9 +436,9 @@ fn token_closes_context(token: &Token, context: Context) -> bool {
impl<'input, Tokens> Iterator for Layout<'input, Tokens>
where Tokens: Iterator<Item = SpannedToken<'input>>
{
type Item = Result<SpannedToken<'input>, Error>;
type Item = Result<SpannedToken<'input>, Spanned<Error, BytePos>>;

fn next(&mut self) -> Option<Result<SpannedToken<'input>, Error>> {
fn next(&mut self) -> Option<Self::Item> {
match self.layout_next_token() {
Ok(Spanned { value: Token::EOF, .. }) => None,
token => Some(token),
Expand Down
2 changes: 1 addition & 1 deletion parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ macro_rules! layout {
err.span.end.absolute,
err.value.into())
})?;
let token = token.map_err(|err| pos::spanned2(0.into(), 0.into(), err.into()))?;
let token = token.map_err(|err| pos::spanned(err.span, err.value.into()))?;
debug!("Lex {:?}", token.value);
let Span { start, end, .. } = token.span;
Ok((start.absolute, token.value, end.absolute))
Expand Down

0 comments on commit 30541c1

Please sign in to comment.