Re: [Pyparsing] White space
Brought to you by:
ptmcg
From: Paul M. <pt...@au...> - 2011-06-22 00:16:50
|
Here's your definition of g >>> g = "$" + "as" + Word(alphas) >>> print g {"$as" W:(abcd...)} "$" + "as" gets interpreted by Python as the addition of two strings, resulting in "$as". Force the leading "$" to be a pyparsing Literal, and then you'll get a better parser: >>> g = Literal("$") + "as" + Word(alphas) >>> print g {{"$" "as"} W:(abcd...)} -- Paul -----Original Message----- From: cathal coffey [mailto:cof...@gm...] Sent: Tuesday, June 21, 2011 5:35 PM To: pyp...@li... Subject: [Pyparsing] White space Hello, I have a quick question. Shouldn't the below grammar accept the given string? from pyparsing import Word, alphas g = "$" + "as" + Word(alphas) g.parseString('$ as abc') ParseException: Expected "$as" (at char 0), (line:1, col:1) I want the grammar to accept $ followed by: any number of spaces followed by: as followed by: any number of spaces followed by: any string of characters. The reason I am confused is that the following grammar accepts regardless of white space... why doesn't the above? g = "as" + Word(alphas) g.parseString(' as abc ') Out: (['as', 'abc'], {}) Kind regards, Cathal ---------------------------------------------------------------------------- -- EditLive Enterprise is the world's most technically advanced content authoring tool. Experience the power of Track Changes, Inline Image Editing and ensure content is compliant with Accessibility Checking. http://p.sf.net/sfu/ephox-dev2dev _______________________________________________ Pyparsing-users mailing list Pyp...@li... https://lists.sourceforge.net/lists/listinfo/pyparsing-users |