提交 94d97acd authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Add token types for all keywords and use them instead of strings

上级 81bb6b2e
......@@ -18,24 +18,199 @@ public class ParserUtil {
public static final int IDENTIFIER = 2;
/**
* The token "null".
* The token "ALL".
*/
public static final int NULL = 3;
public static final int ALL = IDENTIFIER + 1;
/**
* The token "true".
* The token "CHECK".
*/
public static final int TRUE = 4;
public static final int CHECK = ALL + 1;
/**
* The token "false".
* The token "CONSTRAINT".
*/
public static final int FALSE = 5;
public static final int CONSTRAINT = CHECK + 1;
/**
* The token "rownum".
* The token "CROSS".
*/
public static final int ROWNUM = 6;
public static final int CROSS = CONSTRAINT + 1;
/**
* The token "CURRENT_DATE".
*/
public static final int CURRENT_DATE = CROSS + 1;
/**
* The token "CURRENT_TIME".
*/
public static final int CURRENT_TIME = CURRENT_DATE + 1;
/**
* The token "CURRENT_TIMESTAMP".
*/
public static final int CURRENT_TIMESTAMP = CURRENT_TIME + 1;
/**
* The token "DISTINCT".
*/
public static final int DISTINCT = CURRENT_TIMESTAMP + 1;
/**
* The token "EXCEPT".
*/
public static final int EXCEPT = DISTINCT + 1;
/**
* The token "EXISTS".
*/
public static final int EXISTS = EXCEPT + 1;
/**
* The token "FALSE".
*/
public static final int FALSE = EXISTS + 1;
/**
* The token "FETCH".
*/
public static final int FETCH = FALSE + 1;
/**
* The token "FOR".
*/
public static final int FOR = FETCH + 1;
/**
* The token "FOREIGN".
*/
public static final int FOREIGN = FOR + 1;
/**
* The token "FROM".
*/
public static final int FROM = FOREIGN + 1;
/**
* The token "FULL".
*/
public static final int FULL = FROM + 1;
/**
* The token "GROUP".
*/
public static final int GROUP = FULL + 1;
/**
* The token "HAVING".
*/
public static final int HAVING = GROUP + 1;
/**
* The token "INNER".
*/
public static final int INNER = HAVING + 1;
/**
* The token "INTERSECT".
*/
public static final int INTERSECT = INNER + 1;
/**
* The token "IS".
*/
public static final int IS = INTERSECT + 1;
/**
* The token "JOIN".
*/
public static final int JOIN = IS + 1;
/**
* The token "LIKE".
*/
public static final int LIKE = JOIN + 1;
/**
* The token "LIMIT".
*/
public static final int LIMIT = LIKE + 1;
/**
* The token "MINUS".
*/
public static final int MINUS = LIMIT + 1;
/**
* The token "NATURAL".
*/
public static final int NATURAL = MINUS + 1;
/**
* The token "NOT".
*/
public static final int NOT = NATURAL + 1;
/**
* The token "NULL".
*/
public static final int NULL = NOT + 1;
/**
* The token "OFFSET".
*/
public static final int OFFSET = NULL + 1;
/**
* The token "ON".
*/
public static final int ON = OFFSET + 1;
/**
* The token "ORDER".
*/
public static final int ORDER = ON + 1;
/**
* The token "PRIMARY".
*/
public static final int PRIMARY = ORDER + 1;
/**
* The token "ROWNUM".
*/
public static final int ROWNUM = PRIMARY + 1;
/**
* The token "SELECT".
*/
public static final int SELECT = ROWNUM + 1;
/**
* The token "TRUE".
*/
public static final int TRUE = SELECT + 1;
/**
* The token "UNION".
*/
public static final int UNION = TRUE + 1;
/**
* The token "UNIQUE".
*/
public static final int UNIQUE = UNION + 1;
/**
* The token "WHERE".
*/
public static final int WHERE = UNIQUE + 1;
/**
* The token "WITH".
*/
public static final int WITH = WHERE + 1;
private ParserUtil() {
// utility class
......@@ -95,14 +270,14 @@ public class ParserUtil {
*/
switch (s.charAt(0)) {
case 'A':
return getKeywordOrIdentifier(s, "ALL", KEYWORD);
return getKeywordOrIdentifier(s, "ALL", ALL);
case 'C':
if ("CHECK".equals(s)) {
return KEYWORD;
return CHECK;
} else if ("CONSTRAINT".equals(s)) {
return KEYWORD;
return CONSTRAINT;
} else if ("CROSS".equals(s)) {
return KEYWORD;
return CROSS;
}
if (additionalKeywords) {
if ("CURRENT_DATE".equals(s) || "CURRENT_TIME".equals(s) || "CURRENT_TIMESTAMP".equals(s)) {
......@@ -111,32 +286,36 @@ public class ParserUtil {
}
return IDENTIFIER;
case 'D':
return getKeywordOrIdentifier(s, "DISTINCT", KEYWORD);
return getKeywordOrIdentifier(s, "DISTINCT", DISTINCT);
case 'E':
if ("EXCEPT".equals(s)) {
return KEYWORD;
return EXCEPT;
}
return getKeywordOrIdentifier(s, "EXISTS", KEYWORD);
return getKeywordOrIdentifier(s, "EXISTS", EXISTS);
case 'F':
if ("FETCH".equals(s)) {
return KEYWORD;
return FETCH;
} else if ("FROM".equals(s)) {
return KEYWORD;
return FROM;
} else if ("FOR".equals(s)) {
return KEYWORD;
return FOR;
} else if ("FOREIGN".equals(s)) {
return KEYWORD;
return FOREIGN;
} else if ("FULL".equals(s)) {
return KEYWORD;
return FULL;
}
return getKeywordOrIdentifier(s, "FALSE", FALSE);
case 'G':
return getKeywordOrIdentifier(s, "GROUP", KEYWORD);
return getKeywordOrIdentifier(s, "GROUP", GROUP);
case 'H':
return getKeywordOrIdentifier(s, "HAVING", KEYWORD);
return getKeywordOrIdentifier(s, "HAVING", HAVING);
case 'I':
if ("INNER".equals(s) || "INTERSECT".equals(s) || "IS".equals(s)) {
return KEYWORD;
if ("INNER".equals(s)) {
return INNER;
} else if ("INTERSECT".equals(s)) {
return INTERSECT;
} else if ("IS".equals(s)) {
return IS;
}
if (additionalKeywords) {
if ("INTERSECTS".equals(s)) {
......@@ -145,10 +324,12 @@ public class ParserUtil {
}
return IDENTIFIER;
case 'J':
return getKeywordOrIdentifier(s, "JOIN", KEYWORD);
return getKeywordOrIdentifier(s, "JOIN", JOIN);
case 'L':
if ("LIMIT".equals(s) || "LIKE".equals(s)) {
return KEYWORD;
if ("LIMIT".equals(s)) {
return LIMIT;
} else if ("LIKE".equals(s)) {
return LIKE;
}
if (additionalKeywords) {
if ("LOCALTIME".equals(s) || "LOCALTIMESTAMP".equals(s)) {
......@@ -157,28 +338,28 @@ public class ParserUtil {
}
return IDENTIFIER;
case 'M':
return getKeywordOrIdentifier(s, "MINUS", KEYWORD);
return getKeywordOrIdentifier(s, "MINUS", MINUS);
case 'N':
if ("NOT".equals(s)) {
return KEYWORD;
return NOT;
} else if ("NATURAL".equals(s)) {
return KEYWORD;
return NATURAL;
}
return getKeywordOrIdentifier(s, "NULL", NULL);
case 'O':
if ("OFFSET".equals(s)) {
return KEYWORD;
return OFFSET;
} else if ("ON".equals(s)) {
return KEYWORD;
return ON;
}
return getKeywordOrIdentifier(s, "ORDER", KEYWORD);
return getKeywordOrIdentifier(s, "ORDER", ORDER);
case 'P':
return getKeywordOrIdentifier(s, "PRIMARY", KEYWORD);
return getKeywordOrIdentifier(s, "PRIMARY", PRIMARY);
case 'R':
return getKeywordOrIdentifier(s, "ROWNUM", ROWNUM);
case 'S':
if ("SELECT".equals(s)) {
return KEYWORD;
return SELECT;
}
if (additionalKeywords) {
if ("SYSDATE".equals(s) || "SYSTIME".equals(s) || "SYSTIMESTAMP".equals(s)) {
......@@ -198,14 +379,14 @@ public class ParserUtil {
return IDENTIFIER;
case 'U':
if ("UNIQUE".equals(s)) {
return KEYWORD;
return UNIQUE;
}
return getKeywordOrIdentifier(s, "UNION", KEYWORD);
return getKeywordOrIdentifier(s, "UNION", UNION);
case 'W':
if ("WITH".equals(s)) {
return KEYWORD;
return WITH;
}
return getKeywordOrIdentifier(s, "WHERE", KEYWORD);
return getKeywordOrIdentifier(s, "WHERE", WHERE);
default:
return IDENTIFIER;
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论