As discussed here, NimbleParsec should have an expect combinator for better error reporting. I suggest something like this: expect(previous \\ [], expected). This combinator would raise an error is expected didn't match.
My use case: I'm currently working on a parser for the ICU Message Format. Currently, NimbleParsec backtracks so much that I get rather useless error messages. Suppose we have something like this:
{variable, plural, one {...} two {...} abcd {...}}
The above is invalid, because abcd is not a supported option for the plural argument type. I already know it won't be supported as soon as I parse {variable, plural, , and I'd like to emit an error as soon as I find the abcd option. But currently there is no way to do this... NimbleParsec will just backtrack and fail with an error message that doesn't really help anyone (it actually says it expects an end of string on character 0...).
An expect combinator would allow me to emit the correct error message.
As discussed here, NimbleParsec should have an
expectcombinator for better error reporting. I suggest something like this:expect(previous \\ [], expected). This combinator would raise an error isexpecteddidn't match.My use case: I'm currently working on a parser for the ICU Message Format. Currently, NimbleParsec backtracks so much that I get rather useless error messages. Suppose we have something like this:
The above is invalid, because
abcdis not a supported option for thepluralargument type. I already know it won't be supported as soon as I parse{variable, plural,, and I'd like to emit an error as soon as I find theabcdoption. But currently there is no way to do this... NimbleParsec will just backtrack and fail with an error message that doesn't really help anyone (it actually says it expects an end of string on character 0...).An
expectcombinator would allow me to emit the correct error message.