Skip to content

Commit d6d00ab

Browse files
authored
Do not assume "SET" as top level when preceded with "CHARACTER" (#150)
* Do not assume "SET" as top level when preceded with "CHARACTER" * test PHP 8.4
1 parent 1e04414 commit d6d00ab

8 files changed

+20
-2
lines changed

.github/workflows/continuous-integration.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ jobs:
1313
name: "PHPUnit"
1414
uses: "doctrine/.github/.github/workflows/[email protected]"
1515
with:
16-
php-versions: '["8.1", "8.2", "8.3"]'
16+
php-versions: '["8.1", "8.2", "8.3", "8.4"]'
1717
secrets:
1818
CODECOV_TOKEN: "${{ secrets.CODECOV_TOKEN }}"

src/Tokenizer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,7 @@ private function makeTokenizeRegexes(): array
868868
Token::TOKEN_TYPE_BOUNDARY => $regexBoundaries,
869869
// A reserved word cannot be preceded by a '.'
870870
// this makes it so in "mytable.from", "from" is not considered a reserved word
871-
Token::TOKEN_TYPE_RESERVED_TOPLEVEL => '(?<!\.)' . $regexReservedToplevel . '(?=$|\s|' . $regexBoundaries . ')',
871+
Token::TOKEN_TYPE_RESERVED_TOPLEVEL => '(?<!\.|\sCHARACTER\s(?=SET\s))' . $regexReservedToplevel . '(?=$|\s|' . $regexBoundaries . ')',
872872
Token::TOKEN_TYPE_RESERVED_NEWLINE => '(?<!\.)' . $regexReservedNewline . '(?=$|\s|' . $regexBoundaries . ')',
873873
Token::TOKEN_TYPE_RESERVED => '(?<!\.)' . $regexReserved . '(?=$|\s|' . $regexBoundaries . ')'
874874
// A function must be succeeded by '('

tests/clihighlight.txt

+4
Original file line numberDiff line numberDiff line change
@@ -1201,3 +1201,7 @@ MY_NON_TOP_LEVEL_KEYWORD_FX_3();
12011201
t
12021202
WHERE
12031203
t.start = t.end
1204+
---
1205+
CREATE TABLE t (
1206+
c VARCHAR(20)
1207+
) DEFAULT CHARACTER SET utf8mb4 ENGINE = InnoDB

tests/compress.txt

+2
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,5 @@ BEGIN FOR i IN 1..5 LOOP DBMS_OUTPUT.PUT_LINE(i); END LOOP; END;
109109
SELECT a FROM test STRAIGHT_JOIN test2 ON test.id = test2.id
110110
---
111111
SELECT t.id, t.start, t.end, t.end AS e2, t.limit, t.begin, t.case, t.when, t.then, t.else FROM t WHERE t.start = t.end
112+
---
113+
CREATE TABLE t (c VARCHAR(20)) DEFAULT CHARACTER SET utf8mb4 ENGINE = InnoDB

tests/format-highlight.html

+4
Original file line numberDiff line numberDiff line change
@@ -1201,3 +1201,7 @@
12011201
<span style="color: #333;">t</span>
12021202
<span style="font-weight:bold;">WHERE</span>
12031203
<span style="color: #333;">t</span><span >.</span><span style="color: #333;">start</span> <span >=</span> <span style="color: #333;">t</span><span >.</span><span style="color: #333;">end</span></pre>
1204+
---
1205+
<pre style="color: black; background-color: white;"><span style="font-weight:bold;">CREATE</span> <span style="font-weight:bold;">TABLE</span> <span style="color: #333;">t</span> (
1206+
<span style="color: #333;">c</span> <span style="font-weight:bold;">VARCHAR</span>(<span style="color: green;">20</span>)
1207+
) <span style="font-weight:bold;">DEFAULT</span> <span style="font-weight:bold;">CHARACTER</span> <span style="font-weight:bold;">SET</span> <span style="color: #333;">utf8mb4</span> <span style="font-weight:bold;">ENGINE</span> <span >=</span> <span style="color: #333;">InnoDB</span></pre>

tests/format.txt

+4
Original file line numberDiff line numberDiff line change
@@ -1199,3 +1199,7 @@ FROM
11991199
t
12001200
WHERE
12011201
t.start = t.end
1202+
---
1203+
CREATE TABLE t (
1204+
c VARCHAR(20)
1205+
) DEFAULT CHARACTER SET utf8mb4 ENGINE = InnoDB

tests/highlight.html

+2
Original file line numberDiff line numberDiff line change
@@ -423,3 +423,5 @@
423423
<span style="color: #333;">t</span><span >.</span><span style="color: #333;">else</span>
424424
<span style="font-weight:bold;">FROM</span> <span style="color: #333;">t</span>
425425
<span style="font-weight:bold;">WHERE</span> <span style="color: #333;">t</span><span >.</span><span style="color: #333;">start</span> <span >=</span> <span style="color: #333;">t</span><span >.</span><span style="color: #333;">end</span></pre>
426+
---
427+
<pre style="color: black; background-color: white;"><span style="font-weight:bold;">CREATE</span> <span style="font-weight:bold;">TABLE</span> <span style="color: #333;">t</span> (<span style="color: #333;">c</span> <span style="font-weight:bold;">VARCHAR</span>(<span style="color: green;">20</span>)) <span style="font-weight:bold;">DEFAULT</span> <span style="font-weight:bold;">CHARACTER</span> <span style="font-weight:bold;">SET</span> <span style="color: #333;">utf8mb4</span> <span style="font-weight:bold;">ENGINE</span> <span >=</span> <span style="color: #333;">InnoDB</span></pre>

tests/sql.sql

+2
Original file line numberDiff line numberDiff line change
@@ -423,3 +423,5 @@ SELECT
423423
t.else
424424
FROM t
425425
WHERE t.start = t.end
426+
---
427+
CREATE TABLE t (c VARCHAR(20)) DEFAULT CHARACTER SET utf8mb4 ENGINE = InnoDB

0 commit comments

Comments
 (0)