Пример #1
0
 /** Return a token from this source; i.e., match a token on the char stream. */
 public Token nextToken() {
   while (true) {
     state.token = null;
     state.channel = Token.DEFAULT_CHANNEL;
     state.tokenStartCharIndex = input.index();
     state.tokenStartCharPositionInLine = input.getCharPositionInLine();
     state.tokenStartLine = input.getLine();
     state.text = null;
     if (input.LA(1) == CharStream.EOF) {
       Token eof =
           new CommonToken(
               (CharStream) input, Token.EOF, Token.DEFAULT_CHANNEL, input.index(), input.index());
       eof.setLine(getLine());
       eof.setCharPositionInLine(getCharPositionInLine());
       return eof;
     }
     try {
       mTokens();
       if (state.token == null) {
         emit();
       } else if (state.token == Token.SKIP_TOKEN) {
         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()
     }
   }
 }
Пример #2
0
 /** What is the index of the current character of lookahead? */
 public int getCharIndex() {
   return input.index();
 }