Skip to content

Commit

Permalink
fix: Report more errors in the middle of sequence parsers
Browse files Browse the repository at this point in the history
  • Loading branch information
Marwes committed Aug 4, 2018
1 parent 9aa1db9 commit f9e404f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/parser/sequence.rs
Expand Up @@ -83,13 +83,20 @@ macro_rules! tuple_parser {
$h: &mut $h $(, $id : &mut $id )*
) -> ConsumedResult<($h::Output, $($id::Output),*), Input>
{
let inner_offset = err.offset;
err.offset = ErrorOffset(offset);
if first_empty_parser != 0 {
if let Ok(t) = input.uncons() {
err.error.add(StreamError::unexpected_token(t));
}
dispatch_on!(0, |i, mut p| {
if i >= first_empty_parser {
if err.offset <= ErrorOffset(1) {
// We reached the last parser we need to add errors to (and the
// parser that actually returned the error), use the returned
// offset for that parser.
err.offset = inner_offset;
}
Parser::add_error(&mut p, &mut err);
if err.offset <= ErrorOffset(1) {
return false;
Expand All @@ -101,7 +108,7 @@ macro_rules! tuple_parser {
true
}; $h $(, $id)*);
ConsumedErr(err.error)
} else {
} else {
EmptyErr(err)
}
}
Expand Down
18 changes: 18 additions & 0 deletions tests/parser.rs
Expand Up @@ -442,6 +442,24 @@ mod tests_std {
);
}

#[test]
fn sequence_in_optional_nested_2_report_delayed_error() {
use combine::parser::item::position;
assert_eq!(
(char('{'), optional(position().with(char('a')))
.skip(optional(position().with(char('c'))))
.skip(char('}')))
.easy_parse("{b")
.map_err(|e| e.errors),
Err(vec![
Error::Unexpected('b'.into()),
Error::Expected('a'.into()),
Error::Expected('c'.into()),
Error::Expected('}'.into()),
]),
);
}

#[test]
fn sequence_in_many_report_delayed_error() {
use combine::parser::item::position;
Expand Down

0 comments on commit f9e404f

Please sign in to comment.