-
-
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
Enhanced Keywords #1382
Conversation
Add Keywords and document, which keywords are allowed for what purpose
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.
Again, are all those keyword additions to relobjectnames needed? You talked about all those edge case improvements. Are most of those additions not exactly that?
@@ -1733,7 +2007,7 @@ Table TableWithAlias(): | |||
Alias alias = null; | |||
} | |||
{ | |||
table=Table() [alias=Alias() { table.setAlias(alias); }] | |||
table=Table() [ LOOKAHEAD(2) alias=Alias() { table.setAlias(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 should be the aim to do less not more LOOKAHEADs. All this for some keywords?
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.
Yes, all this for some keywords (although the Alias()
Production is affected mostly)
But why exactly would you deny Tokens, which are not defined in the holy SQL:2016 standard as keywords when there is no compelling technical reason ?
Complaints about keywords are felt the second most concern of the users, right after quoting/escaping text and objects.
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.
To me it's not directly obvious why this LOOKAHEAD
is needed. Is that explained somewhere?
Derive All Keywords from Grammar directly Generate production for Object Names (semi-) automatically Add parametrized Keyword Tests
@wumpz: Please check out the great work on PR #1254. It adds a new token Of course the author @OlivierCavadenti has no chance to know, that he would need to add This PR would solve this challenge reliably, preventing new tokens from breaking valid statements and ease the entry for new contributors. |
Parallel Test execution Gradle Caching Explicitly request for latest JavaCC 7.0.10
Parallel Test execution Gradle Caching Explicitly request for latest JavaCC 7.0.10
# Conflicts: # src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt
Update keywords
@@ -227,6 +242,13 @@ task renderRR() { | |||
} | |||
} | |||
} | |||
|
|||
task updateKeywords(type: JavaExec) { |
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.
Since I do not use gradle, what does this do?
Maven is the main build engine. You changed some gradle build options. Does the maven build still run?
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 generates and prints the Source Code Text of the method RelObjectName()
which you would manually insert/replace in the JSQL Grammar file.
This step is optional and does not affect the Maven build. It is executed manually and on demand only.
Although the long term goal was to have a mechanism inside the build tool (Gradle and/or Maven), which during the build:
- analyses the KeyWords automatically
- modifies the Grammar file (methods
RelObjectName()
and friends) - builds the Parser with the modified Grammar
- runs the Keyword Tests
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.
I think this might also be implemented in a mojo in Maven, but that might be not worth the effort.
The naming of this RelObjectName ... methods is sure an issue that should be adressed in futher improvements. So sorry for that: its grown ... ;) |
I am not a fan of injecting those keywords, since not every keyword could be introduced this way and needs other parts of the grammar to be modified. However, building this keyword testing using JUnit 5 is cool. |
You would do me a great favor by documenting the purpose of those 5 methods verbosely. I tried my best to figure it out by trial'n error but I am still not exactly sure why we ended up with 5 methods. (And no worries about grown code.) |
Honestly, I am not a big fan of that PR either -- but after spending many days on that matter trying various things it was the best approach I found and in my opinion it is still much better than the current state:
The work flow is to: a) define the Tokens and Productions in the Grammar first and then b) document any new RESERVED Keywords only in the List (emphasis on RESERVED). The PR has one big advantaged: By defining RESERVED keywords only, it will determine automatically any allowed Keywords and modify the Grammar semi-automatically. |
Allow me to ask please:
And can we have a Skype chat about this :-) |
No, it is exactly the opposite: Only when those tests fail, we would have to amend Where I still fail to understand you plan is this point:
So how would you run your Tests without whitelisting in the grammar first? |
Simply this test will fail until you whitelist or restrict the new tokens. That's what forces developers to do this decision (for us). You are right, that the restricted list should change rarely. The test should then give an advice, how and were this change should be done.
I was not aware of this automatic whitelist keyword building. So this is +1. |
So are you going to resolve the conflicts? This improvement of parsing could be done afterwards. |
# Conflicts: # src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt
# Conflicts: # src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt
@wumpz When could this pr be merged? The parse error is really annoying. |
I can supply you with a bleeding edge JAR file including those PRs, in case its urgent. |
So after merging, I am not able to build anymore since So how should I proceed if I am not willing to use gradle? Isn't that the same problem you had with my proposal? Maven is the main build pipeline. |
Good Morning. Thank you for finally accepting the PR. What caused the problem:
Solution: This should have been done by the author of the It is exactly as you have requested for in your explanations. Although I will run through this procedure today and send a very small PR. |
If you insist in not using I would also provide an equivalent Maven task soon, since we are moving forward now. Workflow should be like that:
Using gradle updateKeywords task is optional, you can also add the new Tokens manually has it has always been done before. After accepting the Keywords PR, any further PR will automatically fail acceptance tests, unless keywords are in order. |
No developer that is using maven knows what to do here? So this workflow has somehow to be included in a developer help. At the moment this is only your tool, since nobody knows and not everybody uses gradle. |
Since we are not willing to run the gradle task and your tests use |
Additional since some JavaCC methods are in place now there is a direct dependency for JavaCC. |
Yes, because you insisted to parse the Grammer using JavaCC instead of using Regular Expressions. I suggest to use Regular Expressions instead for that reason.
Because this is exactly what you would have done before the semi-automation: edit the Production That said, I have added a Maven Task for running the same mvn compile exec:java
Yes, of course. It has been verbosely documented within the new website, which I have committed 1 month ago or so: https://manticore-projects.com/JSQLParser/contribution.html#manage-reserved-keywords I have updated the Keywords2 PR #1653 accordingly with your requested Maven task. |
The Maven task could be implemented as a mojo (maven-plugin) I think, are you interested in that? Then you can run this plugin from the pom.xml during, for example, the generate-sources phase. |
I have some experience writing these maven plugins, so if I infd some time this week, maybe I could draft up some integration so it 'just works' when you run for example |
But probably this will work as well:
|
Thanks! I have add submitted another PR like that on Saturday already. |
Ah excellent! |
I can't find that PR? I think there might also be a chicken-and-egg problem, as the java code that does the work, also needs to be compiled first? (you can solve that using multi-module maven build, but that requires a bit more refactoring) |
this one: #1653 Its pretty straight forward actually since we can execute Java Code directly without compiling the whole package. Also, this step is executed on demand: only when new tokens introduced and/or the Keyword Tests fail. |
That's why e.g. my proposal is only running in scope test. Then this dependency is not needed. I was talking about the IMHO right way to parse the grammar and not the context in which this parsing should happen. I thought this should be obvious. For the same reason, the JSqlParser jar should not include this generation class. It is part of the build process (I know you do not accept that, but I think it's evident.) So a quick solution would be to put all of it in the test folder and make this JavaCC dependency of scope test. However, to get a clean build again use for now Regular Expressions. Saying that, since this is a build step or could be one, it should be separated from JSqlParser source code and put in some kind of build helper module and then could be definitely used if JSqlparser is built. Now If you clone this project you will fail, since the generator class is not yet built.
I have reviewed it already and found in this issue the needed information on how to run it, so I will merge it. |
Rewrite the Reserved Keywords Logic:
RelObjectNameWithoutValue()
based on 3)Advantage:
a) we have now a clear documentation which Keywords are reserved for what reason, with proper tests
b) allowed keywords are generated (semi-)automatically, especially when more Tokens are added to the Grammar. New Tokens won't break SQL Statements, which have been parsed fine before.
To-Dos:
c) Composite Tokens do not work well and still need to be added manually to ALL_KEYWORDS (we would need to refactor the GRAMMAR in order to avoid such composite tokens)
d) @wumpz: Clarify the meaning/purpose of the various
RelObjectNamexxxx()
Productions, so we can auto generate them too.e) Use the Gradle task to fully inject the
RelObjectNamexxxx()
Productions (instead of manually updating the code)Resolves one more Special Oracle Test.
Fixes #1148
Fixes #1450
Fixes #1443
Fixes #1462
Fixes #1508
Fixes #1538
Fixes #1650