error position is advancing when it shouldn't
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
PyMeta |
New
|
Undecided
|
Unassigned |
Bug Description
I am trying to use the "position" attribute of ParseError instances returned by .apply() to determine wheter the input was entirely consumed or not, so I can detect errors on the text being parsed.
I'm using this grammar:
logicGrammar = """
name ::= <letter>:l <letterOrDigit>*:ls => l + ''.join(ls)
value ::= (<token 'T'> | <token 'F'>):v => v == 'T'
binaryop ::= <token '|'> | <token '&'> | <token '^'>
unaryop ::= <token '~'>
prim ::= <value> | <name> | (<token '('> <expr>:nested <token ')'> => (nested,))
unary ::= (<unaryop>:op <unary>:arg => (op, arg)) | <prim>
binary ::= <unary>:arg1 <binaryop>:op <expr>:arg2 => (arg1, op, arg2)
expr ::= <binary> | <unary>
"""
LogicParser = OMeta.makeGramm
def logicParse(text):
result, error = LogicParser(
if error.position != len(text):
raise ValueError('invalid logic expression on %r' % (text[error.
return result
When parsing valid input it works as expected:
assert logicParse('(c|b)') == (('c', '|', 'b'),)
Now when parsing invalid input, I should be able to use the position to determine it was invalid, so the code below should raise ValueError:
assert logicParse(