org.antlr.runtime.MismatchedTokenException Java Examples

The following examples show how to use org.antlr.runtime.MismatchedTokenException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: STLexer.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
Token COMMENT() {
    match('!');
    while ( !(c=='!' && input.LA(2)==delimiterStopChar) ) {
        if ( c==EOF ) {
            RecognitionException re = new MismatchedTokenException((int)'!', input);
            re.line = input.getLine();
            re.charPositionInLine = input.getCharPositionInLine();
            errMgr.lexerError(input.getSourceName(), "Nonterminated comment starting at "+startLine+":"+startCharPositionInLine+": '!"+delimiterStopChar+"' missing", templateToken, re);
            break;
        }
        consume();
    }
    consume();
    consume(); // grab !>
    return newToken(COMMENT);
}
 
Example #2
Source File: STLexer.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
Token COMMENT() {
    match('!');
    while ( !(c=='!' && input.LA(2)==delimiterStopChar) ) {
        if ( c==EOF ) {
            RecognitionException re = new MismatchedTokenException((int)'!', input);
            re.line = input.getLine();
            re.charPositionInLine = input.getCharPositionInLine();
            errMgr.lexerError(input.getSourceName(),
                              "Nonterminated comment starting at " +
                              startLine +":"+startCharPositionInLine +
                              ": '!" +
                              delimiterStopChar +
                              "' missing", templateToken, re);
            break;
        }
        consume();
    }
    consume();
    consume(); // grab !>
    return newToken(COMMENT);
}
 
Example #3
Source File: STLexer.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
Token COMMENT() {
    match('!');
    while ( !(c=='!' && input.LA(2)==delimiterStopChar) ) {
        if ( c==EOF ) {
            RecognitionException re = new MismatchedTokenException((int)'!', input);
            re.line = input.getLine();
            re.charPositionInLine = input.getCharPositionInLine();
            errMgr.lexerError(input.getSourceName(), "Nonterminated comment starting at " +
                                                     startLine +":"+startCharPositionInLine +
                                                     ": '!" +
                                                     delimiterStopChar +
                                                     "' missing", templateToken, re);
            break;
        }
        consume();
    }
    consume();
    consume(); // grab !>
    return newToken(COMMENT);
}
 
Example #4
Source File: STLexer.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
Token COMMENT() {
    match('!');
    while ( !(c=='!' && input.LA(2)==delimiterStopChar) ) {
        if ( c==EOF ) {
            RecognitionException re = new MismatchedTokenException((int)'!', input);
            re.line = input.getLine();
            re.charPositionInLine = input.getCharPositionInLine();
            errMgr.lexerError(input.getSourceName(),
                              "Nonterminated comment starting at " +
                              startLine +":"+startCharPositionInLine +
                              ": '!" +
                              delimiterStopChar +
                              "' missing", templateToken, re);
            break;
        }
        consume();
    }
    consume();
    consume(); // grab !>
    return newToken(COMMENT);
}
 
Example #5
Source File: STLexer.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
Token COMMENT() {
    match('!');
    while ( !(c=='!' && input.LA(2)==delimiterStopChar) ) {
        if ( c==EOF ) {
            RecognitionException re = new MismatchedTokenException((int)'!', input);
            re.line = input.getLine();
            re.charPositionInLine = input.getCharPositionInLine();
            errMgr.lexerError(input.getSourceName(),
                              "Nonterminated comment starting at " +
                              startLine +":" +
                              startCharPositionInLine +
                              ": '!" +
                              delimiterStopChar +
                              "' missing" , templateToken, re);
            break;
        }
        consume();
    }
    consume();
    consume(); // grab !>
    return newToken(COMMENT);
}
 
Example #6
Source File: STLexer.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
Token COMMENT() {
    match('!');
    while ( !(c=='!' && input.LA(2)==delimiterStopChar) ) {
        if ( c==EOF ) {
            RecognitionException re = new MismatchedTokenException((int)'!', input);
            re.line = input.getLine();
            re.charPositionInLine = input.getCharPositionInLine();
            errMgr.lexerError(input.getSourceName(),
                              "Nonterminated comment starting at " +
                              startLine +":" +
                              startCharPositionInLine +
                              ": '!" +
                              delimiterStopChar +
                              "' missing" , templateToken, re);
            break;
        }
        consume();
    }
    consume();
    consume(); // grab !>
    return newToken(COMMENT);
}
 
