Skip to content
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

Merged
merged 2 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/Tokenizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ final class Tokenizer
'CASE',
'CHANGE',
'CHANGED',
'CHARACTER SET',
'CHARACTER',
'CHARSET',
'CHECK',
'CHECKSUM',
Expand All @@ -68,7 +68,7 @@ final class Tokenizer
'CONVERT',
'CREATE',
'CROSS',
'CURRENT ROW',
'CURRENT',
'CURRENT_TIMESTAMP',
'DATABASE',
'DATABASES',
Expand Down Expand Up @@ -182,13 +182,10 @@ final class Tokenizer
'MYISAM',
'NAMES',
'NATURAL',
'NO OTHERS',
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

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 why NO 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done and thank you.

Copy link
Member

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?

Copy link
Contributor Author

@mvorisek mvorisek May 30, 2024

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.

'NOT',
'NULL',
'OFFSET',
'ON',
'ON DELETE',
'ON UPDATE',
'OPEN',
'OPTIMIZE',
'OPTION',
Expand Down Expand Up @@ -242,6 +239,7 @@ final class Tokenizer
'SEPARATOR',
'SERIALIZABLE',
'SESSION',
'SET',
'SHARE',
'SHOW',
'SHUTDOWN',
Expand Down
14 changes: 14 additions & 0 deletions tests/TokenizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
use PHPUnit\Framework\TestCase;
use ReflectionClass;

use function array_filter;
use function preg_match;
use function sort;
use function strtoupper;

final class TokenizerTest extends TestCase
{
Expand Down Expand Up @@ -44,6 +47,17 @@ public function testInternalKeywordListsAreSortedForEasierMaintenance(): void
}
}

public function testKeywordsReservedAreSingleUpperWord(): void
{
$tokenizerReserved = $this->getTokenizerList('reserved');

$kwsDiff = array_filter($tokenizerReserved, static function ($v) {
return $v !== strtoupper($v) || preg_match('~^\w+$~', $v) !== 1;
});

self::assertSame([], $kwsDiff);
}

