From bfaad70899c0973c61f1c3be5468c8c81a4e0063 Mon Sep 17 00:00:00 2001 From: David Majda Date: Thu, 8 May 2014 14:46:11 +0200 Subject: [PATCH] Utility functions cleanup: Cleanup lib/compiler/asts.js --- lib/compiler/asts.js | 4 ++-- lib/compiler/passes/generate-bytecode.js | 2 +- lib/compiler/passes/generate-javascript.js | 6 +++--- lib/compiler/passes/report-left-recursion.js | 2 +- lib/compiler/passes/report-missing-rules.js | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/compiler/asts.js b/lib/compiler/asts.js index d7d59f6..7c3a44f 100644 --- a/lib/compiler/asts.js +++ b/lib/compiler/asts.js @@ -2,11 +2,11 @@ var arrays = require("../utils/arrays"); /* AST utilities. */ var asts = { - findRuleByName: function(ast, name) { + findRule: function(ast, name) { return arrays.find(ast.rules, function(r) { return r.name === name; }); }, - indexOfRuleByName: function(ast, name) { + indexOfRule: function(ast, name) { return arrays.indexOf(ast.rules, function(r) { return r.name === name; }); } }; diff --git a/lib/compiler/passes/generate-bytecode.js b/lib/compiler/passes/generate-bytecode.js index 633baf1..3fee60d 100644 --- a/lib/compiler/passes/generate-bytecode.js +++ b/lib/compiler/passes/generate-bytecode.js @@ -509,7 +509,7 @@ function generateBytecode(ast) { }, rule_ref: function(node) { - return [op.RULE, asts.indexOfRuleByName(ast, node.name)]; + return [op.RULE, asts.indexOfRule(ast, node.name)]; }, literal: function(node) { diff --git a/lib/compiler/passes/generate-javascript.js b/lib/compiler/passes/generate-javascript.js index 7b9c60b..8da5d9a 100644 --- a/lib/compiler/passes/generate-javascript.js +++ b/lib/compiler/passes/generate-javascript.js @@ -634,7 +634,7 @@ function generateJavaScript(ast, options) { if (options.cache) { parts.push(indent2( - generateCacheHeader(asts.indexOfRuleByName(ast, rule.name)) + generateCacheHeader(asts.indexOfRule(ast, rule.name)) )); } @@ -696,10 +696,10 @@ function generateJavaScript(ast, options) { startRuleIndices = '{ ' + arrays.map( options.allowedStartRules, - function(r) { return r + ': ' + asts.indexOfRuleByName(ast, r); } + function(r) { return r + ': ' + asts.indexOfRule(ast, r); } ).join(', ') + ' }'; - startRuleIndex = asts.indexOfRuleByName(ast, options.allowedStartRules[0]); + startRuleIndex = asts.indexOfRule(ast, options.allowedStartRules[0]); parts.push([ ' peg$startRuleIndices = ' + startRuleIndices + ',', diff --git a/lib/compiler/passes/report-left-recursion.js b/lib/compiler/passes/report-left-recursion.js index 480de26..ac4e44a 100644 --- a/lib/compiler/passes/report-left-recursion.js +++ b/lib/compiler/passes/report-left-recursion.js @@ -55,7 +55,7 @@ function reportLeftRecursion(ast) { "Left recursion detected for rule \"" + node.name + "\"." ); } - check(asts.findRuleByName(ast, node.name), appliedRules); + check(asts.findRule(ast, node.name), appliedRules); }, literal: nop, diff --git a/lib/compiler/passes/report-missing-rules.js b/lib/compiler/passes/report-missing-rules.js index b02ed14..8e2018e 100644 --- a/lib/compiler/passes/report-missing-rules.js +++ b/lib/compiler/passes/report-missing-rules.js @@ -32,7 +32,7 @@ function reportMissingRules(ast) { rule_ref: function(node) { - if (!asts.findRuleByName(ast, node.name)) { + if (!asts.findRule(ast, node.name)) { throw new GrammarError( "Referenced rule \"" + node.name + "\" does not exist." );