Allow user-specific conversion of Megaparsec custom error component #29
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The megaparsec parser allows the user to specify a custom error type (the
ein Parsec e s`) which the user may use to provide specific errors.The diagnose
megaparsec-compatsupport simply asks megaparsec for a pretty version of any error generated; if the error is a single line, it's reported withThis, if it's two lines, it'sThisthenWhere, and if it's more than two lines, diagnose drops the megaparsec error output and simply reports<<Unknown error>>.In my target situation, I wanted to use Diagnose as the custom error type as well (
Parsec (Diagnose Text) Text), but since Diagnose errors are more than 2 lines, the result was simply<<Unknown error>>.This patch adds a
mkReportsto theHintclass (the class could have been renamed to adjust to this new functionality, but I wanted to keep the change set minimal). When there is a megaparsecFancyError(i.e. the user's custom error), it calls thismkReportsto allow the user to determine how the report should be generated. The standard report described above is provided as a default.I also provided default implementations for both
Hintmethods so that the user does not have supply an instance.