[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: LPeg - AST / Tree walker?
- From: Lode Hoste <zillode@...>
- Date: Thu, 31 Mar 2011 10:39:58 +0200
Hi,
After watching the talk about LPeg I was inspired to use it to
describe the grammar of my DSL.
I now have a complete PEG grammar (LPEG.RE) of about 300 lines, but
can't find a good pointer on how to generate an AST or parse tree with
callbacks from it.
Other PEG implementations do offer this functionality (e.g.
http://boshi.inimino.org/3box/PanPG/build/demo.html).
My manual work-around currently looks like this:
...
Constant <- {<String> / <Integer> / <Float> / <Symbol>
/ <InstanceName>} -> constant
...
grammar = re.compile(dsl, {
constant = function(c) return {"constant", c} end,
})
Do I have to do this for every non-terminal I specified? Is there
a better way to do this?
Thanks,
Lode