-
Notifications
You must be signed in to change notification settings - Fork 25
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
Make sure keywords are single upper words #107
Conversation
8bd332e
to
78c8eee
Compare
790bb74
to
c03edef
Compare
Changes are described, but they are not explained by commit messages (maybe by tests, but that's not sufficient I'm afraid). For instance, what makes you think keywords appearing in |
"reserved" words are special - they needs to be quoted even if used on places where only identifier is possible (ex In #106, "reserved" words will be asserted by complete lists. |
I'm asking because sql-formatter/src/Tokenizer.php Lines 887 to 932 in 6eb85e0
Is there a part of the code where being part of |
2c9a539
to
3eff766
Compare
I have now removed the test I added testing if all new line/top level keywords are also reserved, as in theory, this does not have to be true. Currently the lists are in quite bad shape, for ex. Reserved keywords should be maintained however on its own and they will be asserted in #106, the reason is "reserved" keyworda are special as they must be always quoted - and they will be needed to address #95. "reserved top level" and "reserved new line" are just bad historical names. |
3eff766
to
5473108
Compare
@greg0ire I have now amended the commits with explanation messages. |
tests/TokenizerTest.php
Outdated
public function testKeywordsReservedAreUpperCasedAndWithoutWhitespace(): void | ||
{ | ||
$tokenizerReserved = $this->getTokenizerList('reserved'); | ||
|
||
$kwsDiff = array_filter($tokenizerReserved, static function ($v) { | ||
return $v !== strtoupper($v) || preg_match('~\s~', $v) !== 0; | ||
}); | ||
|
||
self::assertSame([], $kwsDiff); | ||
} |
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.
What is this method supposed to test? This is checking the format of the reserved 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.
All reserved keywords must be a single word in upper case (so we can rely on it when comparing againts other UC string).
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.
Overall I do not see the need for this change (except of we want to keep the array of keywords alphabetically sorted)
tests/TokenizerTest.php
Outdated
return $res; | ||
} | ||
|
||
public function testKeywordsReservedAreUpperCasedAndWithoutWhitespace(): void |
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 that this test is testing something "too" internal. they way how properties are used in the class should not be IMO really tested. changing the implementation at this level of depth should not really impact tests IMO
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.
explained in #107 (comment)
Would it be possible to isolate the "real" changes you did from the "esthetical" changes? |
df99b3a
to
a47492d
Compare
I don't know if @goetas @derrabus and @SenseException are satisfied with your answers. Since you can't get approvals, I am closing this PR and I suggest you do one PR per commit, so that there is more hope to close open discussions, and so that we do not have to look at too many other PRs and issue to understand what you are trying to do. In these new PRs, try to be less pushy, and to explains things better, with clearer sentences. Take your time. I'll give you an example:
Here it is unclear if you are referring to things before or after your changes, and it is unclear what you are referring to with "they". |
@greg0ire please reopen this PR and I will extract the 2nd commit into another PR. Thank you. |
a47492d
to
cbe343f
Compare
cbe343f
to
229f681
Compare
229f681
to
58998dd
Compare
PR is done and I did my best to explain the change in the PR description. |
@@ -182,13 +182,10 @@ final class Tokenizer | |||
'MYISAM', | |||
'NAMES', | |||
'NATURAL', | |||
'NO OTHERS', |
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 I might not be understanding what you are doing here… shouldn't you be adding back NO
as well as OTHERS
to this list?
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.
NO
or OTHERS
must not be added into "reserved" keywords as both are not "reserved" by SQL/MySQL spec.
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.
Make sure keywords are single upper words
Your commit message does not mention that at any point.
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.
The PR description does. If the commit message should be amended, please tell me what text to put there.
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.
Well maybe it should be a separate commit, since it's an entirely separate concern.
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.
We need to end up exactly with the changes as this PR does - please tell me exactly what to do, am I right you want separate commit for 'NO OTHERS'
keyword removal? Anything else?
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.
2 commits:
- one that removes
NO OTHERS
and explains why, and also takes a guess at whyNO OTHERS
was present in this list in the first place - another that is about making sure we deal with single words, and also explains why that is necessary.
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.
Done and thank you.
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.
Why do you think NO OTHERS
was present in the list in the first place? You cite MySQL grammar, but this library is not solely about MySQL, is it?
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.
Why do you think
NO OTHERS
was present in the list in the first place?
See https://github.com/search?q=repo%3Amysql%2Fmysql-server+%22NO+OTHERS%22&type=code MySQL tests for usecases and https://github.com/antlr/grammars-v4/blob/4264f19a7d/sql/mysql/Oracle/MySQLParser.g4#L1208 for full grammar.
It is however not a "reserved" keyword because of two reasons. Keyword must be a single word. And must be listed as reserved in MySQL or MariaDB docs.
You cite MySQL grammar, but this library is not solely about MySQL, is it?
The jdorm library was for MySQL dialect only. In #106 many keywords will be added as the current list is far from complete.
"NO" or "OTHERS" are not reserved keywords per MySQL grammar
The "reserved" keywords are special as they need to be always quoted and per MySQL/SQLite spec they are always single word and case insensitive.
58998dd
to
ff667cc
Compare
Thanks @mvorisek ! |
Into 1.4.x as this is needed for #106 bugfix.
In this PR, we make sure all "reserved" keywords are single word - this is how SQL specifications (MySQL/MariaDB/SQLite at least) define them.
The "reserved" keywords are special as they need to be always quoted*. The "reserved" keyword list will be updated in #106 to contain all and only the "reserved" keywords.
* this is not only helpful for maintaining the lists properly, but also needed for #73 as only "reserved" keywords can be upper cased safely (issue #95).