error position is advancing when it shouldn't

Bug #711986 reported by Clóvis Fabrício
6
This bug affects 1 person
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.makeGrammar(logicGrammar, {})
def logicParse(text):
    result, error = LogicParser(text).apply('expr')
    if error.position != len(text):
        raise ValueError('invalid logic expression on %r' % (text[error.position-1:]))
    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('(c|b)|') == (('c', '|', 'b'),)

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.