Pyparsing grammar incorrect

23 views Asked by At

Why does the following pyparsing grammar not parse the string correctly?

import pyparsing as pp

token_any = pp.Word(pp.printables)
comment = pp.Literal("*") + token_any("comment text") + "*"

res = comment.parse_string("""*asd*""")
print(res.dump())

The error is Expected '*', found end of text (at char 5), (line:1, col:6). If I understand this correctly, the comment text matches to the end of the string. But shouldn't the next step in the parsing be to try to match the remaining part of the rule, backing up until it does? i.e. this should match the regex \*.*\* (excluding non-printable characters, which my input string doesn't have)

0

There are 0 answers