Example #1
0
 /** <summary>Return a token from this source; i.e., match a token on the char stream.</summary> */
 public virtual IToken NextToken()
 {
     for ( ; ;)
     {
         state.token                        = null;
         state.channel                      = TokenChannels.Default;
         state.tokenStartCharIndex          = input.Index;
         state.tokenStartCharPositionInLine = input.CharPositionInLine;
         state.tokenStartLine               = input.Line;
         state.text = null;
         if (input.LA(1) == CharStreamConstants.EndOfFile)
         {
             IToken eof = new CommonToken((ICharStream)input, CharStreamConstants.EndOfFile, TokenChannels.Default, input.Index, input.Index);
             eof.Line = Line;
             eof.CharPositionInLine = CharPositionInLine;
             return(eof);
         }
         try
         {
             mTokens();
             if (state.token == null)
             {
                 Emit();
             }
             else if (state.token == Tokens.Skip)
             {
                 continue;
             }
             return(state.token);
         }
         catch (NoViableAltException nva)
         {
             ReportError(nva);
             Recover(nva);   // throw out current char and try again
         }
         catch (RecognitionException re)
         {
             ReportError(re);
             // match() routine has already called recover()
         }
     }
 }