Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
94d97acd
提交
94d97acd
authored
6 年前
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add token types for all keywords and use them instead of strings
上级
81bb6b2e
全部展开
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
795 行增加
和
358 行删除
+795
-358
Parser.java
h2/src/main/org/h2/command/Parser.java
+575
-319
ParserUtil.java
h2/src/main/org/h2/util/ParserUtil.java
+220
-39
没有找到文件。
h2/src/main/org/h2/command/Parser.java
浏览文件 @
94d97acd
差异被折叠。
点击展开。
h2/src/main/org/h2/util/ParserUtil.java
浏览文件 @
94d97acd
...
@@ -18,24 +18,199 @@ public class ParserUtil {
...
@@ -18,24 +18,199 @@ public class ParserUtil {
public
static
final
int
IDENTIFIER
=
2
;
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
()
{
private
ParserUtil
()
{
// utility class
// utility class
...
@@ -95,14 +270,14 @@ public class ParserUtil {
...
@@ -95,14 +270,14 @@ public class ParserUtil {
*/
*/
switch
(
s
.
charAt
(
0
))
{
switch
(
s
.
charAt
(
0
))
{
case
'A'
:
case
'A'
:
return
getKeywordOrIdentifier
(
s
,
"ALL"
,
KEYWORD
);
return
getKeywordOrIdentifier
(
s
,
"ALL"
,
ALL
);
case
'C'
:
case
'C'
:
if
(
"CHECK"
.
equals
(
s
))
{
if
(
"CHECK"
.
equals
(
s
))
{
return
KEYWORD
;
return
CHECK
;
}
else
if
(
"CONSTRAINT"
.
equals
(
s
))
{
}
else
if
(
"CONSTRAINT"
.
equals
(
s
))
{
return
KEYWORD
;
return
CONSTRAINT
;
}
else
if
(
"CROSS"
.
equals
(
s
))
{
}
else
if
(
"CROSS"
.
equals
(
s
))
{
return
KEYWORD
;
return
CROSS
;
}
}
if
(
additionalKeywords
)
{
if
(
additionalKeywords
)
{
if
(
"CURRENT_DATE"
.
equals
(
s
)
||
"CURRENT_TIME"
.
equals
(
s
)
||
"CURRENT_TIMESTAMP"
.
equals
(
s
))
{
if
(
"CURRENT_DATE"
.
equals
(
s
)
||
"CURRENT_TIME"
.
equals
(
s
)
||
"CURRENT_TIMESTAMP"
.
equals
(
s
))
{
...
@@ -111,32 +286,36 @@ public class ParserUtil {
...
@@ -111,32 +286,36 @@ public class ParserUtil {
}
}
return
IDENTIFIER
;
return
IDENTIFIER
;
case
'D'
:
case
'D'
:
return
getKeywordOrIdentifier
(
s
,
"DISTINCT"
,
KEYWORD
);
return
getKeywordOrIdentifier
(
s
,
"DISTINCT"
,
DISTINCT
);
case
'E'
:
case
'E'
:
if
(
"EXCEPT"
.
equals
(
s
))
{
if
(
"EXCEPT"
.
equals
(
s
))
{
return
KEYWORD
;
return
EXCEPT
;
}
}
return
getKeywordOrIdentifier
(
s
,
"EXISTS"
,
KEYWORD
);
return
getKeywordOrIdentifier
(
s
,
"EXISTS"
,
EXISTS
);
case
'F'
:
case
'F'
:
if
(
"FETCH"
.
equals
(
s
))
{
if
(
"FETCH"
.
equals
(
s
))
{
return
KEYWORD
;
return
FETCH
;
}
else
if
(
"FROM"
.
equals
(
s
))
{
}
else
if
(
"FROM"
.
equals
(
s
))
{
return
KEYWORD
;
return
FROM
;
}
else
if
(
"FOR"
.
equals
(
s
))
{
}
else
if
(
"FOR"
.
equals
(
s
))
{
return
KEYWORD
;
return
FOR
;
}
else
if
(
"FOREIGN"
.
equals
(
s
))
{
}
else
if
(
"FOREIGN"
.
equals
(
s
))
{
return
KEYWORD
;
return
FOREIGN
;
}
else
if
(
"FULL"
.
equals
(
s
))
{
}
else
if
(
"FULL"
.
equals
(
s
))
{
return
KEYWORD
;
return
FULL
;
}
}
return
getKeywordOrIdentifier
(
s
,
"FALSE"
,
FALSE
);
return
getKeywordOrIdentifier
(
s
,
"FALSE"
,
FALSE
);
case
'G'
:
case
'G'
:
return
getKeywordOrIdentifier
(
s
,
"GROUP"
,
KEYWORD
);
return
getKeywordOrIdentifier
(
s
,
"GROUP"
,
GROUP
);
case
'H'
:
case
'H'
:
return
getKeywordOrIdentifier
(
s
,
"HAVING"
,
KEYWORD
);
return
getKeywordOrIdentifier
(
s
,
"HAVING"
,
HAVING
);
case
'I'
:
case
'I'
:
if
(
"INNER"
.
equals
(
s
)
||
"INTERSECT"
.
equals
(
s
)
||
"IS"
.
equals
(
s
))
{
if
(
"INNER"
.
equals
(
s
))
{
return
KEYWORD
;
return
INNER
;
}
else
if
(
"INTERSECT"
.
equals
(
s
))
{
return
INTERSECT
;
}
else
if
(
"IS"
.
equals
(
s
))
{
return
IS
;
}
}
if
(
additionalKeywords
)
{
if
(
additionalKeywords
)
{
if
(
"INTERSECTS"
.
equals
(
s
))
{
if
(
"INTERSECTS"
.
equals
(
s
))
{
...
@@ -145,10 +324,12 @@ public class ParserUtil {
...
@@ -145,10 +324,12 @@ public class ParserUtil {
}
}
return
IDENTIFIER
;
return
IDENTIFIER
;
case
'J'
:
case
'J'
:
return
getKeywordOrIdentifier
(
s
,
"JOIN"
,
KEYWORD
);
return
getKeywordOrIdentifier
(
s
,
"JOIN"
,
JOIN
);
case
'L'
:
case
'L'
:
if
(
"LIMIT"
.
equals
(
s
)
||
"LIKE"
.
equals
(
s
))
{
if
(
"LIMIT"
.
equals
(
s
))
{
return
KEYWORD
;
return
LIMIT
;
}
else
if
(
"LIKE"
.
equals
(
s
))
{
return
LIKE
;
}
}
if
(
additionalKeywords
)
{
if
(
additionalKeywords
)
{
if
(
"LOCALTIME"
.
equals
(
s
)
||
"LOCALTIMESTAMP"
.
equals
(
s
))
{
if
(
"LOCALTIME"
.
equals
(
s
)
||
"LOCALTIMESTAMP"
.
equals
(
s
))
{
...
@@ -157,28 +338,28 @@ public class ParserUtil {
...
@@ -157,28 +338,28 @@ public class ParserUtil {
}
}
return
IDENTIFIER
;
return
IDENTIFIER
;
case
'M'
:
case
'M'
:
return
getKeywordOrIdentifier
(
s
,
"MINUS"
,
KEYWORD
);
return
getKeywordOrIdentifier
(
s
,
"MINUS"
,
MINUS
);
case
'N'
:
case
'N'
:
if
(
"NOT"
.
equals
(
s
))
{
if
(
"NOT"
.
equals
(
s
))
{
return
KEYWORD
;
return
NOT
;
}
else
if
(
"NATURAL"
.
equals
(
s
))
{
}
else
if
(
"NATURAL"
.
equals
(
s
))
{
return
KEYWORD
;
return
NATURAL
;
}
}
return
getKeywordOrIdentifier
(
s
,
"NULL"
,
NULL
);
return
getKeywordOrIdentifier
(
s
,
"NULL"
,
NULL
);
case
'O'
:
case
'O'
:
if
(
"OFFSET"
.
equals
(
s
))
{
if
(
"OFFSET"
.
equals
(
s
))
{
return
KEYWORD
;
return
OFFSET
;
}
else
if
(
"ON"
.
equals
(
s
))
{
}
else
if
(
"ON"
.
equals
(
s
))
{
return
KEYWORD
;
return
ON
;
}
}
return
getKeywordOrIdentifier
(
s
,
"ORDER"
,
KEYWORD
);
return
getKeywordOrIdentifier
(
s
,
"ORDER"
,
ORDER
);
case
'P'
:
case
'P'
:
return
getKeywordOrIdentifier
(
s
,
"PRIMARY"
,
KEYWORD
);
return
getKeywordOrIdentifier
(
s
,
"PRIMARY"
,
PRIMARY
);
case
'R'
:
case
'R'
:
return
getKeywordOrIdentifier
(
s
,
"ROWNUM"
,
ROWNUM
);
return
getKeywordOrIdentifier
(
s
,
"ROWNUM"
,
ROWNUM
);
case
'S'
:
case
'S'
:
if
(
"SELECT"
.
equals
(
s
))
{
if
(
"SELECT"
.
equals
(
s
))
{
return
KEYWORD
;
return
SELECT
;
}
}
if
(
additionalKeywords
)
{
if
(
additionalKeywords
)
{
if
(
"SYSDATE"
.
equals
(
s
)
||
"SYSTIME"
.
equals
(
s
)
||
"SYSTIMESTAMP"
.
equals
(
s
))
{
if
(
"SYSDATE"
.
equals
(
s
)
||
"SYSTIME"
.
equals
(
s
)
||
"SYSTIMESTAMP"
.
equals
(
s
))
{
...
@@ -198,14 +379,14 @@ public class ParserUtil {
...
@@ -198,14 +379,14 @@ public class ParserUtil {
return
IDENTIFIER
;
return
IDENTIFIER
;
case
'U'
:
case
'U'
:
if
(
"UNIQUE"
.
equals
(
s
))
{
if
(
"UNIQUE"
.
equals
(
s
))
{
return
KEYWORD
;
return
UNIQUE
;
}
}
return
getKeywordOrIdentifier
(
s
,
"UNION"
,
KEYWORD
);
return
getKeywordOrIdentifier
(
s
,
"UNION"
,
UNION
);
case
'W'
:
case
'W'
:
if
(
"WITH"
.
equals
(
s
))
{
if
(
"WITH"
.
equals
(
s
))
{
return
KEYWORD
;
return
WITH
;
}
}
return
getKeywordOrIdentifier
(
s
,
"WHERE"
,
KEYWORD
);
return
getKeywordOrIdentifier
(
s
,
"WHERE"
,
WHERE
);
default
:
default
:
return
IDENTIFIER
;
return
IDENTIFIER
;
}
}
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论