提交 12627199 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Add more context-sensitive keywords

上级 a8488f5f
...@@ -540,6 +540,8 @@ The following tokens are keywords in H2: ...@@ -540,6 +540,8 @@ The following tokens are keywords in H2:
<td>+</td><td>+</td><td>+</td><td>+</td><td>+</td><td>+</td></tr> <td>+</td><td>+</td><td>+</td><td>+</td><td>+</td><td>+</td></tr>
<tr><td>GROUP</td> <tr><td>GROUP</td>
<td>+</td><td>+</td><td>+</td><td>+</td><td>+</td><td>+</td></tr> <td>+</td><td>+</td><td>+</td><td>+</td><td>+</td><td>+</td></tr>
<tr><td>GROUPS</td>
<td>CS</td><td>+</td><td></td><td></td><td></td><td></td></tr>
<tr><td>HAVING</td> <tr><td>HAVING</td>
<td>+</td><td>+</td><td>+</td><td>+</td><td>+</td><td>+</td></tr> <td>+</td><td>+</td><td>+</td><td>+</td><td>+</td><td>+</td></tr>
<tr><td>IF</td> <tr><td>IF</td>
...@@ -590,10 +592,14 @@ The following tokens are keywords in H2: ...@@ -590,10 +592,14 @@ The following tokens are keywords in H2:
<td>+</td><td>+</td><td>+</td><td>+</td><td>+</td><td>+</td></tr> <td>+</td><td>+</td><td>+</td><td>+</td><td>+</td><td>+</td></tr>
<tr><td>OVER</td> <tr><td>OVER</td>
<td>CS</td><td>+</td><td>+</td><td>+</td><td></td><td></td></tr> <td>CS</td><td>+</td><td>+</td><td>+</td><td></td><td></td></tr>
<tr><td>PARTITION</td>
<td>CS</td><td>+</td><td>+</td><td>+</td><td></td><td></td></tr>
<tr><td>PRIMARY</td> <tr><td>PRIMARY</td>
<td>+</td><td>+</td><td>+</td><td>+</td><td>+</td><td>+</td></tr> <td>+</td><td>+</td><td>+</td><td>+</td><td>+</td><td>+</td></tr>
<tr><td>QUALIFY</td> <tr><td>QUALIFY</td>
<td>+</td><td></td><td></td><td></td><td></td><td></td></tr> <td>+</td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td>RANGE</td>
<td>CS</td><td>+</td><td>+</td><td>+</td><td></td><td></td></tr>
<tr><td>REGEXP</td> <tr><td>REGEXP</td>
<td>CS</td><td></td><td></td><td></td><td></td><td></td></tr> <td>CS</td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td>RIGHT</td> <tr><td>RIGHT</td>
...@@ -604,6 +610,8 @@ The following tokens are keywords in H2: ...@@ -604,6 +610,8 @@ The following tokens are keywords in H2:
<td>+</td><td></td><td></td><td></td><td></td><td></td></tr> <td>+</td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td>ROWNUM</td> <tr><td>ROWNUM</td>
<td>+</td><td></td><td></td><td></td><td></td><td></td></tr> <td>+</td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td>ROWS</td>
<td>CS</td><td>+</td><td>+</td><td>+</td><td>+</td><td>+</td></tr>
<tr><td>SELECT</td> <tr><td>SELECT</td>
<td>+</td><td>+</td><td>+</td><td>+</td><td>+</td><td>+</td></tr> <td>+</td><td>+</td><td>+</td><td>+</td><td>+</td><td>+</td></tr>
<tr><td>SYSDATE</td> <tr><td>SYSDATE</td>
......
...@@ -1541,6 +1541,7 @@ public class JdbcDatabaseMetaData extends TraceObject implements ...@@ -1541,6 +1541,7 @@ public class JdbcDatabaseMetaData extends TraceObject implements
* table/column/index name, in addition to the SQL:2003 keywords. The list * table/column/index name, in addition to the SQL:2003 keywords. The list
* returned is: * returned is:
* <pre> * <pre>
* GROUPS
* IF,ILIKE,INTERSECTS, * IF,ILIKE,INTERSECTS,
* LIMIT, * LIMIT,
* MINUS, * MINUS,
...@@ -1558,7 +1559,7 @@ public class JdbcDatabaseMetaData extends TraceObject implements ...@@ -1558,7 +1559,7 @@ public class JdbcDatabaseMetaData extends TraceObject implements
* DISTINCT, * DISTINCT,
* EXCEPT, EXISTS, * EXCEPT, EXISTS,
* FALSE, FETCH, FILTER, FOR, FOREIGN, FROM, FULL, * FALSE, FETCH, FILTER, FOR, FOREIGN, FROM, FULL,
* GROUP, * GROUP, GROUPS
* HAVING, * HAVING,
* IF, ILIKE, IN, INNER, INTERSECT, INTERSECTS, INTERVAL, IS, * IF, ILIKE, IN, INNER, INTERSECT, INTERSECTS, INTERVAL, IS,
* JOIN, * JOIN,
...@@ -1566,9 +1567,9 @@ public class JdbcDatabaseMetaData extends TraceObject implements ...@@ -1566,9 +1567,9 @@ public class JdbcDatabaseMetaData extends TraceObject implements
* MINUS, * MINUS,
* NATURAL, NOT, NULL, * NATURAL, NOT, NULL,
* OFFSET, ON, OR, ORDER, OVER, * OFFSET, ON, OR, ORDER, OVER,
* PRIMARY, * PARTITION, PRIMARY,
* QUALIFY, * QUALIFY,
* REGEXP, RIGHT, ROW, _ROWID_, ROWNUM, * RANGE, REGEXP, RIGHT, ROW, _ROWID_, ROWNUM, ROWS,
* SELECT, SYSDATE, SYSTIME, SYSTIMESTAMP, * SELECT, SYSDATE, SYSTIME, SYSTIMESTAMP,
* TABLE, TODAY, TOP, TRAILING, TRUE, * TABLE, TODAY, TOP, TRAILING, TRUE,
* UNION, UNIQUE, * UNION, UNIQUE,
...@@ -1581,7 +1582,8 @@ public class JdbcDatabaseMetaData extends TraceObject implements ...@@ -1581,7 +1582,8 @@ public class JdbcDatabaseMetaData extends TraceObject implements
@Override @Override
public String getSQLKeywords() { public String getSQLKeywords() {
debugCodeCall("getSQLKeywords"); debugCodeCall("getSQLKeywords");
return "IF,ILIKE,INTERSECTS," // return "GROUPS," //
+ "IF,ILIKE,INTERSECTS," //
+ "LIMIT," // + "LIMIT," //
+ "MINUS," // + "MINUS," //
+ "OFFSET," // + "OFFSET," //
......
...@@ -472,6 +472,11 @@ public class ParserUtil { ...@@ -472,6 +472,11 @@ public class ParserUtil {
if (eq("GROUP", s, ignoreCase, start, end)) { if (eq("GROUP", s, ignoreCase, start, end)) {
return GROUP; return GROUP;
} }
if (additionalKeywords) {
if (eq("GROUPS", s, ignoreCase, start, end)) {
return KEYWORD;
}
}
return IDENTIFIER; return IDENTIFIER;
case 'H': case 'H':
if (eq("HAVING", s, ignoreCase, start, end)) { if (eq("HAVING", s, ignoreCase, start, end)) {
...@@ -551,6 +556,11 @@ public class ParserUtil { ...@@ -551,6 +556,11 @@ public class ParserUtil {
if (eq("PRIMARY", s, ignoreCase, start, end)) { if (eq("PRIMARY", s, ignoreCase, start, end)) {
return PRIMARY; return PRIMARY;
} }
if (additionalKeywords) {
if (eq("PARTITION", s, ignoreCase, start, end)) {
return KEYWORD;
}
}
return IDENTIFIER; return IDENTIFIER;
case 'Q': case 'Q':
if (eq("QUALIFY", s, ignoreCase, start, end)) { if (eq("QUALIFY", s, ignoreCase, start, end)) {
...@@ -564,7 +574,8 @@ public class ParserUtil { ...@@ -564,7 +574,8 @@ public class ParserUtil {
return ROWNUM; return ROWNUM;
} }
if (additionalKeywords) { if (additionalKeywords) {
if (eq("REGEXP", s, ignoreCase, start, end) || eq("RIGHT", s, ignoreCase, start, end)) { if (eq("RANGE", s, ignoreCase, start, end) || eq("REGEXP", s, ignoreCase, start, end)
|| eq("ROWS", s, ignoreCase, start, end) || eq("RIGHT", s, ignoreCase, start, end)) {
return KEYWORD; return KEYWORD;
} }
} }
......
...@@ -463,7 +463,8 @@ public class TestMetaData extends TestDb { ...@@ -463,7 +463,8 @@ public class TestMetaData extends TestDb {
assertEquals("schema", meta.getSchemaTerm()); assertEquals("schema", meta.getSchemaTerm());
assertEquals("\\", meta.getSearchStringEscape()); assertEquals("\\", meta.getSearchStringEscape());
assertEquals("IF,ILIKE,INTERSECTS," // assertEquals("GROUPS," //
+ "IF,ILIKE,INTERSECTS," //
+ "LIMIT," // + "LIMIT," //
+ "MINUS," // + "MINUS," //
+ "OFFSET," // + "OFFSET," //
......
...@@ -100,6 +100,9 @@ public class TestKeywords extends TestBase { ...@@ -100,6 +100,9 @@ public class TestKeywords extends TestBase {
assertEquals("a", rs.getString(1)); assertEquals("a", rs.getString(1));
} }
stat.execute("DROP TABLE TEST"); stat.execute("DROP TABLE TEST");
try (ResultSet rs = stat
.executeQuery("SELECT ROW_NUMBER() OVER(" + s + ") WINDOW " + s + " AS ()")) {
}
} catch (Throwable t) { } catch (Throwable t) {
throw new AssertionError(s + " cannot be used as identifier.", t); throw new AssertionError(s + " cannot be used as identifier.", t);
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论