Utility functions cleanup: Cleanup lib/compiler/asts.js

redux
David Majda 11 years ago
parent 05f97f444d
commit bfaad70899

@ -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; });
}
};

@ -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) {

@ -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 + ',',

@ -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,

@ -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."
);

Loading…
Cancel
Save