I need to parse some statements but want the flexibility of using multiple words to signal the of the statement.
eg.
string = """
start some statement end
other stuff in between
start some other statement.
other stuff in between
start another statement
"""
in this case end
, .
and end of line are the tokens that will signal the end
of the statement I am looking for.
I tried the following:
from pyparsing import restOfLine, SkipTo
skip_to_end_of_line = restOfLine
skip_to_dot = SkipTo('.', include=False)
skip_to_end = SkipTo('end', include=False)
statement = 'start' + skip_to_end_of_line^skip_to_dot^skip_to_end
statement.searchString(string)
([(['start some statement end\nother stuff in between\nstart some other statement'], {}), (['start', ' another statement'], {})], {})
By using the OR function it returns the largest string if there are more than two matches, I would like OR to return the shortest string resulting in
([(['start', ' some statement end'], {}), (['start', ' some other statement.'], {}), (['start', ' another statement'], {})], {})