From: Werner <wernerfbd@gm...> - 2014-05-23 11:40:12
I like to parse many .py files and check if any of the following is
present in it:
test = """# Tags: phoenix-port, unittest, documented, py3-port"""
A file might or might not have this comment line somewhere at the top,
and it might have one or more of the tags.
I like to report on the file name and what tags are present in it, the
use of this is a check list of what modules have been converted/been done.
On the above test string I tried this, but it only reports on the first.
allTags = pp.Literal("# Tags:") +\
result = allTags.parseString(test)
The other problem I have when using 'parseFile' is how to tell it to
ignore everything before or after, or even all if the '# Tags:' line is
Hopefully someone can push me in the right direction.
From: Werner <wernerfbd@gm...> - 2014-05-24 12:43:32
Made a bit of progress, following works for my test string, but doesn't
yet for when I parse files.
tagStart = pp.Literal("# Tags:").setDebug()
otherStuff = pp.lineStart + pp.restOfLine
def aTagLineAction(s, l, t):
aTagLine = tagStart + pp.restOfLine
allLines = pp.OneOrMore(otherStuff | aTagLine)
result = allLines.parseString(test)
From: Werner <wernerfbd@gm...> - 2014-05-24 15:04:34
On 5/23/2014 13:45, Diez B. Roggisch wrote:
> for that problem (if it's that "simple", meaning one line, strict conventions) I wouldn't bother using pyparsing.
> Just readline, and string-methods.
Good point, will do that, but I am still intrigued why my code in the
last post is not handling correctly the none matching lines, i.e. I like
to just have them ignored.