From 6cd5bdc5e60142c7fb86f7fc1c1c628202f0f721 Mon Sep 17 00:00:00 2001 From: David Majda Date: Mon, 3 Oct 2011 13:50:22 +0200 Subject: [PATCH] Passes now do not return anything (they always modify the AST in-place) --- src/compiler.js | 2 +- src/passes.js | 10 +++------- test/passes-test.js | 4 +++- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/compiler.js b/src/compiler.js index cd6ff8b..1601876 100644 --- a/src/compiler.js +++ b/src/compiler.js @@ -23,7 +23,7 @@ PEG.compiler = { } 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); diff --git a/src/passes.js b/src/passes.js index 6d9f5b1..427aa03 100644 --- a/src/passes.js +++ b/src/passes.js @@ -1,8 +1,8 @@ /* * 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 - * modified in-place by the pass. The order in which the passes are run is - * specified in |PEG.compiler.compile| and should be the same as the order of + * is a function that is passed the AST and does not return anything. The AST + * can be modified in-place by the pass. The order in which the passes are run + * is specified in |PEG.compiler.compile| and should be the same as the order of * definitions here. */ PEG.compiler.passes = { @@ -74,8 +74,6 @@ PEG.compiler.passes = { delete ast.rules[name]; } } - - return ast; }, /* @@ -154,7 +152,5 @@ PEG.compiler.passes = { }); compute(ast); - - return ast; } }; diff --git a/test/passes-test.js b/test/passes-test.js index fc8d765..5ec4f60 100644 --- a/test/passes-test.js +++ b/test/passes-test.js @@ -143,7 +143,9 @@ test("removes proxy rules", function() { for (var i = 0; i < cases.length; i++) { 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); } });