Possible to Generate Source from Parse Tree?

Jul 21, 2012 at 6:18 PM
Edited Jul 21, 2012 at 6:19 PM

Just curious if anyone has some ideas about this.

I'm using a grammar for people to describe business data. We take the grammar, parse with Irony, turn that to an object model for persistence / use in the app.

A very simplistic example is using hours a store is open, given simple source like:

Mon - Fri: 10am - 8pm
Sat, Sun: Closed

We would turn this in to something the program can use for determining open/closed state of a store.

What I'm trying to do now is to actually take the object representation of something like this and turn it back in to source for export / viewing / editing, etc.

Anyone have any thoughts on how to proceed?  If not through Irony, what would be my best bet?

(note this is a very simplistic example, I'm doing much more complicated things where using Irony is a bit more useful, this obviously could be done with Regex, etc.)

Jul 23, 2012 at 6:09 PM

PrettyPrinting (generating well-formatted source from ParseTree) is on my to do list, it sure should be core feature, but it's not for now. But it's not difficult to implement for a particular language. Just iterate ParseTree (or Ast tree if you generate it), and write out well-formatted string representations of each node.