Allow passing options to |PEG.buildParser|

These get passed down to the emitter templates.
redux
David Majda 13 years ago
parent f2f88b87ea
commit 9615eb4bb6

@ -17,14 +17,14 @@ PEG.compiler = {
* during the generation and some may protrude to the generated parser and
* cause its malfunction.
*/
compile: function(ast) {
compile: function(ast, options) {
var that = this;
each(this.appliedPassNames, function(passName) {
that.passes[passName](ast);
});
var source = this.emitter(ast);
var source = this.emitter(ast, options);
var result = eval(source);
result._source = source;

@ -1,5 +1,7 @@
/* Emits the generated code for the AST. */
PEG.compiler.emitter = function(ast) {
PEG.compiler.emitter = function(ast, options) {
options = options || {};
var Codie = (function(undefined) {
function stringEscape(s) {
function hex(ch) { return ch.charCodeAt(0).toString(16).toUpperCase(); }
@ -674,11 +676,12 @@ PEG.compiler.emitter = function(ast) {
})();
function fill(name, vars) {
vars.string = quote;
vars.pluck = pluck;
vars.keys = keys;
vars.values = values;
vars.emit = emit;
vars.string = quote;
vars.pluck = pluck;
vars.keys = keys;
vars.values = values;
vars.emit = emit;
vars.options = options;
return templates[name](vars);
}

@ -17,8 +17,8 @@ var PEG = {
* errors are detected during the generation and some may protrude to the
* generated parser and cause its malfunction.
*/
buildParser: function(grammar) {
return PEG.compiler.compile(PEG.parser.parse(grammar));
buildParser: function(grammar, options) {
return PEG.compiler.compile(PEG.parser.parse(grammar), options);
}
};

Loading…
Cancel
Save