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)