Re: Pretty Scheme, ??? Python

2007-07-03 Thread Neil Cerutti
On 2007-07-03, Paul McGuire <[EMAIL PROTECTED]> wrote: > 2. Change the parse actions to deref the 0'th element of t for > binop and with_. > > num.setParseAction(lambda t: Num(int(t.number))) > id_.setParseAction(lambda t: Id(t.name)) > binop.setParseAction(lambda t: BinOp(t[0].op, t[0].lhs, t[0].r

Re: Pretty Scheme, ??? Python

2007-07-03 Thread Paul McGuire
By the way, the next release of pyparsing will allow you to shortcut all of these .setResultsName calls, using this notation instead: binop = ( LPAR + oneOf("+ -")('op') + wae('lhs') + wae('rhs') + RPAR ) with_ = ( LPAR + "with" + LPAR + id_('bound_i

Re: Pretty Scheme, ??? Python

2007-07-03 Thread Paul McGuire
On Jul 3, 11:08 am, Neil Cerutti <[EMAIL PROTECTED]> wrote: > > C:\WINNT\system32\cmd.exe /c python wae.py > ** > File "wae.py", line 6, in __main__ > Failed example: > parse('(+ 3 45)') > Exception raised: > Traceback (mos

Re: Pretty Scheme, ??? Python

2007-07-03 Thread Neil Cerutti
On 2007-07-03, Paul McGuire <[EMAIL PROTECTED]> wrote: > Here is my alternative solution (not using results names). I used > the base WAE class to accept the tokens as the initialization var, > then unpack the list into variables in each respective calc() > method. I did not see the need for a su

Re: Pretty Scheme, ??? Python

2007-07-03 Thread Paul McGuire
Neil - >> The above shadows 'id'; I suppose 'ident' would be better. Doh! I found the id() shadowing later, changed my var to id_ so as not to stray from your BNF too much. >> How can I make it barf for testcases like '(+ 2 3))'? It doesn't >> seem to expect an Eof. To force parsing to the end of

Re: Pretty Scheme, ??? Python

2007-07-03 Thread Neil Cerutti
On 2007-07-02, Paul McGuire <[EMAIL PROTECTED]> wrote: > On Jul 2, 3:56 pm, Neil Cerutti <[EMAIL PROTECTED]> wrote: > from pyparsing import * It's always good when your messages start like that. ;) > """ > Ok, here is the step-by-step, beginning with your posted BNF. > (Based on your test cases,

Re: Pretty Scheme, ??? Python

2007-07-02 Thread Paul McGuire
On Jul 2, 6:28 pm, Paul McGuire <[EMAIL PROTECTED]> wrote: > On Jul 2, 3:56 pm, Neil Cerutti <[EMAIL PROTECTED]> wrote: > > > > > > > On 2007-07-02, Laurent Pointal <[EMAIL PROTECTED]> wrote: > > > > Neil Cerutti wrote: > > >> How can I make the Python more idiomatic Python? > > > > Have you taken

Re: Pretty Scheme, ??? Python

2007-07-02 Thread Paul McGuire
On Jul 2, 3:56 pm, Neil Cerutti <[EMAIL PROTECTED]> wrote: > On 2007-07-02, Laurent Pointal <[EMAIL PROTECTED]> wrote: > > > Neil Cerutti wrote: > >> How can I make the Python more idiomatic Python? > > > Have you taken a look at pyparsing ? > > Yes, I have it. PyParsing has, well, so many convenie

Re: Pretty Scheme, ??? Python

2007-07-02 Thread Neil Cerutti
On 2007-07-02, Laurent Pointal <[EMAIL PROTECTED]> wrote: > Neil Cerutti wrote: >> How can I make the Python more idiomatic Python? > > Have you taken a look at pyparsing ? Yes, I have it. PyParsing has, well, so many convenience features they seem to shout down whatever the core features are, and

Re: Pretty Scheme, ??? Python

2007-07-02 Thread Laurent Pointal
Neil Cerutti wrote: ... > How can I make the Python more idiomatic Python? Have you taken a look at pyparsing ? http://pyparsing.wikispaces.com/ -- http://mail.python.org/mailman/listinfo/python-list