Skip to content
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
7 changes: 4 additions & 3 deletions src/Tokenizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,7 @@ final class Tokenizer
'>',
'+',
'-',
'~*', // https://www.postgresql.org/docs/current/functions-matching.html#FUNCTIONS-POSIX-REGEXP
'*',
'/',
'!',
Expand Down Expand Up @@ -820,10 +821,10 @@ private function makeRegexFromList(array $values, bool $sorted = false): string
$prefix = (string) $prefix;
}

$regex .= preg_quote($prefix, '/');
$regex .= preg_quote($prefix);
Copy link
Contributor

@mvorisek mvorisek Feb 8, 2026

Choose a reason for hiding this comment

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

PR LGTM and I like this change, it seem / was even wrong here as later ~ delimtier was used.


$regex .= count($items) === 1
? preg_quote(substr(reset($items), strlen($prefix)), '/')
? preg_quote(substr(reset($items), strlen($prefix)))
: $this->makeRegexFromList(array_map(static fn ($v) => substr($v, strlen($prefix)), $items), true);
}

Expand Down Expand Up @@ -887,7 +888,7 @@ private function makeTokenizeRegex(array $regexes): string
$parts[] = '(?<t_' . $type . '>' . $regex . ')';
}

return '~\G(?:' . implode('|', $parts) . ')~';
return '(\G(?:' . implode('|', $parts) . '))';
}

/**
Expand Down
3 changes: 3 additions & 0 deletions tests/clihighlight.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1211,3 +1211,6 @@ MY_NON_TOP_LEVEL_KEYWORD_FX_3();
---
SELECT
vector1 <#> vector2
---
SELECT
text ~* '\w+'
2 changes: 2 additions & 0 deletions tests/compress.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,5 @@ CREATE TABLE t (c VARCHAR(20)) DEFAULT CHARACTER SET utf8mb4 ENGINE = InnoDB
SELECT '{}'::json #> '{}'
---
SELECT vector1 <#> vector2
---
SELECT text ~* '\w+'
3 changes: 3 additions & 0 deletions tests/format-highlight.html
Original file line number Diff line number Diff line change
Expand Up @@ -1211,3 +1211,6 @@
---
<pre style="color: black; background-color: white;"><span style="font-weight:bold;">SELECT</span>
<span style="color: #333;">vector1</span> <span >&lt;</span><span >#</span><span >&gt;</span> <span style="color: #333;">vector2</span></pre>
---
<pre style="color: black; background-color: white;"><span style="font-weight:bold;">SELECT</span>
<span style="color: #333;">text</span> <span >~*</span> <span style="color: blue;">'\w+'</span></pre>
3 changes: 3 additions & 0 deletions tests/format.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1209,3 +1209,6 @@ SELECT
---
SELECT
vector1 <#> vector2
---
SELECT
text ~* '\w+'
2 changes: 2 additions & 0 deletions tests/highlight.html
Original file line number Diff line number Diff line change
Expand Up @@ -429,3 +429,5 @@
<pre style="color: black; background-color: white;"><span style="font-weight:bold;">SELECT</span> <span style="color: blue;">'{}'</span><span >::</span><span style="color: #333;">json</span> <span >#</span><span >&gt;</span> <span style="color: blue;">'{}'</span></pre>
---
<pre style="color: black; background-color: white;"><span style="font-weight:bold;">SELECT</span> <span style="color: #333;">vector1</span> <span >&lt;</span><span >#</span><span >&gt;</span> <span style="color: #333;">vector2</span></pre>
---
<pre style="color: black; background-color: white;"><span style="font-weight:bold;">SELECT</span> <span style="color: #333;">text</span> <span >~*</span> <span style="color: blue;">'\w+'</span></pre>
2 changes: 2 additions & 0 deletions tests/sql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -429,3 +429,5 @@ CREATE TABLE t (c VARCHAR(20)) DEFAULT CHARACTER SET utf8mb4 ENGINE = InnoDB
SELECT '{}'::json #> '{}'
---
SELECT vector1 <#> vector2
---
SELECT text ~* '\w+'