Beispiel #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;
 }
Beispiel #2
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;
 }
Beispiel #3
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;
   }
 }
Beispiel #4
0
 /**
  * Lexers can normally match any char in it's vocabulary after matching a token, so do the easy
  * thing and just kill a character and hope it all works out. You can instead use the rule
  * invocation stack to do sophisticated error recovery if you are in a fragment rule.
  */
 public void recover(RecognitionException re) {
   // System.out.println("consuming char "+(char)input.LA(1)+" during recovery");
   // re.printStackTrace();
   input.consume();
 }
Beispiel #5
0
 public void matchAny() {
   input.consume();
 }