mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improved sql parser.
This commit is contained in:
@@ -525,7 +525,7 @@ public class Lexer {
|
||||
token = Token.SEMI;
|
||||
return;
|
||||
case '`':
|
||||
throw new ParserException("TODO"); // TODO
|
||||
throw new ParserException("TODO. " + info()); // TODO
|
||||
case '@':
|
||||
scanVariable();
|
||||
return;
|
||||
@@ -737,7 +737,7 @@ public class Lexer {
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new ParserException("TODO");
|
||||
throw new ParserException("TODO. " + info());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -806,7 +806,7 @@ public class Lexer {
|
||||
}
|
||||
|
||||
if (endIndex == -1) {
|
||||
throw new ParserException("unclosed str");
|
||||
throw new ParserException("unclosed str. " + info());
|
||||
}
|
||||
|
||||
String stringVal = subString(startIndex, endIndex - startIndex);
|
||||
@@ -978,7 +978,7 @@ public class Lexer {
|
||||
}
|
||||
|
||||
if (endIndex == -1) {
|
||||
throw new ParserException("unclosed str");
|
||||
throw new ParserException("unclosed str. " + info());
|
||||
}
|
||||
|
||||
String stringVal = subString(startIndex, endIndex - startIndex);
|
||||
@@ -1081,7 +1081,7 @@ public class Lexer {
|
||||
|
||||
public void scanVariable() {
|
||||
if (ch != '@' && ch != ':' && ch != '#' && ch != '$') {
|
||||
throw new ParserException("illegal variable");
|
||||
throw new ParserException("illegal variable. " + info());
|
||||
}
|
||||
|
||||
mark = pos;
|
||||
@@ -1120,7 +1120,7 @@ public class Lexer {
|
||||
}
|
||||
|
||||
if (ch != '}') {
|
||||
throw new ParserException("syntax error");
|
||||
throw new ParserException("syntax error. " + info());
|
||||
}
|
||||
++pos;
|
||||
bufPos++;
|
||||
@@ -1181,7 +1181,7 @@ public class Lexer {
|
||||
|
||||
// multiline comment结束符错误
|
||||
if (ch == EOI) {
|
||||
throw new ParserException("unterminated /* comment.");
|
||||
throw new ParserException("unterminated /* comment. " + info());
|
||||
}
|
||||
scanChar();
|
||||
bufPos++;
|
||||
@@ -1230,7 +1230,7 @@ public class Lexer {
|
||||
|
||||
// single line comment结束符错误
|
||||
if (ch == EOI) {
|
||||
throw new ParserException("syntax error at end of input.");
|
||||
throw new ParserException("syntax error at end of input. " + info());
|
||||
}
|
||||
|
||||
scanChar();
|
||||
@@ -1258,7 +1258,7 @@ public class Lexer {
|
||||
|
||||
final boolean firstFlag = isFirstIdentifierChar(first);
|
||||
if (!firstFlag) {
|
||||
throw new ParserException("illegal identifier");
|
||||
throw new ParserException("illegal identifier. " + info());
|
||||
}
|
||||
|
||||
mark = pos;
|
||||
@@ -1520,7 +1520,7 @@ public class Lexer {
|
||||
public BigDecimal decimalValue() {
|
||||
String value = subString(mark, bufPos);
|
||||
if (!StringUtils.isNumber(value)){
|
||||
throw new ParserException(value+" is not a number!");
|
||||
throw new ParserException(value+" is not a number! " + info());
|
||||
}
|
||||
return new BigDecimal(value.toCharArray());
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ public class SQLCreateTableParser extends SQLDDLParser {
|
||||
lexer.nextToken();
|
||||
createTable.setType(SQLCreateTableStatement.Type.GLOBAL_TEMPORARY);
|
||||
} else {
|
||||
throw new ParserException("syntax error " + lexer.token() + " " + lexer.stringVal());
|
||||
throw new ParserException("syntax error " + lexer.info());
|
||||
}
|
||||
} else if (lexer.token() == Token.IDENTIFIER && lexer.stringVal().equalsIgnoreCase("LOCAL")) {
|
||||
lexer.nextToken();
|
||||
@@ -75,7 +75,7 @@ public class SQLCreateTableParser extends SQLDDLParser {
|
||||
lexer.nextToken();
|
||||
createTable.setType(SQLCreateTableStatement.Type.LOCAL_TEMPORARY);
|
||||
} else {
|
||||
throw new ParserException("syntax error");
|
||||
throw new ParserException("syntax error. " + lexer.info());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ public class SQLCreateTableParser extends SQLDDLParser {
|
||||
constraint.setParent(createTable);
|
||||
createTable.getTableElementList().add((SQLTableElement) constraint);
|
||||
} else if (token == Token.TABLESPACE) {
|
||||
throw new ParserException("TODO " + token);
|
||||
throw new ParserException("TODO " + lexer.info());
|
||||
} else {
|
||||
SQLColumnDefinition column = this.exprParser.parseColumn();
|
||||
createTable.getTableElementList().add(column);
|
||||
|
||||
@@ -34,16 +34,16 @@ public class SQLDDLParser extends SQLStatementParser {
|
||||
|
||||
if (lexer.token() == Token.IDENTIFIER) {
|
||||
this.exprParser.name();
|
||||
throw new ParserException("TODO");
|
||||
throw new ParserException("TODO. " + lexer.info());
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.PRIMARY) {
|
||||
lexer.nextToken();
|
||||
accept(Token.KEY);
|
||||
|
||||
throw new ParserException("TODO");
|
||||
throw new ParserException("TODO. " + lexer.info());
|
||||
}
|
||||
|
||||
throw new ParserException("TODO");
|
||||
throw new ParserException("TODO " + lexer.info());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -238,7 +238,7 @@ public class SQLExprParser extends SQLParser {
|
||||
case INSERT:
|
||||
lexer.nextToken();
|
||||
if (lexer.token() != Token.LPAREN) {
|
||||
throw new ParserException("syntax error");
|
||||
throw new ParserException("syntax error. " + lexer.info());
|
||||
}
|
||||
sqlExpr = new SQLIdentifierExpr("INSERT");
|
||||
break;
|
||||
@@ -263,7 +263,7 @@ public class SQLExprParser extends SQLParser {
|
||||
}
|
||||
break;
|
||||
case NEW:
|
||||
throw new ParserException("TODO");
|
||||
throw new ParserException("TODO " + lexer.info());
|
||||
case LITERAL_INT:
|
||||
sqlExpr = new SQLIntegerExpr(lexer.integerValue());
|
||||
lexer.nextToken();
|
||||
@@ -520,7 +520,7 @@ public class SQLExprParser extends SQLParser {
|
||||
sqlExpr = new SQLUnaryExpr(SQLUnaryOperator.Negative, sqlExpr);
|
||||
break;
|
||||
default:
|
||||
throw new ParserException("TODO : " + lexer.token());
|
||||
throw new ParserException("TODO : " + lexer.info());
|
||||
}
|
||||
break;
|
||||
case PLUS:
|
||||
@@ -546,7 +546,7 @@ public class SQLExprParser extends SQLParser {
|
||||
sqlExpr = new SQLUnaryExpr(SQLUnaryOperator.Plus, sqlExpr);
|
||||
break;
|
||||
default:
|
||||
throw new ParserException("TODO");
|
||||
throw new ParserException("TODO " + lexer.info());
|
||||
}
|
||||
break;
|
||||
case TILDE:
|
||||
@@ -702,7 +702,7 @@ public class SQLExprParser extends SQLParser {
|
||||
}
|
||||
|
||||
protected SQLExpr parseInterval() {
|
||||
throw new ParserException("TODO");
|
||||
throw new ParserException("TODO. " + lexer.info());
|
||||
}
|
||||
|
||||
public SQLSelectParser createSelectParser() {
|
||||
@@ -861,7 +861,7 @@ public class SQLExprParser extends SQLParser {
|
||||
return primaryRest(methodInvokeExpr);
|
||||
}
|
||||
|
||||
throw new ParserException("not support token:" + lexer.token());
|
||||
throw new ParserException("not support token:" + lexer.token() + ", " + lexer.info());
|
||||
}
|
||||
|
||||
protected SQLExpr dotRest(SQLExpr expr) {
|
||||
@@ -879,7 +879,7 @@ public class SQLExprParser extends SQLParser {
|
||||
name = lexer.stringVal();
|
||||
lexer.nextToken();
|
||||
} else {
|
||||
throw new ParserException("error : " + lexer.stringVal());
|
||||
throw new ParserException("error : " + lexer.info());
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.LPAREN) {
|
||||
@@ -1073,7 +1073,7 @@ public class SQLExprParser extends SQLParser {
|
||||
|
||||
if (lexer.token() != Token.LITERAL_ALIAS && lexer.token() != Token.IDENTIFIER
|
||||
&& (!lexer.getKeywods().containsValue(lexer.token()))) {
|
||||
throw new ParserException("error, " + lexer.token());
|
||||
throw new ParserException("error, " + lexer.info());
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.LITERAL_ALIAS) {
|
||||
@@ -1280,7 +1280,7 @@ public class SQLExprParser extends SQLParser {
|
||||
lexer.nextToken();
|
||||
item.setNullsOrderType(SQLSelectOrderByItem.NullsOrderType.NullsLast);
|
||||
} else {
|
||||
throw new ParserException("TODO " + lexer.token());
|
||||
throw new ParserException("TODO " + lexer.info());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1788,7 +1788,7 @@ public class SQLExprParser extends SQLParser {
|
||||
|
||||
return new SQLBinaryOpExpr(expr, SQLBinaryOperator.NotILike, rightExp, getDbType());
|
||||
} else {
|
||||
throw new ParserException("TODO " + lexer.token());
|
||||
throw new ParserException("TODO " + lexer.info());
|
||||
}
|
||||
return expr;
|
||||
}
|
||||
@@ -1932,7 +1932,7 @@ public class SQLExprParser extends SQLParser {
|
||||
lexer.nextToken();
|
||||
} else {
|
||||
throw new ParserException("syntax error, expect " + token + ", actual " + lexer.token() + " "
|
||||
+ lexer.stringVal());
|
||||
+ lexer.info());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2055,7 +2055,7 @@ public class SQLExprParser extends SQLParser {
|
||||
return parseColumnRest(column);
|
||||
}
|
||||
|
||||
throw new ParserException("TODO : " + lexer.token() + " " + lexer.stringVal());
|
||||
throw new ParserException("TODO : " + lexer.info());
|
||||
}
|
||||
|
||||
if (lexer.token == Token.CHECK) {
|
||||
@@ -2224,7 +2224,7 @@ public class SQLExprParser extends SQLParser {
|
||||
} else if (lexer.token() == Token.CHECK) {
|
||||
constraint = parseCheck();
|
||||
} else {
|
||||
throw new ParserException("TODO : " + lexer.token() + " " + lexer.stringVal());
|
||||
throw new ParserException("TODO : " + lexer.info());
|
||||
}
|
||||
|
||||
constraint.setName(name);
|
||||
|
||||
@@ -56,7 +56,7 @@ public class SQLParser {
|
||||
lexer.nextToken();
|
||||
} else {
|
||||
setErrorEndPos(lexer.pos());
|
||||
throw new ParserException("syntax error, expect " + text + ", actual " + lexer.token());
|
||||
throw new ParserException("syntax error, expect " + text + ", actual " + lexer.token() + ", " + lexer.info());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ public class SQLParser {
|
||||
return null;
|
||||
}
|
||||
|
||||
throw new ParserException("Error : " + lexer.token());
|
||||
throw new ParserException("Error : " + lexer.info());
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.LITERAL_ALIAS) {
|
||||
@@ -296,14 +296,14 @@ public class SQLParser {
|
||||
return intVal;
|
||||
} else {
|
||||
throw new ParserException("syntax error, expect int, actual " + lexer.token() + " "
|
||||
+ lexer.stringVal());
|
||||
+ lexer.info());
|
||||
}
|
||||
}
|
||||
|
||||
public void match(Token token) {
|
||||
if (lexer.token() != token) {
|
||||
throw new ParserException("syntax error, expect " + token + ", actual " + lexer.token() + " "
|
||||
+ lexer.stringVal());
|
||||
+ lexer.info());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -419,7 +419,7 @@ public class SQLSelectParser extends SQLParser {
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.SELECT) {
|
||||
throw new ParserException("TODO");
|
||||
throw new ParserException("TODO " + lexer.info());
|
||||
}
|
||||
|
||||
SQLExprTableSource tableReference = new SQLExprTableSource();
|
||||
@@ -608,7 +608,7 @@ public class SQLSelectParser extends SQLParser {
|
||||
lexer.nextToken();
|
||||
} else {
|
||||
setErrorEndPos(lexer.pos());
|
||||
throw new ParserException("syntax error, expect " + ident + ", actual " + lexer.token());
|
||||
throw new ParserException("syntax error, expect " + ident + ", actual " + lexer.token() + ", " + lexer.info());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -509,11 +509,11 @@ public class SQLStatementParser extends SQLParser {
|
||||
}
|
||||
|
||||
public SQLStatement parseCommit() {
|
||||
throw new ParserException("TODO " + lexer.token() + " " + lexer.stringVal());
|
||||
throw new ParserException("TODO " + lexer.info());
|
||||
}
|
||||
|
||||
public SQLStatement parseShow() {
|
||||
throw new ParserException("TODO " + lexer.token() + " " + lexer.stringVal());
|
||||
throw new ParserException("TODO " + lexer.info());
|
||||
}
|
||||
|
||||
public SQLUseStatement parseUse() {
|
||||
@@ -947,7 +947,7 @@ public class SQLStatementParser extends SQLParser {
|
||||
|
||||
stmt.addItem(addPartition);
|
||||
} else {
|
||||
throw new ParserException("TODO " + lexer.token() + " " + lexer.stringVal());
|
||||
throw new ParserException("TODO " + lexer.info());
|
||||
}
|
||||
} else if (lexer.token() == Token.DISABLE) {
|
||||
lexer.nextToken();
|
||||
@@ -991,7 +991,7 @@ public class SQLStatementParser extends SQLParser {
|
||||
SQLAlterTableAlterColumn alterColumn = parseAlterColumn();
|
||||
stmt.addItem(alterColumn);
|
||||
} else {
|
||||
throw new ParserException("TODO " + lexer.token() + " " + lexer.stringVal());
|
||||
throw new ParserException("TODO " + lexer.info());
|
||||
}
|
||||
} else if (identifierEquals("CHANGE")) {
|
||||
lexer.nextToken();
|
||||
@@ -1055,7 +1055,7 @@ public class SQLStatementParser extends SQLParser {
|
||||
setLifecycle.setLifecycle(this.exprParser.primary());
|
||||
stmt.addItem(setLifecycle);
|
||||
} else {
|
||||
throw new ParserException("TODO " + lexer.token() + " " + lexer.stringVal());
|
||||
throw new ParserException("TODO " + lexer.info());
|
||||
}
|
||||
} else if (lexer.token() == Token.PARTITION) {
|
||||
lexer.nextToken();
|
||||
@@ -1151,9 +1151,9 @@ public class SQLStatementParser extends SQLParser {
|
||||
|
||||
return stmt;
|
||||
}
|
||||
throw new ParserException("TODO " + lexer.token() + " " + lexer.stringVal());
|
||||
throw new ParserException("TODO " + lexer.info());
|
||||
}
|
||||
throw new ParserException("TODO " + lexer.token() + " " + lexer.stringVal());
|
||||
throw new ParserException("TODO " + lexer.info());
|
||||
}
|
||||
|
||||
protected SQLAlterTableItem parseAlterTableRename() {
|
||||
@@ -1175,7 +1175,7 @@ public class SQLStatementParser extends SQLParser {
|
||||
return item;
|
||||
}
|
||||
|
||||
throw new ParserException("TODO " + lexer.token() + " " + lexer.stringVal());
|
||||
throw new ParserException("TODO " + lexer.info());
|
||||
}
|
||||
|
||||
protected SQLAlterTableAlterColumn parseAlterColumn() {
|
||||
@@ -1236,7 +1236,7 @@ public class SQLStatementParser extends SQLParser {
|
||||
item.setIndexName(indexName);
|
||||
stmt.addItem(item);
|
||||
} else {
|
||||
throw new ParserException("TODO " + lexer.token() + " " + lexer.stringVal());
|
||||
throw new ParserException("TODO " + lexer.info());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1267,7 +1267,7 @@ public class SQLStatementParser extends SQLParser {
|
||||
}
|
||||
|
||||
public SQLStatement parseRename() {
|
||||
throw new ParserException("TODO " + lexer.token() + " " + lexer.stringVal());
|
||||
throw new ParserException("TODO " + lexer.info());
|
||||
}
|
||||
|
||||
protected SQLDropTableStatement parseDropTable(boolean acceptDrop) {
|
||||
@@ -1818,7 +1818,7 @@ public class SQLStatementParser extends SQLParser {
|
||||
}
|
||||
|
||||
// lexer.reset(mark_bp, mark_ch, Token.CREATE);
|
||||
throw new ParserException("TODO " + lexer.token() + " " + lexer.stringVal());
|
||||
throw new ParserException("TODO " + lexer.info());
|
||||
} else if (token == Token.DATABASE) {
|
||||
lexer.nextToken();
|
||||
if (identifierEquals("LINK")) {
|
||||
|
||||
Reference in New Issue
Block a user