From c1e1502d4368573225ba79d280f90901c454a37c Mon Sep 17 00:00:00 2001 From: David Majda Date: Thu, 8 May 2014 14:51:17 +0200 Subject: [PATCH] Utility functions cleanup: Cleanup lib/compiler/visitor.js --- lib/compiler/passes/generate-bytecode.js | 2 +- lib/compiler/passes/remove-proxy-rules.js | 2 +- lib/compiler/passes/report-left-recursion.js | 2 +- lib/compiler/passes/report-missing-rules.js | 2 +- lib/compiler/visitor.js | 9 +-------- 5 files changed, 5 insertions(+), 12 deletions(-) diff --git a/lib/compiler/passes/generate-bytecode.js b/lib/compiler/passes/generate-bytecode.js index 3fee60d..7588424 100644 --- a/lib/compiler/passes/generate-bytecode.js +++ b/lib/compiler/passes/generate-bytecode.js @@ -268,7 +268,7 @@ function generateBytecode(ast) { ); } - var generate = visitor.buildNodeVisitor({ + var generate = visitor.build({ grammar: function(node) { arrays.each(node.rules, generate); diff --git a/lib/compiler/passes/remove-proxy-rules.js b/lib/compiler/passes/remove-proxy-rules.js index 35b55f5..8978d06 100644 --- a/lib/compiler/passes/remove-proxy-rules.js +++ b/lib/compiler/passes/remove-proxy-rules.js @@ -24,7 +24,7 @@ function removeProxyRules(ast, options) { }; } - var replace = visitor.buildNodeVisitor({ + var replace = visitor.build({ grammar: replaceInSubnodes("rules"), rule: replaceInExpression, named: replaceInExpression, diff --git a/lib/compiler/passes/report-left-recursion.js b/lib/compiler/passes/report-left-recursion.js index ac4e44a..7c81f1d 100644 --- a/lib/compiler/passes/report-left-recursion.js +++ b/lib/compiler/passes/report-left-recursion.js @@ -19,7 +19,7 @@ function reportLeftRecursion(ast) { }; } - var check = visitor.buildNodeVisitor({ + var check = visitor.build({ grammar: checkSubnodes("rules"), rule: diff --git a/lib/compiler/passes/report-missing-rules.js b/lib/compiler/passes/report-missing-rules.js index 8e2018e..4cc4559 100644 --- a/lib/compiler/passes/report-missing-rules.js +++ b/lib/compiler/passes/report-missing-rules.js @@ -13,7 +13,7 @@ function reportMissingRules(ast) { return function(node) { arrays.each(node[propertyName], check); }; } - var check = visitor.buildNodeVisitor({ + var check = visitor.build({ grammar: checkSubnodes("rules"), rule: checkExpression, named: checkExpression, diff --git a/lib/compiler/visitor.js b/lib/compiler/visitor.js index bd013a9..fe65e6c 100644 --- a/lib/compiler/visitor.js +++ b/lib/compiler/visitor.js @@ -1,13 +1,6 @@ /* Simple AST node visitor builder. */ var visitor = { - /* - * Builds a node visitor -- a function which takes a node and any number of - * other parameters, calls an appropriate function according to the node type, - * passes it all its parameters and returns its value. The functions for - * various node types are passed in a parameter to |buildNodeVisitor| as a - * hash. - */ - buildNodeVisitor: function(functions) { + build: function(functions) { return function(node) { return functions[node.type].apply(null, arguments); };