improve sqlparser

This commit is contained in:
Yako
2014-11-09 00:13:39 +08:00
parent a70258ac23
commit 0355a7cc23
4 changed files with 236 additions and 3 deletions
@@ -534,4 +534,87 @@ public class MySqlLexer extends Lexer {
private boolean isIdentifierChar(char c) {
return c != '#' && CharTypes.isIdentifierChar(c);
}
public void scanNumber() {
mark = pos;
if (ch == '-') {
bufPos++;
ch = charAt(++pos);
}
for (;;) {
if (ch >= '0' && ch <= '9') {
bufPos++;
} else {
break;
}
ch = charAt(++pos);
}
boolean isDouble = false;
if (ch == '.') {
if (charAt(pos + 1) == '.') {
token = Token.LITERAL_INT;
return;
}
bufPos++;
ch = charAt(++pos);
isDouble = true;
for (;;) {
if (ch >= '0' && ch <= '9') {
bufPos++;
} else {
break;
}
ch = charAt(++pos);
}
}
if (ch == 'e' || ch == 'E') {
bufPos++;
ch = charAt(++pos);
if (ch == '+' || ch == '-') {
bufPos++;
ch = charAt(++pos);
}
for (;;) {
if (ch >= '0' && ch <= '9') {
bufPos++;
} else {
break;
}
ch = charAt(++pos);
}
isDouble = true;
}
if (isDouble) {
token = Token.LITERAL_FLOAT;
} else {
if (isFirstIdentifierChar(ch) && !(ch == 'b' && bufPos == 1 && charAt(pos - 1) == '0')) {
bufPos++;
for (;;) {
ch = charAt(++pos);
if (!isIdentifierChar(ch)) {
break;
}
bufPos++;
continue;
}
stringVal = addSymbol();
token = Token.IDENTIFIER;
} else {
token = Token.LITERAL_INT;
}
}
}
}
@@ -373,7 +373,7 @@ public class Lexer {
return;
case '.':
scanChar();
if (isDigit(ch)) {
if (isDigit(ch) && !isFirstIdentifierChar(charAt(pos - 2))) {
unscan();
scanNumber();
return;