petitparser / dart-petitparser

Dynamic parser combinators in Dart.
https://pub.dartlang.org/packages/petitparser
MIT License
457 stars 48 forks source link

Custom Failure message #113

Closed groupsvkg closed 3 years ago

groupsvkg commented 3 years ago

Hello,

Can you please share an example of - how to throw custom Failure message in parser.

I can see Failure message when "word" is not an instance of the grammar. For the case when "word" is instance of the grammar. How can I throw custom Failure message when I know constraint failed in parser.

Regards, Vishal

renggli commented 3 years ago

I hope 7a7a180 solves this? With the optional arguments failureMessage and failurePosition you can customize the generated error: https://github.com/petitparser/dart-petitparser/blob/main/petitparser/lib/src/parser/action/where.dart