Example #7
Source File: STLexer.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
Token COMMENT() {
    match('!');
    while ( !(c=='!' && input.LA(2)==delimiterStopChar) ) {
        if ( c==EOF ) {
            RecognitionException re = new MismatchedTokenException((int)'!', input);
            re.line = input.getLine();
            re.charPositionInLine = input.getCharPositionInLine();
            errMgr.lexerError(input.getSourceName(),
                              "Nonterminated comment starting at " +
                              startLine +":"+startCharPositionInLine +
                              ": '!" +
                              delimiterStopChar +
                              "' missing", templateToken, re);
            break;
        }
        consume();
    }
    consume();
    consume(); // grab !>
    return newToken(COMMENT);
}
 
Example #8
Source File: STLexer.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
Token COMMENT() {
    match('!');
    while ( !(c=='!' && input.LA(2)==delimiterStopChar) ) {
        if ( c==EOF ) {
            RecognitionException re = new MismatchedTokenException((int)'!', input);
            re.line = input.getLine();
            re.charPositionInLine = input.getCharPositionInLine();
            errMgr.lexerError(input.getSourceName(),
                              "Nonterminated comment starting at " +
                              startLine +":"+startCharPositionInLine +
                              ": '!" +
                              delimiterStopChar +
                              "' missing", templateToken, re);
            break;
        }
        consume();
    }
    consume();
    consume(); // grab !>
    return newToken(COMMENT);
}
 
Example #9
Source File: STLexer.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
Token COMMENT() {
    match('!');
    while ( !(c=='!' && input.LA(2)==delimiterStopChar) ) {
        if ( c==EOF ) {
            RecognitionException re = new MismatchedTokenException((int)'!', input);
            re.line = input.getLine();
            re.charPositionInLine = input.getCharPositionInLine();
            errMgr.lexerError(input.getSourceName(),
                              "Nonterminated comment starting at " +
                              startLine +":"+startCharPositionInLine +
                              ": '!" +
                              delimiterStopChar +
                              "' missing", templateToken, re);
            break;
        }
        consume();
    }
    consume();
    consume(); // grab !>
    return newToken(COMMENT);
}
 
Example #10
Source File: STLexer.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
Token COMMENT() {
    match('!');
    while ( !(c=='!' && input.LA(2)==delimiterStopChar) ) {
        if ( c==EOF ) {
            RecognitionException re = new MismatchedTokenException((int)'!', input);
            re.line = input.getLine();
            re.charPositionInLine = input.getCharPositionInLine();
            errMgr.lexerError(input.getSourceName(), "Nonterminated comment starting at "+startLine+":"+startCharPositionInLine+": '!"+delimiterStopChar+"' missing", templateToken, re);
            break;
        }
        consume();
    }
    consume();
    consume(); // grab !>
    return newToken(COMMENT);
}
 
Example #11
Source File: STLexer.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
Token COMMENT() {
    match('!');
    while ( !(c=='!' && input.LA(2)==delimiterStopChar) ) {
        if ( c==EOF ) {
            RecognitionException re = new MismatchedTokenException((int)'!', input);
            re.line = input.getLine();
            re.charPositionInLine = input.getCharPositionInLine();
            errMgr.lexerError(input.getSourceName(), "Nonterminated comment starting at "+startLine+":"+startCharPositionInLine+": '!"+delimiterStopChar+"' missing", templateToken, re);
            break;
        }
        consume();
    }
    consume();
    consume(); // grab !>
    return newToken(COMMENT);
}
 
Example #12
Source File: STLexer.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
Token COMMENT() {
      match('!');
      while ( !(c=='!' && input.LA(2)==delimiterStopChar) ) {
	if (c==EOF) {
		RecognitionException re =
			new MismatchedTokenException((int)'!', input);
		re.line = input.getLine();
		re.charPositionInLine = input.getCharPositionInLine();
		errMgr.lexerError(input.getSourceName(), "Nonterminated comment starting at " +
			startLine+":"+startCharPositionInLine+": '!"+
			delimiterStopChar+"' missing", templateToken, re);
		break;
	}
	consume();
}
      consume(); consume(); // grab !>
return newToken(COMMENT);
  }
 
Example #13
Source File: STLexer.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
Token COMMENT() {
    match('!');
    while ( !(c=='!' && input.LA(2)==delimiterStopChar) ) {
        if ( c==EOF ) {
            RecognitionException re = new MismatchedTokenException((int)'!', input);
            re.line = input.getLine();
            re.charPositionInLine = input.getCharPositionInLine();
            errMgr.lexerError(input.getSourceName(), "Nonterminated comment starting at "+startLine+":"+startCharPositionInLine+": '!"+delimiterStopChar+"' missing", templateToken, re);
            break;
        }
        consume();
    }
    consume();
    consume(); // grab !>
    return newToken(COMMENT);
}
 
