Re: [Pyparsing] White space
Brought to you by:
ptmcg
From: Ralph C. <ra...@in...> - 2011-06-22 10:49:44
|
Hi, Paul McGuire wrote: > > from pyparsing import Word, alphas > > g = "$" + "as" + Word(alphas) > > g.parseString('$ as abc') > > ParseException: Expected "$as" (at char 0), (line:1, col:1) > > 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". I guess yet another way, keyword issue aside, is to alter the associativity with parenthesis? >>> g = "$" + ("as" + Word(alphas)) >>> print g {"$" {"as" W:(abcd...)}} >>> g.parseString('$ as abc') (['$', 'as', 'abc'], {}) >>> Cheers, Ralph. |