help with pyparsing

N

Neal Becker

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
 
P

Paul McGuire

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top