I find that the use of ZeroOrMore() seems to suppress
exceptions. The following little script illustrates this
from pyparsing import *
expression = Word(alphas) + ZeroOrMore("+" + Word(alphas))
if __name__ == "__main__":
results = expression.parseString('a-b')
except Exception, inst:
results in ['a'] being printed to screen.
If I redefine
expression = Word(alphas) + "+" + Word(alphas)
I do get an exception as expected:
%Expected "+" (at char 1), (line:1, col:2)
Is there some way to still get the ParseException?
Thanks in advance,
Log in to post a comment.