Antlr4.Tool.GrammarParserInterpreter.GetAllPossibleParseTrees C# (CSharp) Method

GetAllPossibleParseTrees() public static method

public static GetAllPossibleParseTrees ( Grammar g, Parser originalParser, ITokenStream tokens, int decision, Antlr4.Runtime.Sharpen.BitSet alts, int startIndex, int stopIndex, int startRuleIndex ) : IList
g Grammar
originalParser Parser
tokens ITokenStream
decision int
alts Antlr4.Runtime.Sharpen.BitSet
startIndex int
stopIndex int
startRuleIndex int
return IList
        public static IList<ParserRuleContext> GetAllPossibleParseTrees(Grammar g,
                                                                       Parser originalParser,
                                                                       ITokenStream tokens,
                                                                       int decision,
                                                                       BitSet alts,
                                                                       int startIndex,
                                                                       int stopIndex,
                                                                       int startRuleIndex)
        {
            IList<ParserRuleContext> trees = new List<ParserRuleContext>();
            // Create a new parser interpreter to parse the ambiguous subphrase
            ParserInterpreter parser = DeriveTempParserInterpreter(g, originalParser, tokens);

            if (stopIndex >= (tokens.Size - 1))
            {
                // if we are pointing at EOF token
                // EOF is not in tree, so must be 1 less than last non-EOF token
                stopIndex = tokens.Size - 2;
            }

            // get ambig trees
            int alt = alts.NextSetBit(0);
            while (alt >= 0)
            {
                // re-parse entire input for all ambiguous alternatives
                // (don't have to do first as it's been parsed, but do again for simplicity
                //  using this temp parser.)
                parser.Reset();
                parser.AddDecisionOverride(decision, startIndex, alt);
                ParserRuleContext t = parser.Parse(startRuleIndex);
                GrammarInterpreterRuleContext ambigSubTree =
                    (GrammarInterpreterRuleContext)Trees.GetRootOfSubtreeEnclosingRegion(t, startIndex, stopIndex);
                // Use higher of overridden decision tree or tree enclosing all tokens
                if (Trees.IsAncestorOf(parser.OverrideDecisionRoot, ambigSubTree))
                {
                    ambigSubTree = (GrammarInterpreterRuleContext)parser.OverrideDecisionRoot;
                }
                trees.Add(ambigSubTree);
                alt = alts.NextSetBit(alt + 1);
            }

            return trees;
        }