Open kristapsdz-saic opened 2 years ago
This is a deliberate design decision. The definition of what is valid syntax is assumed to lie entirely in the grammar definition, and action functions are only responsible for building nodes based on that assumption.
If an action function throws an exception, that will make the entire parse fail, even if there are other choice branches the parser could have tried. Preventing this would require action functions to return a special value to indicate failure, whereas we currently assume all values, including null
, are valid action values.
We _are_currently considering having a distinct mechanism for predicates, where users can inject code to decide whether the input is valid or not, but that would be a separate interface from action functions.
There's currently no way for Java actions to throw an error to signal failure, which has been problematic in a larger project I'm implementing with this great piece of software.
I've worked around this by patching the action invocations to throw. (Edited for the newest version.)
This has worked very well in having the actions throw nested errors, with the top-level wrapping in a ParseError to pass to the caller.
Since existing implements without the
throw
are more specific than the interface, this will not affect existing code.If you'd like any other changes to merge a throwable into the mainline, please let me know what I can do!