diff --git a/lib/compiler/asts.js b/lib/compiler/asts.js index 102e354..67344de 100644 --- a/lib/compiler/asts.js +++ b/lib/compiler/asts.js @@ -13,50 +13,50 @@ var asts = { return arrays.indexOf(ast.rules, function(r) { return r.name === name; }); }, - matchesEmpty: function(ast, node) { - function matchesTrue() { return true; } - function matchesFalse() { return false; } + alwaysAdvancesOnSuccess: function(ast, node) { + function advancesTrue() { return true; } + function advancesFalse() { return false; } - function matchesExpression(node) { - return matches(node.expression); + function advancesExpression(node) { + return advances(node.expression); } - var matches = visitor.build({ - rule: matchesExpression, + var advances = visitor.build({ + rule: advancesExpression, choice: function(node) { - return arrays.some(node.alternatives, matches); + return arrays.every(node.alternatives, advances); }, - action: matchesExpression, + action: advancesExpression, sequence: function(node) { - return arrays.every(node.elements, matches); + return arrays.some(node.elements, advances); }, - labeled: matchesExpression, - text: matchesExpression, - simple_and: matchesTrue, - simple_not: matchesTrue, - optional: matchesTrue, - zero_or_more: matchesTrue, - one_or_more: matchesExpression, - semantic_and: matchesTrue, - semantic_not: matchesTrue, + labeled: advancesExpression, + text: advancesExpression, + simple_and: advancesFalse, + simple_not: advancesFalse, + optional: advancesFalse, + zero_or_more: advancesFalse, + one_or_more: advancesExpression, + semantic_and: advancesFalse, + semantic_not: advancesFalse, rule_ref: function(node) { - return matches(asts.findRule(ast, node.name)); + return advances(asts.findRule(ast, node.name)); }, literal: function(node) { - return node.value === ""; + return node.value !== ""; }, - "class": matchesFalse, - any: matchesFalse + "class": advancesTrue, + any: advancesTrue }); - return matches(node); + return advances(node); } }; diff --git a/lib/compiler/passes/report-infinite-loops.js b/lib/compiler/passes/report-infinite-loops.js index 9f8f11c..7d23936 100644 --- a/lib/compiler/passes/report-infinite-loops.js +++ b/lib/compiler/passes/report-infinite-loops.js @@ -11,13 +11,13 @@ var GrammarError = require("../../grammar-error"), function reportInfiniteLoops(ast) { var check = visitor.build({ zero_or_more: function(node) { - if (asts.matchesEmpty(ast, node.expression)) { + if (!asts.alwaysAdvancesOnSuccess(ast, node.expression)) { throw new GrammarError("Infinite loop detected.", node.location); } }, one_or_more: function(node) { - if (asts.matchesEmpty(ast, node.expression)) { + if (!asts.alwaysAdvancesOnSuccess(ast, node.expression)) { throw new GrammarError("Infinite loop detected.", node.location); } } diff --git a/lib/compiler/passes/report-left-recursion.js b/lib/compiler/passes/report-left-recursion.js index 6261947..4bb12dc 100644 --- a/lib/compiler/passes/report-left-recursion.js +++ b/lib/compiler/passes/report-left-recursion.js @@ -29,7 +29,7 @@ function reportLeftRecursion(ast) { check(element, visitedRules); } - return asts.matchesEmpty(ast, element); + return !asts.alwaysAdvancesOnSuccess(ast, element); }); },