Example #14
Source File: STLexer.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
Token COMMENT() {
    match('!');
    while ( !(c=='!' && input.LA(2)==delimiterStopChar) ) {
        if ( c==EOF ) {
            RecognitionException re = new MismatchedTokenException((int)'!', input);
            re.line = input.getLine();
            re.charPositionInLine = input.getCharPositionInLine();
            errMgr.lexerError(input.getSourceName(), "Nonterminated comment starting at "+startLine+":"+startCharPositionInLine+": '!"+delimiterStopChar+"' missing", templateToken, re);
            break;
        }
        consume();
    }
    consume();
    consume(); // grab !>
    return newToken(COMMENT);
}
 
Example #15
Source File: STLexer.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
Token COMMENT() {
    match('!');
    while ( !(c=='!' && input.LA(2)==delimiterStopChar) ) {
        if ( c==EOF ) {
            RecognitionException re = new MismatchedTokenException((int)'!', input);
            re.line = input.getLine();
            re.charPositionInLine = input.getCharPositionInLine();
            errMgr.lexerError(input.getSourceName(), "Nonterminated comment starting at "+startLine+":"+startCharPositionInLine+": '!"+delimiterStopChar+"' missing", templateToken, re);
            break;
        }
        consume();
    }
    consume();
    consume(); // grab !>
    return newToken(COMMENT);
}
 
Example #16
Source File: STLexer.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
Token COMMENT() {
    match('!');
    while ( !(c=='!' && input.LA(2)==delimiterStopChar) ) {
        if ( c==EOF ) {
            RecognitionException re = new MismatchedTokenException((int)'!', input);
            re.line = input.getLine();
            re.charPositionInLine = input.getCharPositionInLine();
            errMgr.lexerError(input.getSourceName(), "Nonterminated comment starting at "+startLine+":"+startCharPositionInLine+": '!"+delimiterStopChar+"' missing", templateToken, re);
            break;
        }
        consume();
    }
    consume();
    consume(); // grab !>
    return newToken(COMMENT);
}
 
Example #17
Source File: CtfAntlrException.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Re-throw the exception but read its data
 *
 * @param e
 *            the previous recognition exception (Antlr specific)
 */
public CtfAntlrException(MismatchedTokenException e) {
    super(e);
    fErrorLine = e.line;
    fCharPositionInLine = e.charPositionInLine;
    fFile = "metadata"; //$NON-NLS-1$ // we're in CTF, the only thing using antlr is metadata
    parseMismatchedException(e);
}
 
Example #18
Source File: PhoenixParserException.java    From phoenix with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static SQLExceptionCode getErrorCode(Throwable e) {
    if (e instanceof MissingTokenException) {
        return SQLExceptionCode.MISSING_TOKEN;
    } else if (e instanceof UnwantedTokenException) {
        return SQLExceptionCode.UNWANTED_TOKEN;
    } else if (e instanceof MismatchedTokenException) {
        return SQLExceptionCode.MISMATCHED_TOKEN;
    } else if (e instanceof UnknownFunctionException) {
        return SQLExceptionCode.UNKNOWN_FUNCTION;
    } else {
        return SQLExceptionCode.PARSER_ERROR;
    }
}
 
Example #19
Source File: PhoenixParserException.java    From phoenix with Apache License 2.0 5 votes vote down vote up
public static SQLExceptionCode getErrorCode(Throwable e) {
    if (e instanceof MissingTokenException) {
        return SQLExceptionCode.MISSING_TOKEN;
    } else if (e instanceof UnwantedTokenException) {
        return SQLExceptionCode.UNWANTED_TOKEN;
    } else if (e instanceof MismatchedTokenException) {
        return SQLExceptionCode.MISMATCHED_TOKEN;
    } else if (e instanceof UnknownFunctionException) {
        return SQLExceptionCode.UNKNOWN_FUNCTION;
    } else {
        return SQLExceptionCode.PARSER_ERROR;
    }
}
 
Example #20
Source File: TestLogicalPlanGenerator.java    From spork with Apache License 2.0 5 votes vote down vote up
@Test(expected = MismatchedTokenException.class)
public void testNegative3() throws Exception {
	String query = "A = load 'y'; all = load 'x';";
	try {
        ParserTestingUtils.generateLogicalPlan( query );
    } catch(Exception ex) {
        MismatchedTokenException mex = (MismatchedTokenException)ex;
        assertTrue( mex.token.getText().equals("all") );
        throw ex;
    }
}
 
Example #21
Source File: STLexer.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
Token COMMENT() {
    match('!');
    while ( !(c=='!' && input.LA(2)==delimiterStopChar) ) {
        if ( c==EOF ) {
            RecognitionException re = new MismatchedTokenException((int)'!', input);
            re.line = input.getLine();
            re.charPositionInLine = input.getCharPositionInLine();
            errMgr.lexerError(input.getSourceName(), "Nonterminated comment starting at "+startLine+":"+startCharPositionInLine+": '!"+delimiterStopChar+"' missing", templateToken, re);
            break;
        }
        consume();
    }
    consume();
    consume(); // grab !>
    return newToken(COMMENT);
}
 
Example #22
Source File: TestLogicalPlanGenerator.java    From spork with Apache License 2.0 5 votes vote down vote up
@Test(expected = MismatchedTokenException.class)
public void testNegative2() throws Exception {
  	String query = "ship = load 'x';";
  	try {
        ParserTestingUtils.generateLogicalPlan( query );
    } catch(Exception ex) {
        MismatchedTokenException mex = (MismatchedTokenException)ex;
        assertTrue( mex.token.getText().equals("ship") );
        throw ex;
    }
}
 
Example #23
Source File: RecognizerErrorHandler.java    From legstar-core2 with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Simplify error message text for end users.
 * @param e exception that occurred
 * @param msg as formatted by ANTLR
 * @return a more readable error message
 */
public static String makeUserMsg(final RecognitionException e, final String msg) {
    if (e instanceof NoViableAltException) {
        return msg.replace("no viable alternative at", "unrecognized");
    } else if (e instanceof UnwantedTokenException) {
        return msg.replace("extraneous input", "unexpected token");
    } else if (e instanceof MismatchedTokenException) {
        if (msg.contains("mismatched input '<EOF>'")) {
            return msg.replace("mismatched input '<EOF>' expecting", "reached end of file looking for");
        } else {
            return msg.replace("mismatched input", "unexpected token");
        }
    } else if (e instanceof EarlyExitException) {
        return msg.replace("required (...)+ loop did not match anything", "required tokens not found");
    } else if (e instanceof FailedPredicateException) {
        if (msg.contains("picture_string failed predicate: {Unbalanced parentheses}")) {
            return "Unbalanced parentheses in picture string";
        }
        if (msg.contains("PICTURE_PART failed predicate: {Contains invalid picture symbols}")) {
            return "Picture string contains invalid symbols";
        }
        if (msg.contains("PICTURE_PART failed predicate: {Syntax error in last picture clause}")) {
            return "Syntax error in last picture clause";
        }
        if (msg.contains("DATA_NAME failed predicate: {Syntax error in last clause}")) {
            return "Syntax error in last COBOL clause";
        }
    }
    return msg;
}
 
Example #24
Source File: STLexer.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/** <pre>
*  STRING : '"'
*           (   '\\' '"'
*           |   '\\' ~'"'
*           |   ~('\\'|'"')
*           )*
*           '"'
*         ;
* </pre>
*/
  Token mSTRING() {
  	//{setText(getText().substring(1, getText().length()-1));}
      boolean sawEscape = false;
      StringBuilder buf = new StringBuilder();
      buf.append(c); consume();
      while ( c != '"' ) {
          if ( c=='\\' ) {
              sawEscape = true;
              consume();
		switch ( c ) {
			case 'n' : buf.append('\n'); break;
			case 'r' : buf.append('\r'); break;
			case 't' : buf.append('\t'); break;
              	default : buf.append(c); break;
		}
		consume();
              continue;
          }
          buf.append(c);
          consume();
	if ( c==EOF ) {
		RecognitionException re =
			new MismatchedTokenException((int)'"', input);
		re.line = input.getLine();
		re.charPositionInLine = input.getCharPositionInLine();
		errMgr.lexerError(input.getSourceName(), "EOF in string", templateToken, re);
		break;
	}
      }
      buf.append(c);
      consume();
      if ( sawEscape ) return newToken(STRING, buf.toString());
      else return newToken(STRING);
  }
 
Example #25
Source File: PhoenixParserException.java    From phoenix with Apache License 2.0 5 votes vote down vote up
public static SQLExceptionCode getErrorCode(Throwable e) {
    if (e instanceof MissingTokenException) {
        return SQLExceptionCode.MISSING_TOKEN;
    } else if (e instanceof UnwantedTokenException) {
        return SQLExceptionCode.UNWANTED_TOKEN;
    } else if (e instanceof MismatchedTokenException) {
        return SQLExceptionCode.MISMATCHED_TOKEN;
    } else if (e instanceof UnknownFunctionException) {
        return SQLExceptionCode.UNKNOWN_FUNCTION;
    } else {
        return SQLExceptionCode.PARSER_ERROR;
    }
}
 
