Re: help with pyparsing
- From: Paul McGuire <ptmcg@xxxxxxxxxxxxx>
- Date: Wed, 31 Oct 2007 08:13:30 -0700
On Oct 31, 6:59 am, Neal Becker <ndbeck...@xxxxxxxxx> 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
.
- References:
- help with pyparsing
- From: Neal Becker
- help with pyparsing
- Prev by Date: Re: shouldn't 'string'.find('ugh') return 0, not -1 ?
- Next by Date: Re: shouldn't 'string'.find('ugh') return 0, not -1 ?
- Previous by thread: help with pyparsing
- Next by thread: Creating a temporary file in Python
- Index(es):
Relevant Pages
|