Skip to content

Improve error reporting for some failed match scenarios #142

@AndrewSav

Description

@AndrewSav

Consider that at a certain point during parsing I know that the parsing is not going to succeed. E.g. parser A matched (so I know that alternatives like C and and D won't match) but, after parser A matched, parser B failed. There is no point to continue here and we have an opportunity here to produce a good error message. Do we have a way to do this?

Consider this:

A.Then(x => B).Or(C).Or(D).Many().AtEnd()

When B fails then C and D will be tried (I only want them tried if A itself fails). If A matched I know that neither C nor D will match. Many will succeed and then At End will fail with a lame error message about something unexpected.

When I'm parsing B and it has failed I know why, this is because after a they had to specify b but they did not so I would like print out what B expected and how what they specified is different from that.

E.g. A.Then(x => B.FailOnError("you have to specify correct b after a")).Or(C).Or(D).Many().AtEnd()

Can we do this already by cleverly rewriting this chain of parsers?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions