Parse() public method

Begin parsing at startRuleIndex
public Parse ( int startRuleIndex ) : ParserRuleContext
startRuleIndex int
return ParserRuleContext
コード例 #1
0
 /// <summary>
 /// For repeated use of a tree pattern, compile it to a
 /// <see cref="ParseTreePattern"/>
 /// using this method.
 /// </summary>
 public virtual ParseTreePattern Compile(string pattern, int patternRuleIndex)
 {
     IList<IToken> tokenList = Tokenize(pattern);
     ListTokenSource tokenSrc = new ListTokenSource(tokenList);
     CommonTokenStream tokens = new CommonTokenStream(tokenSrc);
     ParserInterpreter parserInterp = new ParserInterpreter(parser.GrammarFileName, Arrays.AsList(parser.TokenNames), Arrays.AsList(parser.RuleNames), parser.GetATNWithBypassAlts(), tokens);
     IParseTree tree = null;
     try
     {
         parserInterp.ErrorHandler = new BailErrorStrategy();
         tree = parserInterp.Parse(patternRuleIndex);
     }
     catch (ParseCanceledException e)
     {
         //			System.out.println("pattern tree = "+tree.toStringTree(parserInterp));
         throw (RecognitionException)e.InnerException;
     }
     catch (RecognitionException)
     {
         throw;
     }
     catch (Exception e)
     {
         throw new ParseTreePatternMatcher.CannotInvokeStartRule(e);
     }
     // Make sure tree pattern compilation checks for a complete parse
     if (tokens.La(1) != TokenConstants.Eof)
     {
         throw new ParseTreePatternMatcher.StartRuleDoesNotConsumeFullPattern();
     }
     return new ParseTreePattern(this, pattern, patternRuleIndex, tree);
 }