Re: [Pyparsing] empty lines and restOfLine comments
Brought to you by:
ptmcg
From: <pt...@au...> - 2005-04-01 03:50:30
|
To use restOfLine, you need to join using "\n", not "". The \n characters tell restOfLine when to stop. I'll try to pull together a Dict example with your input data. -- Paul ----- Original Message ----- From: Robert Pollak <rob...@gm...> Date: Thursday, March 31, 2005 5:22 pm Subject: [Pyparsing] empty lines and restOfLine comments > 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']? > > > ------------------------------------------------------- > This SF.net email is sponsored by Demarc: > A global provider of Threat Management Solutions. > Download our HomeAdmin security software for free today! > http://www.demarc.com/Info/Sentarus/hamr30 > _______________________________________________ > Pyparsing-users mailing list > Pyp...@li... > https://lists.sourceforge.net/lists/listinfo/pyparsing-users > |