public override void Run(Grammar grammar, CompileResult result) { var containsAssertions = ContainsAssertionsEvaluator.Evaluate(grammar); var zeroWidth = ZeroWidthEvaluator.Evaluate(grammar); new ZeroWidthRepetitionTreeWalker(containsAssertions, zeroWidth, result).WalkGrammar(grammar); }
/// <summary> /// Detects which expressions in a <see cref="Grammar"/> are left-adjacent. /// </summary> /// <param name="grammar">The <see cref="Grammar"/> to inspect.</param> /// <returns>A <see cref="ILookup{Rule, Expression}"/> containing the left-adjacent rules.</returns> public static ILookup <Rule, Expression> Detect(Grammar grammar) { var leftAdjacent = new Dictionary <Rule, List <Expression> >(); var zeroWidth = ZeroWidthEvaluator.Evaluate(grammar); new LeftRecursionExpressionTreeWalker(zeroWidth, leftAdjacent).WalkGrammar(grammar); return(leftAdjacent.SelectMany(i => i.Value, (i, v) => new { i.Key, Value = v }).ToLookup(i => i.Key, i => i.Value)); }