[Pyparsing] empty lines and restOfLine comments
Brought to you by:
ptmcg
From: Robert P. <rob...@gm...> - 2005-03-31 23:22:45
|
Hello! I am a(nother) Python and pyparsing newbie. I want to use pyparsing-1.3 to parse files that look like the following snippet, enclosed in triple quotes: """ / Flux DSS-DESIGNER, Sample Data / Projekt: Set 1 // HYDRAULIK & QUERPROFIL-DATEN floin_file = set_1.floin floab_file = set_1.floab floout_file = floout flores_file = flores // REGELUNG ctrlin_file = set_1.ctrlin ctrlres_file = ctrl_res """ Lines starting with a slash (comments) should be ignored. I have been reading (either on this list or in the sf help forum - I cannot find it right now) that empty lines can only be read using grammar.parseString("".join(inputFile.readlines())), like in the configParse.py example. But when everything is joined like this, how can the end of the comment lines be determined? I am currently stuck at: chars = alphanums + "_" + "." + "\\" assignment = Word(chars) + "=" + Word(chars) line = (assignment | restOfLine) + LineEnd grammar = ZeroOrMore(line) This does not even run through - I get Traceback (most recent call last): File "parseCfg.py", line 6, in ? line = (assignment | restOfLine) + LineEnd File "/usr/lib/python2.3/site-packages/pyparsing.py", line 635, in __add__ return And( [ self, other ] ) File "/usr/lib/python2.3/site-packages/pyparsing.py", line 1306, in __init__ if not e.mayReturnEmpty: AttributeError: type object 'LineEnd' has no attribute 'mayReturnEmpty' When I just use "line = assignment | restOfLine" instead, the parser runs into an infinite loop on the snippet above, with or without the "join readlines" trick. Thank you for any help, Robert Btw, how can I use a pyparsing.Dict here to get direct access e.g. to myParseResult['floin_file']? |