Thread: [Pyparsing] pyparsing bug or operator error with cStyleComment?
Brought to you by:
ptmcg
From: Paul W. <pa...@xe...> - 2009-07-28 03:26:46
|
Hi, I'm trying to build a better working parser for named.conf files, and ran into a strange issue while parsing various kinds of comments. I think the below examples shows what I think is a bug: from pyparsing import * stuff = """ /* comment 1*/ // test // test2 /* test3 indeed */ /* test4 */ """ comment1 = Group(Word("//") + restOfLine) comment2 = Group(Word("#") + restOfLine) comment3 = cStyleComment comment = OneOrMore(comment1 | comment2 | comment3) parser = OneOrMore(comment) res = parser.parseString(stuff,parseAll=True) This gives me: pyparsing.ParseException: Expected end of text (at char 46), (line:7, col:4) I think that "cStyleComment" comments do not correctly work over multiple lines. Paul |
From: Paul W. <pa...@xe...> - 2009-07-28 03:43:24
|
Hi, I'm trying to build a better working parser for named.conf files, and ran into a strange issue while parsing various kinds of comments. I think the below examples shows what I think is a bug: from pyparsing import * stuff = """ /* comment 1*/ // test // test2 /* test3 indeed */ /* test4 */ """ comment1 = Group(Word("//") + restOfLine) comment2 = Group(Word("#") + restOfLine) comment3 = cStyleComment comment = OneOrMore(comment1 | comment2 | comment3) parser = OneOrMore(comment) res = parser.parseString(stuff,parseAll=True) This gives me: pyparsing.ParseException: Expected end of text (at char 46), (line:7, col:4) I think that "cStyleComment" comments do not correctly work over multiple lines. Paul |
From: spir <den...@fr...> - 2009-07-28 11:19:46
|
Le Mon, 27 Jul 2009 23:05:59 -0400 (EDT), Paul Wouters <pa...@xe...> s'exprima ainsi: > > Hi, > > I'm trying to build a better working parser for named.conf files, and ran > into a strange issue while parsing various kinds of comments. I think the > below examples shows what I think is a bug: > > from pyparsing import * > > stuff = """ > /* comment 1*/ > > // test > // test2 > /* test3 > indeed */ > /* test4 > */ > """ > > comment1 = Group(Word("//") + restOfLine) > comment2 = Group(Word("#") + restOfLine) > comment3 = cStyleComment > comment = OneOrMore(comment1 | comment2 | comment3) > parser = OneOrMore(comment) > > res = parser.parseString(stuff,parseAll=True) > > This gives me: > > pyparsing.ParseException: Expected end of text (at char 46), (line:7, col:4) > I think that "cStyleComment" comments do not correctly work over multiple > lines. > > Paul well, you're wrong about cStyleComment, at least: =========== from pyparsing import cStyleComment stuff = """/* test test test */""" print cStyleComment.parseString(stuff) # ==> '/* test\n test \ntest */' =========== Also, comment's format should be simply "comment = comment1 | comment2 | comment3". See also below: =========== from pyparsing import cStyleComment,OneOrMore stuff = """ /* test3 indeed */ /* test4 */""" print OneOrMore(cStyleComment).parseString(stuff) # ==> ['/* test3\n indeed */', '/* test4\n*/'] =========== This said, I couldn't find the reason of the bug. Denis ------ la vita e estrany |