Example #26
Source File: STLexer.java    From codebuff with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/** <pre>
 *  STRING : '"'
 *           (   '\\' '"'
 *           |   '\\' ~'"'
 *           |   ~('\\'|'"')
 *           )*
 *           '"'
 *         ;
 * </pre>
 */

Token mSTRING() {
    //{setText(getText().substring(1, getText().length()-1));}
    boolean sawEscape = false;
    StringBuilder buf = new StringBuilder();
    buf.append(c);
    consume();
    while ( c!='"' ) {
        if ( c=='\\' ) {
            sawEscape = true;
            consume();
            switch ( c ) {
                case 'n':
                    buf.append('\n');
                    break;
                case 'r':
                    buf.append('\r');
                    break;
                case 't':
                    buf.append('\t');
                    break;
                default:
                    buf.append(c);
                    break;
            }
            consume();
            continue;
        }
        buf.append(c);
        consume();
        if ( c==EOF ) {
            RecognitionException re = new MismatchedTokenException((int)'"', input);
            re.line = input.getLine();
            re.charPositionInLine = input.getCharPositionInLine();
            errMgr.lexerError(input.getSourceName(), "EOF in string", templateToken, re);
            break;
        }
    }
    buf.append(c);
    consume();
    if ( sawEscape ) return newToken(STRING, buf.toString());
    else return newToken(STRING);
}
 
Example #27
Source File: STLexer.java    From codebuff with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/** <pre>
 *  STRING : '"'
 *           (   '\\' '"'
 *           |   '\\' ~'"'
 *           |   ~('\\'|'"')
 *           )*
 *           '"'
 *         ;
 * </pre>
 */

Token mSTRING() {
    //{setText(getText().substring(1, getText().length()-1));}
    boolean sawEscape = false;
    StringBuilder buf = new StringBuilder();
    buf.append(c);
    consume();
    while ( c!='"' ) {
        if ( c=='\\' ) {
            sawEscape = true;
            consume();
            switch ( c ) {
                case 'n' :
                    buf.append('\n');
                    break;
                case 'r' :
                    buf.append('\r');
                    break;
                case 't' :
                    buf.append('\t');
                    break;
                default:
                    buf.append(c);
                    break;
            }
            consume();
            continue;
        }
        buf.append(c);
        consume();
        if ( c==EOF ) {
            RecognitionException re = new MismatchedTokenException((int)'"', input);
            re.line = input.getLine();
            re.charPositionInLine = input.getCharPositionInLine();
            errMgr.lexerError(input.getSourceName(), "EOF in string", templateToken, re);
            break;
        }
    }
    buf.append(c);
    consume();
    if ( sawEscape ) return newToken(STRING, buf.toString());
    else return newToken(STRING);
}
 
Example #28
Source File: FastSimpleGenericEdifactDirectXMLParser.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
protected void mismatch( IntStream input, int ttype, BitSet follow ) throws RecognitionException {
  throw new MismatchedTokenException( ttype, input );
}
 
Example #29
Source File: FastSimpleGenericEdifactDirectXMLParser.java    From hop with Apache License 2.0 4 votes vote down vote up
protected void mismatch( IntStream input, int ttype, BitSet follow ) throws RecognitionException {
  throw new MismatchedTokenException( ttype, input );
}
 
Example #30
Source File: STLexer.java    From codebuff with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/** <pre>
 *  STRING : '"'
 *           (   '\\' '"'
 *           |   '\\' ~'"'
 *           |   ~('\\'|'"')
 *           )*
 *           '"'
 *         ;
 * </pre>
 */

Token mSTRING() {
    //{setText(getText().substring(1, getText().length()-1));}
    boolean sawEscape = false;
    StringBuilder buf = new StringBuilder();
    buf.append(c);
    consume();
    while ( c!='"' ) {
        if ( c=='\\' ) {
            sawEscape = true;
            consume();
            switch ( c ) {
                case 'n':
                    buf.append('\n');
                    break;
                case 'r':
                    buf.append('\r');
                    break;
                case 't':
                    buf.append('\t');
                    break;
                default:
                    buf.append(c);
                    break;
            }
            consume();
            continue;
        }
        buf.append(c);
        consume();
        if ( c==EOF ) {
            RecognitionException re = new MismatchedTokenException((int)'"', input);
            re.line = input.getLine();
            re.charPositionInLine = input.getCharPositionInLine();
            errMgr.lexerError(input.getSourceName(), "EOF in string", templateToken, re);
            break;
        }
    }
    buf.append(c);
    consume();
    if ( sawEscape ) return newToken(STRING, buf.toString());
    else return newToken(STRING);
}