Good morning or good afternoon, depending where you are.
I wrote my first grammar today with PEG and I think it's an awesome tool.
Anyway, I ran into a sort of design limitation. My grammar describe a
simple template parser, the problem is that I would like to isolate
everything in the grammar file, and have a full template engine in that
file.
This translates to a very simple requirement: being able to export a
function to the public interface of the parser, which now contains only
parse().
Basically what my new method would do is something like:
function templateEngine(tpl, vars, callback) {
var node = this.parse(tpl);
if (node == "IfStatement") {
callback.call("IfStatement", this.resolve(node.condition, vars));
}
else if ( .... )
}
So as you can see it's very simple logic, that would otherwise need to go
into my main application file or yet another file with only this two
functions that wraps the generated parser.
I hope the purpose it's clear, I don't feel very expressive today. What I
want is a way to publish a function to the same level of the "parse:" call.
Any ideas?
Thank you. This tool rocks.