Skip to content

Commit 94fedae

Browse files
authored
Merge pull request #27 from greg0ire/extract-tokenization
Extract tokenization
2 parents fbe071c + 705a800 commit 94fedae

File tree

8 files changed

+1210
-1153
lines changed

8 files changed

+1210
-1153
lines changed

examples/cli.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,6 @@
2626
require_once __DIR__ . '/../vendor/autoload.php';
2727

2828
use Doctrine\SqlFormatter\SqlFormatter;
29+
use Doctrine\SqlFormatter\Tokenizer;
2930

3031
echo (new SqlFormatter())->format($sql);

src/CliHighlighter.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ final class CliHighlighter implements Highlighter
3838

3939
public function highlightToken(int $type, string $value) : string
4040
{
41-
if ($type === SqlFormatter::TOKEN_TYPE_BOUNDARY && ($value==='(' || $value===')')) {
41+
if ($type === Token::TOKEN_TYPE_BOUNDARY && ($value==='(' || $value===')')) {
4242
return $value;
4343
}
4444

@@ -53,24 +53,24 @@ public function highlightToken(int $type, string $value) : string
5353
private function prefix(int $type) : ?string
5454
{
5555
switch ($type) {
56-
case SqlFormatter::TOKEN_TYPE_BOUNDARY:
56+
case Token::TOKEN_TYPE_BOUNDARY:
5757
return $this->cliBoundary;
58-
case SqlFormatter::TOKEN_TYPE_WORD:
58+
case Token::TOKEN_TYPE_WORD:
5959
return $this->cliWord;
60-
case SqlFormatter::TOKEN_TYPE_BACKTICK_QUOTE:
60+
case Token::TOKEN_TYPE_BACKTICK_QUOTE:
6161
return $this->cliBacktickQuote;
62-
case SqlFormatter::TOKEN_TYPE_QUOTE:
62+
case Token::TOKEN_TYPE_QUOTE:
6363
return $this->cliQuote;
64-
case SqlFormatter::TOKEN_TYPE_RESERVED:
65-
case SqlFormatter::TOKEN_TYPE_RESERVED_TOPLEVEL:
66-
case SqlFormatter::TOKEN_TYPE_RESERVED_NEWLINE:
64+
case Token::TOKEN_TYPE_RESERVED:
65+
case Token::TOKEN_TYPE_RESERVED_TOPLEVEL:
66+
case Token::TOKEN_TYPE_RESERVED_NEWLINE:
6767
return $this->cliReserved;
68-
case SqlFormatter::TOKEN_TYPE_NUMBER:
68+
case Token::TOKEN_TYPE_NUMBER:
6969
return $this->cliNumber;
70-
case SqlFormatter::TOKEN_TYPE_VARIABLE:
70+
case Token::TOKEN_TYPE_VARIABLE:
7171
return $this->cliVariable;
72-
case SqlFormatter::TOKEN_TYPE_COMMENT:
73-
case SqlFormatter::TOKEN_TYPE_BLOCK_COMMENT:
72+
case Token::TOKEN_TYPE_COMMENT:
73+
case Token::TOKEN_TYPE_BLOCK_COMMENT:
7474
return $this->cliComment;
7575
default:
7676
return null;

src/HtmlHighlighter.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function highlightToken(int $type, string $value) : string
5353
{
5454
$value = htmlentities($value, ENT_COMPAT | ENT_IGNORE, 'UTF-8');
5555

56-
if ($type === SqlFormatter::TOKEN_TYPE_BOUNDARY && ($value==='(' || $value===')')) {
56+
if ($type === Token::TOKEN_TYPE_BOUNDARY && ($value==='(' || $value===')')) {
5757
return $value;
5858
}
5959

@@ -68,24 +68,24 @@ public function highlightToken(int $type, string $value) : string
6868
public function attributes(int $type) : ?string
6969
{
7070
switch ($type) {
71-
case SqlFormatter::TOKEN_TYPE_BOUNDARY:
71+
case Token::TOKEN_TYPE_BOUNDARY:
7272
return $this->boundaryAttributes;
73-
case SqlFormatter::TOKEN_TYPE_WORD:
73+
case Token::TOKEN_TYPE_WORD:
7474
return $this->wordAttributes;
75-
case SqlFormatter::TOKEN_TYPE_BACKTICK_QUOTE:
75+
case Token::TOKEN_TYPE_BACKTICK_QUOTE:
7676
return $this->backtickQuoteAttributes;
77-
case SqlFormatter::TOKEN_TYPE_QUOTE:
77+
case Token::TOKEN_TYPE_QUOTE:
7878
return $this->quoteAttributes;
79-
case SqlFormatter::TOKEN_TYPE_RESERVED:
80-
case SqlFormatter::TOKEN_TYPE_RESERVED_TOPLEVEL:
81-
case SqlFormatter::TOKEN_TYPE_RESERVED_NEWLINE:
79+
case Token::TOKEN_TYPE_RESERVED:
80+
case Token::TOKEN_TYPE_RESERVED_TOPLEVEL:
81+
case Token::TOKEN_TYPE_RESERVED_NEWLINE:
8282
return $this->reservedAttributes;
83-
case SqlFormatter::TOKEN_TYPE_NUMBER:
83+
case Token::TOKEN_TYPE_NUMBER:
8484
return $this->numberAttributes;
85-
case SqlFormatter::TOKEN_TYPE_VARIABLE:
85+
case Token::TOKEN_TYPE_VARIABLE:
8686
return $this->variableAttributes;
87-
case SqlFormatter::TOKEN_TYPE_COMMENT:
88-
case SqlFormatter::TOKEN_TYPE_BLOCK_COMMENT:
87+
case Token::TOKEN_TYPE_COMMENT:
88+
case Token::TOKEN_TYPE_BLOCK_COMMENT:
8989
return $this->commentAttributes;
9090
default:
9191
return null;

0 commit comments

Comments
 (0)