|
Graham Wakefield wrote:
Before I try to do this, I was wondering if somebody could tell me whether it is even possible... I'd like to graphically render an lpeg grammar, by traversing the grammar nodes and creating a dot-syntax (GraphViz) representation of the nodes and relationships. I don't necessarily have access to how the grammar was made (assume it was passed to me externally), so I just wanted to know if it is possible to query the grammar structure directly by stepping through key-value pairs, or whether some parts of it are opaque?
I can't tell whether it's useful for you or far too low level but the LPeg module includes a print function which prints IIRC a representation of an LPeg pattern's byte code. I don't see lpeg.print() in the manual but last time I checked (just now with Ubuntu's liblua5.1-lpeg2 package) it worked. I'm not sure whether lpeg.print() supports io.output() so that could be an interesting exercise :-).
Alternatively you could write a "proxy module" that looks like LPeg but also maintains an internal tree of grammar nodes which you can query however you want to.
- Peter Odding