@Override public String toString() { return "MismatchedTokenException("+getUnexpectedType()+"!="+expecting+")"; } }
public String toString() { return "MismatchedTokenException("+getUnexpectedType()+"!="+expecting+")"; } }
@Override public String toString() { return "MismatchedTokenException("+getUnexpectedType()+"!="+expecting+")"; } }
@Override public String toString() { return "MismatchedTokenException("+getUnexpectedType()+"!="+expecting+")"; } }
@Override public String toString() { return "MismatchedTokenException("+getUnexpectedType()+"!="+expecting+")"; } }
@Override public String toString() { return "MismatchedTokenException("+getUnexpectedType()+"!="+expecting+")"; } }
@Override public SyntaxErrorMessage getSyntaxErrorMessage(IParserErrorContext context) { if (context.getRecognitionException() instanceof MismatchedTokenException) { MismatchedTokenException exception = (MismatchedTokenException) context.getRecognitionException(); if (exception.expecting >= 0 && exception.getUnexpectedType() >= 0) { String expectingTokenTypeName = context.getTokenNames()[exception.expecting]; String unexpectedTokenTypeName = context.getTokenNames()[exception.getUnexpectedType()]; if ("RULE_ID".equals(expectingTokenTypeName)) { if (!unexpectedTokenTypeName.startsWith(RULE_PREFIX) && Character.isJavaIdentifierStart(unexpectedTokenTypeName.replace("'", "").charAt(0))) { return new SyntaxErrorMessage( "Keywords of the query language are to be prefixed with the ^ character when used as an identifier", EMFIssueCodes.IDENTIFIER_AS_KEYWORD); } else if (unexpectedTokenTypeName.startsWith(RULE_PREFIX)) { return new SyntaxErrorMessage(String.format( "Mismatched input: %s '%s' found instead of the expected identifier", unexpectedTokenTypeName.substring(RULE_PREFIX.length()).toLowerCase(), exception.token.getText()), Diagnostic.SYNTAX_DIAGNOSTIC); } } } } return super.getSyntaxErrorMessage(context); }
@Override public SyntaxErrorMessage getSyntaxErrorMessage(IParserErrorContext context) { if (context.getRecognitionException() instanceof MismatchedTokenException) { MismatchedTokenException exception = (MismatchedTokenException) context.getRecognitionException(); if (exception.expecting >= 0 && exception.getUnexpectedType() >= 0) { String expectingTokenTypeName = context.getTokenNames()[exception.expecting]; String unexpectedTokenTypeName = context.getTokenNames()[exception.getUnexpectedType()]; if ("RULE_ID".equals(expectingTokenTypeName)) { if (!unexpectedTokenTypeName.startsWith(RULE_PREFIX) && Character.isJavaIdentifierStart(unexpectedTokenTypeName.replace("'", "").charAt(0))) { return new SyntaxErrorMessage( "Keywords of the query language are to be prefixed with the ^ character when used as an identifier", IssueCodes.IDENTIFIER_AS_KEYWORD); } else if (unexpectedTokenTypeName.startsWith(RULE_PREFIX)) { return new SyntaxErrorMessage(String.format( "Mismatched input: %s '%s' found instead of the expected identifier", unexpectedTokenTypeName.substring(RULE_PREFIX.length()).toLowerCase(), exception.token.getText()), Diagnostic.SYNTAX_DIAGNOSTIC); } } } } return super.getSyntaxErrorMessage(context); }
if ((mismatched.getUnexpectedType() < 0) || (mismatched.getUnexpectedType() >= treeWalker.getTokenNames().length)) unexpected = treeWalker.getTokenNames()[mismatched.getUnexpectedType()];
private ErroSintatico traduzirErrosPara(int linha, int coluna, MismatchedTokenException erro, String[] tokens, Stack<String> pilhaContexto, String codigoFonte) { String tokenEsperado = AnalisadorSintatico.getToken(tokens, erro.expecting); String tokenEncontrado = AnalisadorSintatico.getToken(tokens, erro.getUnexpectedType()); switch (tokenEsperado) { case ")": return new ErroParentesis(linha, coluna, ErroParentesis.Tipo.FECHAMENTO); case "(": return new ErroParentesis(linha, coluna, ErroParentesis.Tipo.ABERTURA); case ";": { if (!tokenEncontrado.equals(")")) { return new ErroParentesis(linha, coluna, ErroParentesis.Tipo.FECHAMENTO); } } } return new ErroParaEsperaCondicao(linha, coluna); }
if ((mismatched.getUnexpectedType() < 0) || (mismatched.getUnexpectedType() >= parser.getTokenNames().length)) unexpected = parser.getTokenNames()[mismatched.getUnexpectedType()]; if (parser.getLexerTokenParaphrases().get(mismatched.getUnexpectedType()) != null) unexpected = parser.getLexerTokenParaphrases().get(mismatched.getUnexpectedType()); if (parser.getParserTokenParaphrases().get(mismatched.getUnexpectedType()) != null) unexpected = parser.getParserTokenParaphrases().get(mismatched.getUnexpectedType());