Code: Select all
data = """\
map=1
sub=1
int=99
foo=bar
sub=2
foo=bar
int=99
bar=qux
"""
Code: Select all
from pyparsing import *
stmt = Forward()
suite = IndentedBlock(stmt)
identifier = Word(alphas, alphanums)
key = Combine(identifier + "=" + Word(nums))
definition = key + suite
rhs = Regex(r"[a-z0-9]+")
lhs = identifier + Suppress("=") + rhs
stmt
Der resultierende Parse-Tree ist fast korrekt: < /p>
['map=1', ['sub=1', ['int=99', ['foo', 'bar']], 'sub=2', ['foo', 'bar', 'int=99', ['bar', 'qux']]]]
< /code>
Wie kann ich diese Mehrdeutigkeit beseitigen? Vielleicht eine Art negatives Aussehen, das?