Esempio n. 1
0
 public void matchRange(int a, int b) throws MismatchedRangeException {
   if (input.LA(1) < a || input.LA(1) > b) {
     if (state.backtracking > 0) {
       state.failed = true;
       return;
     }
     MismatchedRangeException mre = new MismatchedRangeException(a, b, input);
     recover(mre);
     throw mre;
   }
   input.consume();
   state.failed = false;
 }
Esempio n. 2
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()
     }
   }
 }
Esempio n. 3
0
 public void match(int c) throws MismatchedTokenException {
   if (input.LA(1) != c) {
     if (state.backtracking > 0) {
       state.failed = true;
       return;
     }
     MismatchedTokenException mte = new MismatchedTokenException(c, input);
     recover(mte); // don't really recover; just consume in lexer
     throw mte;
   }
   input.consume();
   state.failed = false;
 }
Esempio n. 4
0
 public void match(String s) throws MismatchedTokenException {
   int i = 0;
   while (i < s.length()) {
     if (input.LA(1) != s.charAt(i)) {
       if (state.backtracking > 0) {
         state.failed = true;
         return;
       }
       MismatchedTokenException mte = new MismatchedTokenException(s.charAt(i), input);
       recover(mte);
       throw mte;
     }
     i++;
     input.consume();
     state.failed = false;
   }
 }