parsley icon indicating copy to clipboard operation
parsley copied to clipboard

Contextual Information in Error Messages

Open j-mie6 opened this issue 1 year ago • 1 comments

Is your feature request related to a problem? Please describe. When parsing programming languages and other grammars with nested structure, it is possible that layers of context are passed through. One example is the filename itself, which is already incorporated into error messages when using parseFromFile. Another example would be reporting syntax errors within functions.

Describe the solution you'd like New combinators can be added to allow for the tracking of contextual information during the parse, but this also requires the formatting of contextual information to be added to ErrorBuilder: since these methods are abstract, this requires a breaking change to the API.

j-mie6 avatar Dec 31 '22 18:12 j-mie6

I think that we can actually add this via a non-breaking case. The idea is to have a subclass ErrorBuilder1 or something, that acts like the old Revision mixins but in reverse, where you have to opt-in to new features, not out of them. Then the internal formatting logic must have something like:

errBuilder match { 
  case builder: ErrorBuilder1[Err] => /* new logic */
  case builder: ErrorBuilder[Err]   => /* old logic */
}

This will mean it can handle all the new functionality and fall back to old ones if the user implemented an old type.

j-mie6 avatar Sep 14 '23 12:09 j-mie6