grammar = Literal("from") + Literal(":") + Word(alphas)
The grammar needs to reject from : mary
and only accept from:mary
i.e. without any interleaving spaces. How can I enforce this in pyparsing ? Thanks
Can you use Combine
?
grammar = Combine(Literal("from") + Literal(":") + Word(alphas))
So then:
EDIT in response to your comment.
Really?
>>> grammar = pyparsing.Combine(Literal("from") + Literal(":") + Word(pyparsing.alphas))
>>> grammar.parseString('from : mary')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/pymodules/python2.6/pyparsing.py", line 1076, in parseString
raise exc
pyparsing.ParseException: Expected ":" (at char 4), (line:1, col:5)
>>> grammar.parseString('from:mary')
(['from:mary'], {})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With