grappa icon indicating copy to clipboard operation
grappa copied to clipboard

Allow custom parse error messages

Open akirschbaum opened this issue 11 years ago • 1 comments

It should be possible to generate custom error messages from a parser. For example with a function like BaseParser.parseError(String message) which causes a parse error with the given custom error message.

akirschbaum avatar May 20 '14 06:05 akirschbaum

Yes, I agree with that.

The (internal) current API however causes two problems:

  • error messages are either collected (ReportingParseRunner, others) or not at all (BasicParseRunner);
  • the Rule interface leaves no possibility to insert a custom error message; in fact, there is no "errorMessage" field in AbstractMatcher.

I'll have to collect more knowledge on the API to be able to figure out how to collect user error messages, and also the interface to do it, since it's quite important. I thought about something like this:

Rule myRule()
{
    return sequence("foo", bar()).errorMessage("no dice...");
}

That is a definite feature I want in 1.0.0 so I'll be working on it. Not sure yet how I'll do it though...

fge avatar May 20 '14 07:05 fge