mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
odps sql parser improved comment support
This commit is contained in:
@@ -22,7 +22,6 @@ import static com.alibaba.druid.sql.parser.Token.LITERAL_CHARS;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.alibaba.druid.sql.parser.CharTypes;
|
||||
import com.alibaba.druid.sql.parser.Keywords;
|
||||
import com.alibaba.druid.sql.parser.Lexer;
|
||||
import com.alibaba.druid.sql.parser.NotAllowCommentException;
|
||||
@@ -512,9 +511,28 @@ public class MySqlLexer extends Lexer {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private final static boolean[] identifierFlags = new boolean[256];
|
||||
static {
|
||||
for (char c = 0; c < identifierFlags.length; ++c) {
|
||||
if (c >= 'A' && c <= 'Z') {
|
||||
identifierFlags[c] = true;
|
||||
} else if (c >= 'a' && c <= 'z') {
|
||||
identifierFlags[c] = true;
|
||||
} else if (c >= '0' && c <= '9') {
|
||||
identifierFlags[c] = true;
|
||||
}
|
||||
}
|
||||
// identifierFlags['`'] = true;
|
||||
identifierFlags['_'] = true;
|
||||
identifierFlags['-'] = true; // mysql
|
||||
}
|
||||
|
||||
private boolean isIdentifierChar(char c) {
|
||||
return c != '#' && CharTypes.isIdentifierChar(c);
|
||||
public static boolean isIdentifierChar(char c) {
|
||||
if (c <= identifierFlags.length) {
|
||||
return identifierFlags[c];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void scanNumber() {
|
||||
|
||||
@@ -73,6 +73,10 @@ public class OdpsCreateTableParser extends SQLCreateTableParser {
|
||||
} else {
|
||||
accept(Token.LPAREN);
|
||||
|
||||
if (lexer.isKeepComments() && lexer.hasComment()) {
|
||||
stmt.addBodyBeforeComment(lexer.readAndResetComments());
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
if (lexer.token() != Token.IDENTIFIER) {
|
||||
throw new ParserException("expect identifier");
|
||||
|
||||
@@ -96,6 +96,12 @@ public class OdpsOutputVisitor extends SQLASTOutputVisitor implements OdpsASTVis
|
||||
int size = x.getTableElementList().size();
|
||||
if (size > 0) {
|
||||
print0(" (");
|
||||
|
||||
if (this.isPrettyFormat() && x.hasBodyBeforeComment()) {
|
||||
print(' ');
|
||||
printComment(x.getBodyBeforeCommentsDirect(), "");
|
||||
}
|
||||
|
||||
incrementIndent();
|
||||
println();
|
||||
for (int i = 0; i < size; ++i) {
|
||||
|
||||
Reference in New Issue
Block a user