#[DoesNotPerformAssertions]
public function testThereAreNoRegressions(): void
{
Expand Down
14 changes: 7 additions & 7 deletions tests/clihighlight.txt
Original file line number Diff line number Diff line change
Expand Up @@ -915,31 +915,31 @@
c
GROUPS
BETWEEN UNBOUNDED PRECEDING
AND CURRENT ROW
EXCLUDE NO OTHERS
AND CURRENT ROW
EXCLUDE NO OTHERS
) AS no_others,
GROUP_CONCAT(b, '.') OVER (
ORDER BY
c
GROUPS
BETWEEN UNBOUNDED PRECEDING
AND CURRENT ROW
EXCLUDE CURRENT ROW
AND CURRENT ROW
EXCLUDE CURRENT ROW
) AS current_row,
GROUP_CONCAT(b, '.') OVER (
ORDER BY
c
GROUPS
BETWEEN UNBOUNDED PRECEDING
AND CURRENT ROW
AND CURRENT ROW
EXCLUDE GROUP
) AS grp,
GROUP_CONCAT(b, '.') OVER (
ORDER BY
c
GROUPS
BETWEEN UNBOUNDED PRECEDING
AND CURRENT ROW
AND CURRENT ROW
EXCLUDE TIES
) AS tie,
GROUP_CONCAT(b, '.') FILTER (
Expand Down Expand Up @@ -990,7 +990,7 @@
ORDER BY
RevenueYear
ROWS
BETWEEN CURRENT ROW
BETWEEN CURRENT ROW
AND UNBOUNDED FOLLOWING
) AS MinRevenueBeyond
FROM
Expand Down
14 changes: 7 additions & 7 deletions tests/format-highlight.html
Original file line number Diff line number Diff line change
Expand Up @@ -915,31 +915,31 @@
<span style="color: #333;">c</span>
<span style="font-weight:bold;">GROUPS</span>
<span style="font-weight:bold;">BETWEEN</span> <span style="font-weight:bold;">UNBOUNDED</span> <span style="font-weight:bold;">PRECEDING</span>
<span style="font-weight:bold;">AND</span> <span style="font-weight:bold;">CURRENT ROW</span>
<span style="font-weight:bold;">EXCLUDE</span> <span style="font-weight:bold;">NO OTHERS</span>
<span style="font-weight:bold;">AND</span> <span style="font-weight:bold;">CURRENT</span> <span style="font-weight:bold;">ROW</span>
<span style="font-weight:bold;">EXCLUDE</span> <span style="color: #333;">NO</span> <span style="color: #333;">OTHERS</span>
) <span style="font-weight:bold;">AS</span> <span style="color: #333;">no_others</span><span >,</span>
<span style="font-weight:bold;">GROUP_CONCAT</span>(<span style="color: #333;">b</span><span >,</span> <span style="color: blue;">'.'</span>) <span style="font-weight:bold;">OVER</span> (
<span style="font-weight:bold;">ORDER BY</span>
<span style="color: #333;">c</span>
<span style="font-weight:bold;">GROUPS</span>
<span style="font-weight:bold;">BETWEEN</span> <span style="font-weight:bold;">UNBOUNDED</span> <span style="font-weight:bold;">PRECEDING</span>
<span style="font-weight:bold;">AND</span> <span style="font-weight:bold;">CURRENT ROW</span>
<span style="font-weight:bold;">EXCLUDE</span> <span style="font-weight:bold;">CURRENT ROW</span>
<span style="font-weight:bold;">AND</span> <span style="font-weight:bold;">CURRENT</span> <span style="font-weight:bold;">ROW</span>
<span style="font-weight:bold;">EXCLUDE</span> <span style="font-weight:bold;">CURRENT</span> <span style="font-weight:bold;">ROW</span>
) <span style="font-weight:bold;">AS</span> <span style="color: #333;">current_row</span><span >,</span>
<span style="font-weight:bold;">GROUP_CONCAT</span>(<span style="color: #333;">b</span><span >,</span> <span style="color: blue;">'.'</span>) <span style="font-weight:bold;">OVER</span> (
<span style="font-weight:bold;">ORDER BY</span>
<span style="color: #333;">c</span>
<span style="font-weight:bold;">GROUPS</span>
<span style="font-weight:bold;">BETWEEN</span> <span style="font-weight:bold;">UNBOUNDED</span> <span style="font-weight:bold;">PRECEDING</span>
<span style="font-weight:bold;">AND</span> <span style="font-weight:bold;">CURRENT ROW</span>
<span style="font-weight:bold;">AND</span> <span style="font-weight:bold;">CURRENT</span> <span style="font-weight:bold;">ROW</span>
<span style="font-weight:bold;">EXCLUDE</span> <span style="font-weight:bold;">GROUP</span>
) <span style="font-weight:bold;">AS</span> <span style="color: #333;">grp</span><span >,</span>
<span style="font-weight:bold;">GROUP_CONCAT</span>(<span style="color: #333;">b</span><span >,</span> <span style="color: blue;">'.'</span>) <span style="font-weight:bold;">OVER</span> (
<span style="font-weight:bold;">ORDER BY</span>
<span style="color: #333;">c</span>
<span style="font-weight:bold;">GROUPS</span>
<span style="font-weight:bold;">BETWEEN</span> <span style="font-weight:bold;">UNBOUNDED</span> <span style="font-weight:bold;">PRECEDING</span>
<span style="font-weight:bold;">AND</span> <span style="font-weight:bold;">CURRENT ROW</span>
<span style="font-weight:bold;">AND</span> <span style="font-weight:bold;">CURRENT</span> <span style="font-weight:bold;">ROW</span>
<span style="font-weight:bold;">EXCLUDE</span> <span style="font-weight:bold;">TIES</span>
) <span style="font-weight:bold;">AS</span> <span style="color: #333;">tie</span><span >,</span>
<span style="font-weight:bold;">GROUP_CONCAT</span>(<span style="color: #333;">b</span><span >,</span> <span style="color: blue;">'.'</span>) <span style="font-weight:bold;">FILTER</span> (
Expand Down Expand Up @@ -990,7 +990,7 @@
<span style="font-weight:bold;">ORDER BY</span>
<span style="color: #333;">RevenueYear</span>
<span style="font-weight:bold;">ROWS</span>
<span style="font-weight:bold;">BETWEEN</span> <span style="font-weight:bold;">CURRENT ROW</span>
<span style="font-weight:bold;">BETWEEN</span> <span style="font-weight:bold;">CURRENT</span> <span style="font-weight:bold;">ROW</span>
<span style="font-weight:bold;">AND</span> <span style="font-weight:bold;">UNBOUNDED</span> <span style="font-weight:bold;">FOLLOWING</span>
) <span style="font-weight:bold;">AS</span> <span style="color: #333;">MinRevenueBeyond</span>
<span style="font-weight:bold;">FROM</span>
Expand Down
Loading