Formal grammar: SWIPL Example error handling

Nothing is thrown… :frowning:

I really don’t want to re-open this can of worms, but if you recall from a lengthy discussion on this forum some time back, I have a philosophical objection to errors compared to failure in logic programs, so you won’t see exceptions generated from most code I write, unless there’s no recourse, e.g., resource errors.

But if you want to modify the parser to generate exceptions that’s your call. In this particular case there are two sources of failure: syntax parsing (using the grammar) and expression reduction (semantics) and you’ve only trapped failure due to the latter. To convert the former failures to exceptions, you need to add a “failure” handling clause to string_termList/2 to throw the error. In fact this will catch both classes of error if you choose to remove your mod.

Or you could do the same to ppeg_parse (your predicate I assume) and not change the example Prolog parser at all. The failures are “noisy” so you won’t lose any diagnostic information.