help with pyparsing

Paul McGuire ptmcg at austin.rr.com
Wed Oct 31 16:13:30 CET 2007


On Oct 31, 6:59 am, Neal Becker <ndbeck... at gmail.com> wrote:
> I'm just trying out pyparsing.  I get stack overflow on my first try.  Any
> help?
>
> #/usr/bin/python
>
> from pyparsing import Word, alphas, QuotedString, OneOrMore, delimitedList
>
> first_line = '[' + delimitedList (QuotedString) + ']'
>
> def main():
>     string = '''[ 'a', 'b', 'cdef']'''
>     greeting = first_line.parseString (string)
>     print greeting
>
> if __name__ == "__main__":
>     main()
>
> /usr/lib/python2.5/site-packages/pyparsing.py:2727: SyntaxWarning: Cannot
> add element of type <type 'type'> to ParserElement
>   return ( expr + ZeroOrMore( Suppress( delim ) + expr ) ).setName(dlName)
> /usr/lib/python2.5/site-packages/pyparsing.py:1008: SyntaxWarning: Cannot
> add element of type <type 'type'> to ParserElement
>   return other + self
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "/usr/tmp/python-k3AVeY.py", line 5, in <module>
>     first_line = '[' + delimitedList (QuotedString) + ']'
>   File "/usr/lib/python2.5/site-packages/pyparsing.py", line 2727, in
> delimitedList
>     return ( expr + ZeroOrMore( Suppress( delim ) + expr ) ).setName(dlName)
>   File "/usr/lib/python2.5/site-packages/pyparsing.py", line 1008, in
> __radd__
>     return other + self
>   File "/usr/lib/python2.5/site-packages/pyparsing.py", line 1008, in
> __radd__
>     return other + self

Oh!  You are so close!

QuotedString is a class.  delimitedList does not accept a class, but
an expression, which is usually created using instances of the
pyparsing classes.  quotedString is an expression, defining a pretty
complex quoted string syntax (single or double-quoted string).

Just change QuotedString to quotedString throughout your script, and
try again.

-- Paul




More information about the Python-list mailing list