Change error handler invocation to include a set of expected tokens. This is really useful to create error message to end users;
It unifies error handling by always calling the error handler with 3 arguments, in an order that makes sense: token, expected, state. This means the order, and existence/absense of arguments does not depend on whether or not the parser has been initialized with a state or not. The state is always included, even if it's None.
I realize this is a backward-incompatible change, but it definitely is a lot cleaner, I think. Let me know if you think this should be dealt with differently.
Example:
@pg.error
def error_handler(token, expected, state):
exp = ', '.join(sorted(expected))
msg = 'Ran into %s where it was expecting any of %s' % (token, exp)
raise ValueError(msg)
This does two things:
token
,expected
,state
. This means the order, and existence/absense of arguments does not depend on whether or not the parser has been initialized with a state or not. The state is always included, even if it'sNone
.I realize this is a backward-incompatible change, but it definitely is a lot cleaner, I think. Let me know if you think this should be dealt with differently.
Example: