Thanks, that definitely helped. I forgot you could run arbitrary python
before the entry point.

I've got it parsing now, but the one issue I'm still running into is that
the syntax tree that comes back has a lot of junk nodes. The ToAST.transform
function will clean them up, but it seems to be not-rpython, and I don't
think there's any way I can call it before the entry point (since it's
processing the ast, not the grammar).

Is that class just hopeless? Or is there some way I can annotate it myself
in the code? (

On Mon, Apr 18, 2011 at 8:47 PM, Leonardo Santagada <santag...@gmail.com>wrote:

> IIRC you have to parse your grammar definition before your entry point
>
> for example in the module level somewhere you do
>
> try:
>    t = GFILE.read(mode='U')
>    regexs, rules, ToAST = parse_ebnf(t)
> except ParseError,e:
>    print e.nice_error_message(filename=str(GFILE),source=t)
>    raise
>
> parsef = make_parse_function(regexs, rules, eof=True)
>
> then parsef can be used inside your entry point. What I mean is,
> parse_ebnf and make_parse_function are not RPython, so they need to
> run before translation take place (remember that the pypy translator
> runs after import time, and it translates rpython from live python
> objects in memory).
>
> On Mon, Apr 18, 2011 at 10:15 PM, Ian Overgard <ian.overg...@gmail.com>
> wrote:
> > Hey guys,
> >
> > I was playing around with using the parser generator in rlib, but I'm
> having
> > some trouble figuring out how to get it to work in rpython (I did get one
> > working in normal python though). Is there a resource on using it
> somewhere,
> > or maybe just a few pointers? (I realize it's probably in a pretty beta
> > state, but so far it seems like the only parser-generator that's runnable
> in
> > rpython without really big changes). I was reading this:
> > http://codespeak.net/pypy/dist/pypy/doc/rlib.html#full-example but it
> seems
> > to cut off rather abruptly.
> >
> > It seems like you do something along the lines of instantiating one in
> > normal python, then asking it for its string representation and
> generating a
> > source file from that. Is that accurate? Or did I just manage to confuse
> > myself terribly while reading the prolog example?
> >
> > Thanks!
> > Ian
> >
> > _______________________________________________
> > pypy-dev@codespeak.net
> > http://codespeak.net/mailman/listinfo/pypy-dev
> >
>
>
>
> --
> Leonardo Santagada
>
_______________________________________________
pypy-dev@codespeak.net
http://codespeak.net/mailman/listinfo/pypy-dev

Reply via email to