private static ParseException mapToParseException(RecognitionException cause, String text) { return new ParseException("Error parsing SQL", cause, text, cause.line, cause.charPositionInLine); }
@Override public String toString() { StringBuilder builder = new StringBuilder(getMessage()); if (line >= 0 && column >= 0) builder.append(" at line ").append(line).append(", column ").append(column); if (parsedText != null) builder.append(" in ").append(parsedText); return builder.toString(); }
public void assertNext(char c) { if (!hasNext()) throw new ParseException("Expected '" + c + "', but no more character is available", source, line, column); char next = next(); if (next != c) throw new ParseException("Expected '" + c + "', but found '" + next + "'", source, line, column); }
public E parse(String text) { ParsePosition pos = new ParsePosition(0); E result = parseObject(text, pos); if (pos.getIndex() < text.length()) throw new ParseException("Illegal syntax", text, -1, pos.getIndex()); return result; }
public XMLElementParser<E> getParser(Element element, E[] parentPath) { for (int i = parsers.size() - 1; i >= 0; i--) { // search for parsers in reverse order, to child classes can override parsers of parent classes XMLElementParser<E> parser = parsers.get(i); if (parser.supports(element, parentPath)) return parser; } Object parent = (ArrayUtil.isEmpty(parentPath) ? null : ArrayUtil.lastElementOf(parentPath)); String message = "Syntax Error: Element '" + element.getNodeName() + "' not supported " + (parent != null ? "in the context of a " + parent.getClass().getSimpleName() : "as top level element"); throw new ParseException(message, XMLUtil.format(element)); }
public XMLElementParser<E> getParser(Element element, E[] parentPath) { for (int i = parsers.size() - 1; i >= 0; i--) { // search for parsers in reverse order, to child classes can override parsers of parent classes XMLElementParser<E> parser = parsers.get(i); if (parser.supports(element, parentPath)) return parser; } Object parent = (ArrayUtil.isEmpty(parentPath) ? null : ArrayUtil.lastElementOf(parentPath)); String message = "Syntax Error: Element '" + element.getNodeName() + "' not supported " + (parent != null ? "in the context of a " + parent.getClass().getSimpleName() : "as top level element"); throw new ParseException(message, XMLUtil.format(element)); }
case '[' : minInclusive = true; break; case ']' : minInclusive = false; break; default : throw new ParseException("Expected '[' or ']', found: " + c, text); throw new ParseException("Expected ',', found '" + c + "'", text); pos.setIndex(pos.getIndex() + 1); skipWhiteSpace(text, pos); case ']' : maxInclusive = true; break; case '[' : maxInclusive = false; break; default : throw new ParseException("Expected '[' or ']', found: " + c, text);
private static Sheet sheet(String uri, String sheetName) throws IOException, ParseException { try { Workbook workbook = WorkbookFactory.create(IOUtil.getInputStreamForURI(uri)); Sheet sheet = sheetName != null ? workbook.getSheet(sheetName) : workbook.getSheetAt(0); if (sheet == null) throw new IllegalArgumentException("Sheet '" + sheetName + "' not found in file " + uri); return sheet; } catch (InvalidFormatException e) { throw new ParseException("Error parsing sheet '" + sheetName + "' of " + uri, null); } }
private static Sheet sheet(String uri, int sheetIndex) throws IOException { Workbook workbook; try { workbook = WorkbookFactory.create(IOUtil.getInputStreamForURI(uri)); return workbook.getSheetAt(sheetIndex); } catch (InvalidFormatException e) { throw new ParseException("Error parsing sheet " + sheetIndex + " of " + uri, e, null, -1, -1); } }
private static void convertTableDetail(CommonTree node, DBTable table, DatabaseDialect dialect) { switch (node.getType()) { case SQLLexer.COLUMN_SPEC: convertColumnSpec(node, table); break; case SQLLexer.PRIMARY: convertInlinePK(node, table, dialect); break; default: throw new ParseException("Unknown table detail token type", String.valueOf(node.getText()), node.getLine(), node.getCharPositionInLine()); } }
private static void convertColumnDetail(CommonTree node, DBColumn column) { switch (node.getType()) { case SQLLexer.NOT : column.setNullable(false); break; case SQLLexer.DEFAULT : column.setNullable(false); break; default: throw new ParseException("Unknown column detail token type", String.valueOf(node.getText()), node.getLine(), node.getCharPositionInLine()); } }
private static Object convertNode(CommonTree node, DatabaseDialect dialect) { switch (node.getType()) { case SQLLexer.CREATE_TABLE: return convertCreateTable(node, dialect); case SQLLexer.DROP_TABLE: return convertDropTable(node); case SQLLexer.ALTER_TABLE: return convertAlterTable(node); case SQLLexer.CREATE_SEQUENCE: return convertCreateSequence(node); case SQLLexer.DROP_SEQUENCE: return convertDropSequence(node); case SQLLexer.CREATE_INDEX: return convertCreateIndex(node); case SQLLexer.COMMENT_TABLE: return convertTableComment(node); case SQLLexer.COMMENT_COLUMN: return convertColumnComment(node); } if (node.isNil()) { List<Object> nodes = convertNodes(getChildNodes(node), dialect); return nodes.toArray(); } throw new ParseException("Unknown token type", "'" + node.getText() + "'"); }
case SQLLexer.STRING: return convertStringToExpression(node); case SQLLexer.INT: return convertInt(node); default: throw new ParseException("Unknown token type (" + node.getType() + ")", "'" + node.getText() + "'");