Skip to content

Unexpected backtracking behavior or bad error message #5

@dvogel

Description

@dvogel
from parcon import SignificantLiteral, Regex

Digits = Regex(ur"[0-9]+")
DecimalLiteral = ((Digits + SignificantLiteral(".") + Digits)
                  | (SignificantLiteral(".") + Digits))
SinglePeriod = SignificantLiteral(".")
BadExpr = (SignificantLiteral("junk that won't match") | SinglePeriod)
WrappingExpr = (BadExpr | DecimalLiteral | SignificantLiteral(".."))

"""
Here's my understanding of what should happen:

Given the parser definitions above, when parsing "..", WrappingExpr
should attempt to parse using BadExpr. The first parser tried by
BadExpr will obviously fail, as designed. The second parser,
SinglePeriod will succeed. BadExpr will then succeed if all=False,
but with all=True it will fail. WrappingExpr will then attempt to
parse using DecimalLiteral. The first form of DecimalLiteral requires
a digit prefix, which fails to match. The second form of DecimalLiteral
matches the period prefix but then fails because it is not followed by
digits. WrappingExpr should then attempt the SignificantLiteral("..")
parser and that parser should succeed but instead I get:

    ParseException: Parse failure: At position 0: expected "junk that won't match"
"""
print "all=False"
print WrappingExpr.parse_string("..", all=False)
print "all=True"
print WrappingExpr.parse_string("..", all=True)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions