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