Passes now do not return anything (they always modify the AST in-place)

redux
David Majda 13 years ago
parent 3983f46d5d
commit 6cd5bdc5e6

@ -23,7 +23,7 @@ PEG.compiler = {
} }
for (i = 0; i < PASS_NAMES.length; i++) { for (i = 0; i < PASS_NAMES.length; i++) {
ast = this.passes[PASS_NAMES[i]](ast); this.passes[PASS_NAMES[i]](ast);
} }
var source = this.emitter(ast); var source = this.emitter(ast);

@ -1,8 +1,8 @@
/* /*
* Optimalization passes made on the grammar AST before compilation. Each pass * Optimalization passes made on the grammar AST before compilation. Each pass
* is a function that is passed the AST and returns a new AST. The AST can be * is a function that is passed the AST and does not return anything. The AST
* modified in-place by the pass. The order in which the passes are run is * can be modified in-place by the pass. The order in which the passes are run
* specified in |PEG.compiler.compile| and should be the same as the order of * is specified in |PEG.compiler.compile| and should be the same as the order of
* definitions here. * definitions here.
*/ */
PEG.compiler.passes = { PEG.compiler.passes = {
@ -74,8 +74,6 @@ PEG.compiler.passes = {
delete ast.rules[name]; delete ast.rules[name];
} }
} }
return ast;
}, },
/* /*
@ -154,7 +152,5 @@ PEG.compiler.passes = {
}); });
compute(ast); compute(ast);
return ast;
} }
}; };

@ -143,7 +143,9 @@ test("removes proxy rules", function() {
for (var i = 0; i < cases.length; i++) { for (var i = 0; i < cases.length; i++) {
var ast = PEG.parser.parse(cases[i].grammar); var ast = PEG.parser.parse(cases[i].grammar);
deepEqual(PEG.compiler.passes.removeProxyRules(ast), cases[i].ast); PEG.compiler.passes.removeProxyRules(ast);
deepEqual(ast, cases[i].ast);
} }
}); });

Loading…
Cancel
Save