Make the code emitter a compiler pass

This gives the compiler a more regular structure.
redux
David Majda 13 years ago
parent 44852fa6b4
commit 4f86fca3d7

@ -8,7 +8,8 @@ PEG.compiler = {
"reportLeftRecursion", "reportLeftRecursion",
"removeProxyRules", "removeProxyRules",
"computeVarNames", "computeVarNames",
"computeParams" "computeParams",
"generateCode"
], ],
/* /*
@ -24,7 +25,7 @@ PEG.compiler = {
that.passes[passName](ast, options); that.passes[passName](ast, options);
}); });
var source = this.emitter(ast, options); var source = ast.code;
var result = eval(source); var result = eval(source);
result._source = source; result._source = source;
@ -33,4 +34,3 @@ PEG.compiler = {
}; };
// @include "compiler/passes.js" // @include "compiler/passes.js"
// @include "compiler/emitter.js"

@ -12,3 +12,4 @@ PEG.compiler.passes = {};
// @include "passes/remove-proxy-rules.js" // @include "passes/remove-proxy-rules.js"
// @include "passes/compute-var-names.js" // @include "passes/compute-var-names.js"
// @include "passes/compute-params.js" // @include "passes/compute-params.js"
// @include "passes/generate-code.js"

@ -1,5 +1,5 @@
/* Emits the generated code for the AST. */ /* Generates the parser code. */
PEG.compiler.emitter = function(ast, options) { PEG.compiler.passes.generateCode = function(ast, options) {
options = options || {}; options = options || {};
if (options.cache === undefined) { if (options.cache === undefined) {
options.cache = false; options.cache = false;
@ -885,5 +885,5 @@ PEG.compiler.emitter = function(ast, options) {
} }
}); });
return emit(ast); ast.code = emit(ast);
}; };
Loading…
Cancel
Save