-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Enhanced Keywords #1382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Enhanced Keywords #1382
Changes from 1 commit
Commits
Show all changes
65 commits
Select commit
Hold shift + click to select a range
834dab1
Enhanced Keywords
manticore-projects 7a885a1
Fix incorrect tests
manticore-projects 1b69d25
Merge remote-tracking branch 'origin/master' into Keywords
manticore-projects 5d20d06
Define Reserved Keywords explicitly
manticore-projects df9c56e
Fix test resources
manticore-projects de805ab
Adjust Gradle to JUnit 5
manticore-projects d5a6dca
Do not mark SpeedTest for concurrent execution
manticore-projects a9d0503
Remove unused imports
manticore-projects 6dfa05f
Adjust Gradle to JUnit 5
manticore-projects 8f0bfe6
Do not mark SpeedTest for concurrent execution
manticore-projects 5cd0974
Remove unused imports
manticore-projects 5f11d3f
Merge remote-tracking branch 'origin/master'
manticore-projects 2af3cd5
Merge remote-tracking branch 'origin/Keywords' into Keywords
manticore-projects 4bef952
Merge remote-tracking branch 'origin/master' into Keywords
manticore-projects 1fd56ac
Keyword test adopt JUnit5
manticore-projects 873dfd4
Merge Master
manticore-projects 1a9db26
CheckStyle sanitation of method names
manticore-projects 3ab04b0
Merge https://github.com/JSQLParser/JSqlParser
manticore-projects de94651
Merge branch 'JSQLParser:master' into master
manticore-projects 84709a9
Merge branch 'master' of github.com:JSQLParser/JSqlParser
manticore-projects dc3ef91
Merge github.com:JSQLParser/JSqlParser into Keywords
manticore-projects 0e0662d
Merge Master
manticore-projects 3c8da30
Merge branch 'master' of github.com:JSQLParser/JSqlParser
manticore-projects cae7a1f
Merge branch 'master' into Keywords
manticore-projects 886fe59
Add Jupiter Parameters dependency again
manticore-projects 353edb4
Automate the `updateKeywords` Step
manticore-projects 0ad0b79
Update PMD and rules
manticore-projects ae46480
Rewrite test expected to fail
manticore-projects 74c1f71
Appease Codacy
manticore-projects ba9992e
Remove broken rule warning about perfectly fine switch-case statements
manticore-projects 7cad82e
Merge remote-tracking branch 'origin/master' into Keywords
manticore-projects a19b963
Force Changes
manticore-projects 8edf488
Fix Merge Issues
manticore-projects fbf0c8b
Merge remote-tracking branch 'manticore/Keywords' into Keywords
manticore-projects 83b8a03
Read Tokens directly from the Grammar File without invoking JTREE
manticore-projects 452e8a5
Appease PMD/Codacy
manticore-projects bde4da3
Merge Origin/Master
manticore-projects 0ce18dd
Extract the Keywords from the Grammar by using JTRee (instead of Regex)
manticore-projects 546fe16
Appease Codacy/PMD
manticore-projects 81c299f
Merge origin/master
manticore-projects 83166d2
Separate UpdateKeywords Task again
manticore-projects f4284a0
Clean-up the imports
manticore-projects cd462e5
Add JavaCC dependency to Maven for building ParserKeywordsUtils
manticore-projects a86edf5
Add JavaCC dependency to Maven for building ParserKeywordsUtils
manticore-projects 6b07f70
Merge branch 'master' of github.com:JSQLParser/JSqlParser
manticore-projects 8a8b718
Merge remote-tracking branch 'origin/master' into Keywords
manticore-projects d54c1fb
Merge Upstream
manticore-projects 1d89095
Merge remote-tracking branch 'manticore/Keywords' into Keywords
manticore-projects ab6f9d5
Merge Master
manticore-projects 39a3476
Merge github.com:JSQLParser/JSqlParser
manticore-projects 61bfb68
Merge Master
manticore-projects 796893d
Fixes broken PR #1524 and Commit fb6e950ce0e62ebcd7a44ba9eea679da2b04…
manticore-projects 520e1e6
Add AST Visualization
manticore-projects 7f4c510
Merge branch 'master' of github.com:JSQLParser/JSqlParser
manticore-projects a4032a2
Merge remote-tracking branch 'origin/master' into Keywords
manticore-projects 08141a3
Merge branch 'master' into Keywords
manticore-projects c512b8e
Merge branch 'master' of github.com:JSQLParser/JSqlParser into Keywords
manticore-projects 0c6f0e4
build: temporarily reduce the Code Coverage requirements
manticore-projects 6953d8b
Merge remote-tracking branch 'origin/master' into Keywords
manticore-projects a8ffe64
merge Master
manticore-projects 1d4eb9e
Merge branch 'master' into Keywords
manticore-projects b6146cf
build: JSQLParser is a build dependency
manticore-projects b07d839
chore: Update keywords
manticore-projects 1e159ba
Merge remote-tracking branch 'manticore/Keywords' into Keywords
manticore-projects b0d6218
feat: add line count to output
manticore-projects File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Read Tokens directly from the Grammar File without invoking JTREE
- read Tokens per REGEX Matcher - move Reserved Keywords from Grammar into ParserKeywordsUtils - adjust the Tests
- Loading branch information
commit 83b8a03885b7fe5536e5c18e285ab3f5ca6f9338
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ | |
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
| import java.util.*; | ||
| import java.util.regex.Matcher; | ||
| import java.util.regex.Pattern; | ||
|
|
||
| public class ParserKeywordsUtils { | ||
|
|
@@ -28,20 +29,156 @@ public class ParserKeywordsUtils { | |
| public final static int RESTRICTED_SQL2016 = 64; | ||
|
|
||
| public final static int RESTRICTED_JSQLPARSER = 128 | ||
| | RESTRICTED_FUNCTION | ||
| | RESTRICTED_SCHEMA | ||
| | RESTRICTED_TABLE | ||
| | RESTRICTED_COLUMN | ||
| | RESTRICTED_EXPRESSION | ||
| | RESTRICTED_ALIAS | ||
| | RESTRICTED_SQL2016; | ||
|
|
||
| public static List<String> getDefinedKeywords() throws Exception { | ||
| return CCJSqlParser.getDefinedKeywords(); | ||
| } | ||
| | RESTRICTED_FUNCTION | ||
| | RESTRICTED_SCHEMA | ||
| | RESTRICTED_TABLE | ||
| | RESTRICTED_COLUMN | ||
| | RESTRICTED_EXPRESSION | ||
| | RESTRICTED_ALIAS | ||
| | RESTRICTED_SQL2016; | ||
|
|
||
| public static List<String> getReservedKeywords(int restrictriction) { | ||
| // Classification follows http://www.h2database.com/html/advanced.html#keywords | ||
| Object[][] ALL_RESERVED_KEYWORDS = { | ||
| { "ABSENT", RESTRICTED_JSQLPARSER } | ||
| , { "ALL" , RESTRICTED_SQL2016 } | ||
| , { "AND" , RESTRICTED_SQL2016 } | ||
| , { "ANY" , RESTRICTED_JSQLPARSER } | ||
| , { "AS" , RESTRICTED_SQL2016 } | ||
| , { "BETWEEN" , RESTRICTED_SQL2016 } | ||
| , { "BOTH" , RESTRICTED_SQL2016 } | ||
| , { "CASEWHEN" , RESTRICTED_ALIAS } | ||
| , { "CHECK" , RESTRICTED_SQL2016 } | ||
| , { "CONNECT" , RESTRICTED_ALIAS } | ||
| , { "CONNECT_BY_ROOT" , RESTRICTED_JSQLPARSER } | ||
| , { "CONSTRAINT" , RESTRICTED_SQL2016 } | ||
| , { "CREATE" , RESTRICTED_ALIAS } | ||
| , { "CROSS" , RESTRICTED_SQL2016 } | ||
| , { "CURRENT" , RESTRICTED_JSQLPARSER } | ||
| , { "DISTINCT" , RESTRICTED_SQL2016 } | ||
| , { "DOUBLE" , RESTRICTED_ALIAS } | ||
| , { "ELSE" , RESTRICTED_JSQLPARSER } | ||
| , { "EXCEPT" , RESTRICTED_SQL2016 } | ||
| , { "EXISTS" , RESTRICTED_SQL2016 } | ||
| , { "FETCH" , RESTRICTED_SQL2016 } | ||
| , { "FOR" , RESTRICTED_SQL2016 } | ||
| , { "FORCE" , RESTRICTED_SQL2016 } | ||
| , { "FOREIGN" , RESTRICTED_SQL2016 } | ||
| , { "FROM" , RESTRICTED_SQL2016 } | ||
| , { "FULL", RESTRICTED_SQL2016 } | ||
| , { "GROUP", RESTRICTED_SQL2016 } | ||
| , { "GROUPING" , RESTRICTED_ALIAS } | ||
| , { "HAVING" , RESTRICTED_SQL2016 } | ||
| , { "IF" , RESTRICTED_SQL2016 } | ||
| , { "IIF" , RESTRICTED_ALIAS } | ||
| , { "IGNORE" , RESTRICTED_ALIAS } | ||
| , { "ILIKE" , RESTRICTED_SQL2016 } | ||
| , { "IN" , RESTRICTED_SQL2016 } | ||
| , { "INNER" , RESTRICTED_SQL2016 } | ||
| , { "INTERSECT" , RESTRICTED_SQL2016 } | ||
| , { "INTERVAL", RESTRICTED_SQL2016 } | ||
| , { "IS" , RESTRICTED_SQL2016 } | ||
| , { "JOIN" , RESTRICTED_JSQLPARSER } | ||
| , { "LATERAL" , RESTRICTED_SQL2016 } | ||
| , { "LEFT", RESTRICTED_SQL2016 } | ||
| , { "LIKE" , RESTRICTED_SQL2016 } | ||
| , { "LIMIT" , RESTRICTED_SQL2016 } | ||
| , { "MINUS" , RESTRICTED_SQL2016 } | ||
| , { "NATURAL" , RESTRICTED_SQL2016 } | ||
| , { "NOCYCLE" , RESTRICTED_JSQLPARSER } | ||
| , { "NOT", RESTRICTED_SQL2016 } | ||
| , { "NULL" , RESTRICTED_SQL2016 } | ||
| , { "OFFSET" , RESTRICTED_SQL2016 } | ||
| , { "ON" , RESTRICTED_SQL2016 } | ||
| , { "ONLY" , RESTRICTED_JSQLPARSER } | ||
| , { "OPTIMIZE" , RESTRICTED_ALIAS } | ||
| , { "OR" , RESTRICTED_SQL2016 } | ||
| , { "ORDER" , RESTRICTED_SQL2016 } | ||
| , { "OUTER" , RESTRICTED_JSQLPARSER } | ||
| , { "OPTIMIZE ", RESTRICTED_JSQLPARSER } | ||
| , { "PIVOT" , RESTRICTED_JSQLPARSER } | ||
| , { "PROCEDURE" , RESTRICTED_ALIAS } | ||
| , { "PUBLIC", RESTRICTED_ALIAS } | ||
| , { "RECURSIVE" , RESTRICTED_SQL2016 } | ||
| , { "REGEXP" , RESTRICTED_SQL2016 } | ||
| , { "RETURNING" , RESTRICTED_JSQLPARSER } | ||
| , { "RIGHT" , RESTRICTED_SQL2016 } | ||
| , { "SEL" , RESTRICTED_ALIAS } | ||
| , { "SELECT" , RESTRICTED_ALIAS } | ||
| , { "SEMI" , RESTRICTED_JSQLPARSER } | ||
| , { "SET" , RESTRICTED_JSQLPARSER } | ||
| , { "SOME" , RESTRICTED_JSQLPARSER } | ||
| , { "START" , RESTRICTED_JSQLPARSER } | ||
| , { "TABLES" , RESTRICTED_ALIAS } | ||
| , { "TOP" , RESTRICTED_SQL2016 } | ||
| , { "TRAILING", RESTRICTED_SQL2016 } | ||
| , { "UNBOUNDED" , RESTRICTED_JSQLPARSER } | ||
| , { "UNION" , RESTRICTED_SQL2016 } | ||
| , { "UNIQUE" , RESTRICTED_SQL2016 } | ||
| , { "UNPIVOT" , RESTRICTED_JSQLPARSER } | ||
| , { "USE" , RESTRICTED_JSQLPARSER } | ||
| , { "USING" , RESTRICTED_SQL2016 } | ||
| , { "SQL_CACHE" , RESTRICTED_JSQLPARSER } | ||
| , { "SQL_CALC_FOUND_ROWS" , RESTRICTED_JSQLPARSER } | ||
| , { "SQL_NO_CACHE" , RESTRICTED_JSQLPARSER } | ||
| , { "STRAIGHT_JOIN" , RESTRICTED_JSQLPARSER } | ||
| , { "VALUE", RESTRICTED_JSQLPARSER } | ||
| , { "VALUES" , RESTRICTED_SQL2016 } | ||
| , { "VARYING" , RESTRICTED_JSQLPARSER } | ||
| , { "WHEN" , RESTRICTED_SQL2016 } | ||
| , { "WHERE" , RESTRICTED_SQL2016 } | ||
| , { "WINDOW" , RESTRICTED_SQL2016 } | ||
| , { "WITH" , RESTRICTED_SQL2016 } | ||
| , { "XOR", RESTRICTED_JSQLPARSER } | ||
| , { "XMLSERIALIZE" , RESTRICTED_JSQLPARSER } | ||
|
|
||
| // add keywords from the composite token definitions: | ||
| // tk=<K_DATE_LITERAL> | tk=<K_DATETIMELITERAL> | tk=<K_STRING_FUNCTION_NAME> | ||
| // we will use the composite tokens instead, which are always hit first before the simple keywords | ||
| // @todo: figure out a way to remove these composite tokens, as they do more harm than good | ||
| , { "SEL", RESTRICTED_JSQLPARSER } | ||
| , { "SELECT", RESTRICTED_JSQLPARSER } | ||
|
|
||
| , { "DATE", RESTRICTED_JSQLPARSER } | ||
| , { "TIME" , RESTRICTED_JSQLPARSER } | ||
| , { "TIMESTAMP", RESTRICTED_JSQLPARSER } | ||
|
|
||
| , { "YEAR", RESTRICTED_JSQLPARSER } | ||
| , { "MONTH", RESTRICTED_JSQLPARSER } | ||
| , { "DAY", RESTRICTED_JSQLPARSER } | ||
| , { "HOUR", RESTRICTED_JSQLPARSER } | ||
| , { "MINUTE" , RESTRICTED_JSQLPARSER } | ||
| , { "SECOND", RESTRICTED_JSQLPARSER } | ||
|
|
||
| , { "SUBSTR", RESTRICTED_JSQLPARSER } | ||
| , { "SUBSTRING", RESTRICTED_JSQLPARSER } | ||
| , { "TRIM", RESTRICTED_JSQLPARSER } | ||
| , { "POSITION", RESTRICTED_JSQLPARSER } | ||
| , { "OVERLAY", RESTRICTED_JSQLPARSER } | ||
|
|
||
| , { "NEXTVAL", RESTRICTED_JSQLPARSER } | ||
|
|
||
| //@todo: figure out what those are about | ||
| , { "RR", RESTRICTED_JSQLPARSER } | ||
| , { "RS", RESTRICTED_JSQLPARSER } | ||
| , { "UR", RESTRICTED_JSQLPARSER } | ||
| , { "CS", RESTRICTED_JSQLPARSER } | ||
|
|
||
| //@todo: Object Names should not start with Hex-Prefix, we shall not find that Token | ||
| , { "0x", RESTRICTED_JSQLPARSER } | ||
| }; | ||
|
|
||
| ArrayList<String> keywords = new ArrayList<>(); | ||
| for (Object[] data : ALL_RESERVED_KEYWORDS) { | ||
| int value = (int) data[1]; | ||
|
|
||
| // test if bit is not set | ||
| if ( (value & restrictriction) == restrictriction | ||
| || (restrictriction & value) == value ) | ||
| keywords.add( (String) data[0] ); | ||
| } | ||
|
|
||
| public static List<String> getReservedKeywords(int restriction) { | ||
| return CCJSqlParser.getReservedKeywords(restriction); | ||
| return keywords; | ||
| } | ||
|
|
||
| public static void main(String[] args) throws Exception { | ||
|
|
@@ -58,12 +195,34 @@ public static void main(String[] args) throws Exception { | |
| } | ||
| } | ||
|
|
||
| public static void buildGrammarForRelObjectNameWithoutValue(File file) throws Exception { | ||
| Pattern pattern = Pattern.compile("String\\W*RelObjectNameWithoutValue\\W*\\(\\W*\\)\\W*:\\s*\\{(?:[^}{]+|\\{(?:[^}{]+|\\{[^}{]*})*})*}\\s*\\{(?:[^}{]+|\\{(?:[^}{]+|\\{[^}{]*})*})*}", Pattern.MULTILINE); | ||
| public static TreeSet<String> getAllKeywords(File file) throws IOException { | ||
| Pattern tokenBlockPattern = Pattern.compile("TOKEN\\s*:\\s*(?:/\\*.*\\*/*)\\n\\{(?:[^\\}\\{]+|\\{(?:[^\\}\\{]+|\\{[^\\}\\{]*\\})*\\})*\\}", Pattern.MULTILINE); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool regex. Maybe insert a comment to indicate/example what matches? I cannot read it from the regex directly. |
||
| Pattern tokenStringValuePattern = Pattern.compile("\\\"(\\w{2,})\\\"", Pattern.MULTILINE); | ||
|
|
||
| TreeSet<String> allKeywords = new TreeSet<>(); | ||
| allKeywords.addAll(CCJSqlParser.getDefinedKeywords()); | ||
| for (String reserved: CCJSqlParser.getReservedKeywords(RESTRICTED_JSQLPARSER)) { | ||
|
|
||
| Path path = file.toPath(); | ||
| Charset charset = Charset.defaultCharset(); | ||
| String content = new String(Files.readAllBytes(path), charset); | ||
|
|
||
| Matcher tokenBlockmatcher = tokenBlockPattern.matcher(content); | ||
| while (tokenBlockmatcher.find()) { | ||
| String tokenBlock = tokenBlockmatcher.group(0); | ||
| Matcher tokenStringValueMatcher= tokenStringValuePattern.matcher(tokenBlock); | ||
| while (tokenStringValueMatcher.find()) { | ||
| String tokenValue=tokenStringValueMatcher.group(1); | ||
| allKeywords.add(tokenValue); | ||
| } | ||
| } | ||
| return allKeywords; | ||
| } | ||
|
|
||
| public static void buildGrammarForRelObjectNameWithoutValue(File file) throws Exception { | ||
| Pattern methodBlockPattern = Pattern.compile("String\\W*RelObjectNameWithoutValue\\W*\\(\\W*\\)\\W*:\\s*\\{(?:[^}{]+|\\{(?:[^}{]+|\\{[^}{]*})*})*}\\s*\\{(?:[^}{]+|\\{(?:[^}{]+|\\{[^}{]*})*})*}", Pattern.MULTILINE); | ||
|
|
||
| TreeSet<String> allKeywords = getAllKeywords(file); | ||
|
|
||
| for (String reserved: getReservedKeywords(RESTRICTED_JSQLPARSER)) { | ||
| allKeywords.remove(reserved); | ||
| } | ||
|
|
||
|
|
@@ -82,17 +241,17 @@ public static void buildGrammarForRelObjectNameWithoutValue(File file) throws Ex | |
| + " { return tk.image; }\n" | ||
| + "}"); | ||
|
|
||
| replaceInFile(file, pattern, builder.toString()); | ||
| replaceInFile(file, methodBlockPattern, builder.toString()); | ||
| } | ||
|
|
||
| public static void buildGrammarForRelObjectName(File file) throws Exception { | ||
| // Pattern pattern = Pattern.compile("String\\W*RelObjectName\\W*\\(\\W*\\)\\W*:\\s*\\{(?:[^}{]+|\\{(?:[^}{]+|\\{[^}{]*})*})*}\\s*\\{(?:[^}{]+|\\{(?:[^}{]+|\\{[^}{]*})*})*}", Pattern.MULTILINE); | ||
| TreeSet<String> allKeywords = new TreeSet<>(); | ||
| for (String reserved: CCJSqlParser.getReservedKeywords(RESTRICTED_ALIAS)) { | ||
| for (String reserved: getReservedKeywords(RESTRICTED_ALIAS)) { | ||
| allKeywords.add(reserved); | ||
| } | ||
|
|
||
| for (String reserved: CCJSqlParser.getReservedKeywords(RESTRICTED_JSQLPARSER & ~RESTRICTED_ALIAS)) { | ||
| for (String reserved: getReservedKeywords(RESTRICTED_JSQLPARSER & ~RESTRICTED_ALIAS)) { | ||
| allKeywords.remove(reserved); | ||
| } | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't thoses lists directly derived from the grammar? At least RESTRICTED_ALIAS?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is the other way around: This List will define, how we rewrite
RelObjectName.... This List will be defined manually and everything else follows it.