Antlr4.Analysis.LeftRecursionDetector.AddRulesToCycle C# (CSharp) Method

AddRulesToCycle() protected method

protected AddRulesToCycle ( Rule enclosingRule, Rule targetRule ) : void
enclosingRule Antlr4.Tool.Rule
targetRule Antlr4.Tool.Rule
return void
        protected virtual void AddRulesToCycle(Rule enclosingRule, Rule targetRule)
        {
            //System.err.println("left-recursion to "+targetRule.name+" from "+enclosingRule.name);
            bool foundCycle = false;
            foreach (ISet<Rule> rulesInCycle in listOfRecursiveCycles)
            {
                // ensure both rules are in same cycle
                if (rulesInCycle.Contains(targetRule))
                {
                    rulesInCycle.Add(enclosingRule);
                    foundCycle = true;
                }
                if (rulesInCycle.Contains(enclosingRule))
                {
                    rulesInCycle.Add(targetRule);
                    foundCycle = true;
                }
            }
            if (!foundCycle)
            {
                ISet<Rule> cycle = new OrderedHashSet<Rule>();
                cycle.Add(targetRule);
                cycle.Add(enclosingRule);
                listOfRecursiveCycles.Add(cycle);
            }
        }
    }