diff --git a/lib/compiler/passes/report-left-recursion.js b/lib/compiler/passes/report-left-recursion.js index ea5bdd6..207fdf3 100644 --- a/lib/compiler/passes/report-left-recursion.js +++ b/lib/compiler/passes/report-left-recursion.js @@ -3,7 +3,18 @@ var arrays = require("../../utils/arrays"), asts = require("../asts"), visitor = require("../visitor"); -/* Checks that no left recursion is present. */ +/* + * Reports left recursion in the grammar, which prevents infinite recursion in + * the generated parser. + * + * Both direct and indirect recursion is detected. The pass also correctly + * reports cases like this: + * + * start = "a"? start + * + * In general, if a rule reference can be reached without consuming any input, + * it can lead to left recursion. + */ function reportLeftRecursion(ast) { function matchesEmptyTrue() { return true; } function matchesEmptyFalse() { return false; }