Trampolining in Python is actually quite tricky to do correctly (including
exception handling). At least, I have found it so.
I started with the Python library test code, written by Tim Peters, and linked
in the Lepl credits. I'd suggest reading and understanding that before
looking at Lepl:
http://www.koders.com/python/fid9B99238B5452E1EDA851459C2F4B5FD19ECBAD17.aspx?s=mdef%3Amd5
Here are my initial notes on that:
http://www.acooke.org/cute/RecursiveG0.html
There are more notes here, but they're rather cryptic and include wrong turns:
http://www.acooke.org/cute/Avoidingth0.html
Looking at the notes I made over the years, I found this blog post, which was
quite popular, and which introduces the basic concepts, but it doesn't really
get to full co-routines:
http://eli.thegreenplace.net/2009/08/29/co-routines-as-an-alternative-to-state-machines/
That blog post references
http://www.dabeaz.com/coroutines/index.html which
also avoids the hardest parts (if I remember correctly), but which is also a
good place to start.
The above is a bit chaotic, so to summarise, I'd suggest reading the following
in the order given:
http://eli.thegreenplace.net/2009/08/29/co-routines-as-an-alternative-to-state-machines/
http://www.dabeaz.com/coroutines/index.html
http://www.koders.com/python/fid9B99238B5452E1EDA851459C2F4B5FD19ECBAD17.aspx?s=mdef%3Amd5
If you want to look at the Lepl code too, the trampoline itself is here -
http://www.acooke.org/lepl/api/lepl.core.parser-pysrc.html#trampoline - but
the coroutines are generated using decorators which makes them much less
readable -
http://www.acooke.org/lepl/api/lepl.matchers.support-pysrc.html -
so I doubt it's going to be very helpful.
Good luck - I'm happy to answer more questions either here or via direct email
if you want, but I am not very good at explaining things - I am a self taught
programmer and rely too much on intuition...
Andrew