From 25ed2b7ee28b1d5835d661f070a488ee466e1b01 Mon Sep 17 00:00:00 2001 From: David Majda Date: Wed, 1 Apr 2015 10:07:01 +0200 Subject: [PATCH] Improve comment describing the |reportLeftRecursion| pass --- lib/compiler/passes/report-left-recursion.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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; }