Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Successful parser will not clear the error stack #355

Open
yihuaf opened this issue Jun 4, 2023 · 1 comment
Open

Successful parser will not clear the error stack #355

yihuaf opened this issue Jun 4, 2023 · 1 comment

Comments

@yihuaf
Copy link

yihuaf commented Jun 4, 2023

Not sure if this is intended behavior or a bug. The operations such as many will parse success 0 or N times and will stop at the last failed parse. The parse will generate some error. The parsing operation will be successful but the error stack is not cleared. A subsequent skip fails will cause the errors from the failed many the N+1 failed parse to show up.

Consider the following example:

    #[test]
    fn test_skip() {
        use combine::EasyParser;
        let ret = many::<String, _, _>(combine::parser::char::char('a'))
            .skip(combine::parser::char::char('b'))
            .easy_parse("a");
        println!("{:?}", ret);
    }

The input is a "a", and the parser is to parse many 'a' followed by a b (which will fail). The expected error is:

errors: [Unexpected(Static("end of input")), Expected(Token('b'))]

But the actual output is:

errors: [Unexpected(Static("end of input")), Expected(Token('a')), Expected(Token('b'))]

The Expected(Token('a')) error is from the many parser parsing "a". It should be cleared once the many parser is deemed successful.

@Marwes
Copy link
Owner

Marwes commented Jun 5, 2023

That is expected behavior. At the point where it fails another a or a b would be accepted. Arguably we could drop the a expectation here since the full parse would fail but I am not entirely sure how that would be decided without losing other cases where the a expectation should remain in the error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants