/** * Converts the given ANTLR RecognitionException into a QuerySyntaxException. The RecognitionException * does not become the cause because ANTLR exceptions are not serializable. * * @param e The ANTLR exception * @param hql The query string * * @return The QuerySyntaxException */ public static QuerySyntaxException convert(RecognitionException e, String hql) { String positionInfo = e.getLine() > 0 && e.getColumn() > 0 ? " near line " + e.getLine() + ", column " + e.getColumn() : ""; return new QuerySyntaxException( e.getMessage() + positionInfo, hql ); }
/** * Extracts the error from the <tt>RecognitionException</tt> and generates * a location of the error by extracting the original text at the exceptions * line and column. * * @param originalText * the original Seam Text markup as fed into the parser * @param re * an ANTLR <tt>RecognitionException</tt> thrown by the parser * @param charsBefore * characters before error location included in message * @param charsAfter * characters after error location included in message * @return an error message with some helpful context about where the error * occured */ public static String getErrorLocation(String originalText, RecognitionException re, int charsBefore, int charsAfter) { int beginIndex = Math.max(re.getColumn() - 1 - charsBefore, 0); int endIndex = Math.min(re.getColumn() + charsAfter, originalText.length()); String location = null; // Avoid IOOBE even if what we show is wrong, we need to figure out why the indexes are off sometimes if (beginIndex > 0 && beginIndex < endIndex && endIndex > 0 && endIndex < originalText.length()) location = originalText.substring(beginIndex, endIndex); if (location == null) return location; // Filter some dangerous characters we do not want in error messages return location.replace("\n", " ").replace("\r", " ").replace("#{", "# {"); }
public void reportError(RecognitionException e, String s) { antlrTool.error(s, e.getFilename(), e.getLine(), e.getColumn()); }
/** * Reports the given error. * * @param ex encountered exception. */ public void reportError(RecognitionException ex) { Integer line = new Integer((recognizer!=null?recognizer.getStartLine():0) +ex.getLine()); Integer column = new Integer((recognizer!=null?recognizer.getStartColumn():0) +ex.getColumn()); Object args[] = { getFilename(), line, column, ex.getMessage() }; _logger.l7dlog(Level.ERROR, "PARSER_ERROR", args, ex); }
.err( I18n.ERR_07004_PARSER_FAILURE_ACI_ITEM, spec, e.getLocalizedMessage() ), e.getColumn() );
private void invokeParser( String subject ) throws ParseException { try { monitor.startedParse( "starting parse on:\n" + subject ); schemaDescriptions = parser.openLdapSchema(); afterParse(); monitor.finishedParse( "Done parsing!" ); } catch ( RecognitionException e ) { String msg = "Parser failure on:\n\t" + subject; msg += "\nAntlr exception trace:\n" + ExceptionUtils.getFullStackTrace( e ); throw new ParseException( msg, e.getColumn() ); } catch ( TokenStreamException e2 ) { String msg = "Parser failure on:\n\t" + subject; msg += "\nAntlr exception trace:\n" + ExceptionUtils.getFullStackTrace( e2 ); throw new ParseException( msg, 0 ); } }
/** * Invoke the parser * @param schemaName The schema to be parsed * @return A list of schema elements * * @throws java.io.IOException If the schema file can't be processed * @throws java.text.ParseException If we weren't able to parse the schema */ private List<SchemaElement> invokeParser( String schemaName ) throws IOException, ParseException { try { parser.parseSchema(); return parser.getSchemaElements(); } catch ( RecognitionException re ) { String msg = I18n.err( I18n.ERR_06002_PARSER_FAILURE, schemaName, ExceptionUtils.getFullStackTrace( re ) ); init(); throw new ParseException( msg, re.getColumn() ); } catch ( TokenStreamException tse ) { String msg = I18n.err( I18n.ERR_06002_PARSER_FAILURE, schemaName, ExceptionUtils.getFullStackTrace( tse ) ); init(); throw new ParseException( msg, 0 ); } }
/** Delegates the error message to the tool if any was registered via * {@link #initTool(antlr.Tool)} * @since 2.7.2 */ public void reportError(RecognitionException e) { if (getTool() != null) { getTool().error(e.getErrorMessage(), e.getFilename(), e.getLine(), e.getColumn()); } else { super.reportError(e); } }
/** Delegates the error message to the tool if any was registered via * {@link #initTool(antlr.Tool)} * @since 2.7.2 */ public void reportError(RecognitionException e) { if (getTool() != null) { getTool().error(e.getErrorMessage(), e.getFilename(), e.getLine(), e.getColumn()); } else { super.reportError(e); } }
public void matchGenericTypeBracketsFailed(String problem, String solution) throws SemanticException { Token lt = null; int lineNum = Token.badToken.getLine(), colNum = Token.badToken.getColumn(); try { lt = LT(1); if(lt != null) { lineNum = lt.getLine(); colNum = lt.getColumn(); } } catch (TokenStreamException ee) { if(ee instanceof TokenStreamRecognitionException) { lineNum = ((TokenStreamRecognitionException) ee).recog.getLine(); colNum = ((TokenStreamRecognitionException) ee).recog.getColumn(); } } throw new SemanticException(problem + ";\n solution: " + solution, getFilename(), lineNum, colNum); }
public void matchGenericTypeBracketsFailed(String problem, String solution) throws SemanticException { Token lt = null; int lineNum = Token.badToken.getLine(), colNum = Token.badToken.getColumn(); try { lt = LT(1); if(lt != null) { lineNum = lt.getLine(); colNum = lt.getColumn(); } } catch (TokenStreamException ee) { if(ee instanceof TokenStreamRecognitionException) { lineNum = ((TokenStreamRecognitionException) ee).recog.getLine(); colNum = ((TokenStreamRecognitionException) ee).recog.getColumn(); } } throw new SemanticException(problem + ";\n solution: " + solution, getFilename(), lineNum, colNum); }
public void matchGenericTypeBracketsFailed(String problem, String solution) throws SemanticException { Token lt = null; int lineNum = Token.badToken.getLine(), colNum = Token.badToken.getColumn(); try { lt = LT(1); if(lt != null) { lineNum = lt.getLine(); colNum = lt.getColumn(); } } catch (TokenStreamException ee) { if(ee instanceof TokenStreamRecognitionException) { lineNum = ((TokenStreamRecognitionException) ee).recog.getLine(); colNum = ((TokenStreamRecognitionException) ee).recog.getColumn(); } } throw new SemanticException(problem + ";\n solution: " + solution, getFilename(), lineNum, colNum); }
public void requireFailed(String problem, String solution) throws SemanticException { // TODO: Needs more work. Token lt = null; int lineNum = Token.badToken.getLine(), colNum = Token.badToken.getColumn(); try { lt = LT(1); if(lt != null) { lineNum = lt.getLine(); colNum = lt.getColumn(); } } catch (TokenStreamException ee) { if(ee instanceof TokenStreamRecognitionException) { lineNum = ((TokenStreamRecognitionException) ee).recog.getLine(); colNum = ((TokenStreamRecognitionException) ee).recog.getColumn(); } } throw new SemanticException(problem + ";\n solution: " + solution, getFilename(), lineNum, colNum); }
public void requireFailed(String problem, String solution) throws SemanticException { // TODO: Needs more work. Token lt = null; int lineNum = Token.badToken.getLine(), colNum = Token.badToken.getColumn(); try { lt = LT(1); if(lt != null) { lineNum = lt.getLine(); colNum = lt.getColumn(); } } catch (TokenStreamException ee) { if(ee instanceof TokenStreamRecognitionException) { lineNum = ((TokenStreamRecognitionException) ee).recog.getLine(); colNum = ((TokenStreamRecognitionException) ee).recog.getColumn(); } } throw new SemanticException(problem + ";\n solution: " + solution, getFilename(), lineNum, colNum); }
public void requireFailed(String problem, String solution) throws SemanticException { // TODO: Needs more work. Token lt = null; int lineNum = Token.badToken.getLine(), colNum = Token.badToken.getColumn(); try { lt = LT(1); if(lt != null) { lineNum = lt.getLine(); colNum = lt.getColumn(); } } catch (TokenStreamException ee) { if(ee instanceof TokenStreamRecognitionException) { lineNum = ((TokenStreamRecognitionException) ee).recog.getLine(); colNum = ((TokenStreamRecognitionException) ee).recog.getColumn(); } } throw new SemanticException(problem + ";\n solution: " + solution, getFilename(), lineNum, colNum); }