Skip to content

Commit 0f7b39d

Browse files
committed
Add all "type reserved" MySQL keywords
To fix all type highlighting in function tests.
1 parent 82e01b2 commit 0f7b39d

File tree

6 files changed

+214
-183
lines changed

6 files changed

+214
-183
lines changed

src/Tokenizer.php

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,17 @@ final class Tokenizer
4646
'BACKUP',
4747
'BEGIN',
4848
'BETWEEN',
49+
'BIGINT',
50+
'BINARY',
4951
'BINLOG',
52+
'BLOB',
5053
'BOTH',
5154
'BY',
5255
'CASCADE',
5356
'CASE',
5457
'CHANGE',
5558
'CHANGED',
59+
'CHAR',
5660
'CHARACTER',
5761
'CHARSET',
5862
'CHECK',
@@ -79,6 +83,7 @@ final class Tokenizer
7983
'DAY_HOUR',
8084
'DAY_MINUTE',
8185
'DAY_SECOND',
86+
'DECIMAL',
8287
'DEFAULT',
8388
'DEFINER',
8489
'DELAYED',
@@ -90,6 +95,7 @@ final class Tokenizer
9095
'DISTINCTROW',
9196
'DIV',
9297
'DO',
98+
'DOUBLE',
9399
'DROP',
94100
'DUMPFILE',
95101
'DUPLICATE',
@@ -110,12 +116,16 @@ final class Tokenizer
110116
'EXISTS',
111117
'EXPLAIN',
112118
'EXTENDED',
119+
'FALSE',
113120
'FAST',
114121
'FIELDS',
115122
'FILE',
116123
'FILTER',
117124
'FIRST',
118125
'FIXED',
126+
'FLOAT',
127+
'FLOAT4',
128+
'FLOAT8',
119129
'FLUSH',
120130
'FOLLOWING',
121131
'FOR',
@@ -149,6 +159,13 @@ final class Tokenizer
149159
'INSERT',
150160
'INSERT_ID',
151161
'INSERT_METHOD',
162+
'INT',
163+
'INT1',
164+
'INT2',
165+
'INT3',
166+
'INT4',
167+
'INT8',
168+
'INTEGER',
152169
'INTERSECT',
153170
'INTERVAL',
154171
'INTO',
@@ -172,6 +189,9 @@ final class Tokenizer
172189
'LOCK',
173190
'LOCKS',
174191
'LOGS',
192+
'LONG',
193+
'LONGBLOB',
194+
'LONGTEXT',
175195
'LOW_PRIORITY',
176196
'MARIA',
177197
'MASTER',
@@ -185,6 +205,9 @@ final class Tokenizer
185205
'MAX_UPDATES_PER_HOUR',
186206
'MAX_USER_CONNECTIONS',
187207
'MEDIUM',
208+
'MEDIUMBLOB',
209+
'MEDIUMINT',
210+
'MEDIUMTEXT',
188211
'MERGE',
189212
'MINUTE',
190213
'MINUTE_SECOND',
@@ -198,6 +221,7 @@ final class Tokenizer
198221
'NATURAL',
199222
'NOT',
200223
'NULL',
224+
'NUMERIC',
201225
'OFFSET',
202226
'ON',
203227
'OPEN',
@@ -231,6 +255,7 @@ final class Tokenizer
231255
'READ',
232256
'READ_ONLY',
233257
'READ_WRITE',
258+
'REAL',
234259
'RECURSIVE',
235260
'REFERENCES',
236261
'REGEXP',
@@ -263,6 +288,7 @@ final class Tokenizer
263288
'SHOW',
264289
'SHUTDOWN',
265290
'SLAVE',
291+
'SMALLINT',
266292
'SONAME',
267293
'SOUNDS',
268294
'SQL',
@@ -300,6 +326,9 @@ final class Tokenizer
300326
'TERMINATED',
301327
'THEN',
302328
'TIES',
329+
'TINYBLOB',
330+
'TINYINT',
331+
'TINYTEXT',
303332
'TO',
304333
'TRAILING',
305334
'TRANSACTIONAL',
@@ -318,6 +347,9 @@ final class Tokenizer
318347
'USE',
319348
'USING',
320349
'VALUES',
350+
'VARBINARY',
351+
'VARCHAR',
352+
'VARCHARACTER',
321353
'VARIABLES',
322354
'VIEW',
323355
'WHEN',
@@ -414,7 +446,6 @@ final class Tokenizer
414446
'CEIL',
415447
'CEILING',
416448
'CENTROID',
417-
'CHAR',
418449
'CHARACTER_LENGTH',
419450
'CHAR_LENGTH',
420451
'CHECKSUM_AGG',

tests/SqlFormatterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function testHighlightBinary(): void
6969
$html = '<pre style="color: black; background-color: white;">' .
7070
'<span style="font-weight:bold;">SELECT</span> <span style="color: blue;">' .
7171
$binaryData .
72-
'</span> <span style="font-weight:bold;">AS</span> <span style="color: #333;">BINARY</span></pre>';
72+
'</span> <span style="font-weight:bold;">AS</span> <span style="font-weight:bold;">BINARY</span></pre>';
7373

7474
$this->assertSame($html, $this->formatter->highlight($sql));
7575
}

tests/TokenizerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public static function tokenizeLongConcatData(): Generator
190190
$expectedTokens[] = new Token(Token::TOKEN_TYPE_WHITESPACE, ' ');
191191
$expectedTokens[] = new Token(Token::TOKEN_TYPE_RESERVED, 'as');
192192
$expectedTokens[] = new Token(Token::TOKEN_TYPE_WHITESPACE, ' ');
193-
$expectedTokens[] = new Token(Token::TOKEN_TYPE_WORD, 'blob');
193+
$expectedTokens[] = new Token(Token::TOKEN_TYPE_RESERVED, 'blob');
194194
$expectedTokens[] = new Token(Token::TOKEN_TYPE_BOUNDARY, ')');
195195
}
196196

tests/clihighlight.txt

Lines changed: 60 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -46,30 +46,30 @@
4646
NAMES 'utf8';
4747
---
4848
CREATE TABLE `PREFIX_address` (
49-
`id_address` int(10) unsigned NOT NULL auto_increment,
50-
`id_country` int(10) unsigned NOT NULL,
51-
`id_state` int(10) unsigned default NULL,
52-
`id_customer` int(10) unsigned NOT NULL default '0',
53-
`id_manufacturer` int(10) unsigned NOT NULL default '0',
54-
`id_supplier` int(10) unsigned NOT NULL default '0',
55-
`id_warehouse` int(10) unsigned NOT NULL default '0',
56-
`alias` varchar(32) NOT NULL,
57-
`company` varchar(64) default NULL,
58-
`lastname` varchar(32) NOT NULL,
59-
`firstname` varchar(32) NOT NULL,
60-
`address1` varchar(128) NOT NULL,
61-
`address2` varchar(128) default NULL,
62-
`postcode` varchar(12) default NULL,
63-
`city` varchar(64) NOT NULL,
49+
`id_address` int(10) unsigned NOT NULL auto_increment,
50+
`id_country` int(10) unsigned NOT NULL,
51+
`id_state` int(10) unsigned default NULL,
52+
`id_customer` int(10) unsigned NOT NULL default '0',
53+
`id_manufacturer` int(10) unsigned NOT NULL default '0',
54+
`id_supplier` int(10) unsigned NOT NULL default '0',
55+
`id_warehouse` int(10) unsigned NOT NULL default '0',
56+
`alias` varchar(32) NOT NULL,
57+
`company` varchar(64) default NULL,
58+
`lastname` varchar(32) NOT NULL,
59+
`firstname` varchar(32) NOT NULL,
60+
`address1` varchar(128) NOT NULL,
61+
`address2` varchar(128) default NULL,
62+
`postcode` varchar(12) default NULL,
63+
`city` varchar(64) NOT NULL,
6464
`other` text,
65-
`phone` varchar(16) default NULL,
66-
`phone_mobile` varchar(16) default NULL,
67-
`vat_number` varchar(32) default NULL,
68-
`dni` varchar(16) DEFAULT NULL,
65+
`phone` varchar(16) default NULL,
66+
`phone_mobile` varchar(16) default NULL,
67+
`vat_number` varchar(32) default NULL,
68+
`dni` varchar(16) DEFAULT NULL,
6969
`date_add` datetime NOT NULL,
7070
`date_upd` datetime NOT NULL,
71-
`active` tinyint(1) unsigned NOT NULL default '1',
72-
`deleted` tinyint(1) unsigned NOT NULL default '0',
71+
`active` tinyint(1) unsigned NOT NULL default '1',
72+
`deleted` tinyint(1) unsigned NOT NULL default '0',
7373
PRIMARY KEY (`id_address`),
7474
KEY `address_customer` (`id_customer`),
7575
KEY `id_country` (`id_country`),
@@ -80,51 +80,51 @@
8080
) ENGINE = ENGINE_TYPE DEFAULT CHARSET = utf8
8181
---
8282
CREATE TABLE `PREFIX_alias` (
83-
`id_alias` int(10) unsigned NOT NULL auto_increment,
84-
`alias` varchar(255) NOT NULL,
85-
`search` varchar(255) NOT NULL,
86-
`active` tinyint(1) NOT NULL default '1',
83+
`id_alias` int(10) unsigned NOT NULL auto_increment,
84+
`alias` varchar(255) NOT NULL,
85+
`search` varchar(255) NOT NULL,
86+
`active` tinyint(1) NOT NULL default '1',
8787
PRIMARY KEY (`id_alias`),
8888
UNIQUE KEY `alias` (`alias`)
8989
) ENGINE = ENGINE_TYPE DEFAULT CHARSET = utf8
9090
---
9191
CREATE TABLE `PREFIX_carrier` (
92-
`id_carrier` int(10) unsigned NOT NULL AUTO_INCREMENT,
93-
`id_reference` int(10) unsigned NOT NULL,
94-
`id_tax_rules_group` int(10) unsigned DEFAULT '0',
95-
`name` varchar(64) NOT NULL,
96-
`url` varchar(255) DEFAULT NULL,
97-
`active` tinyint(1) unsigned NOT NULL DEFAULT '0',
98-
`deleted` tinyint(1) unsigned NOT NULL DEFAULT '0',
99-
`shipping_handling` tinyint(1) unsigned NOT NULL DEFAULT '1',
100-
`range_behavior` tinyint(1) unsigned NOT NULL DEFAULT '0',
101-
`is_module` tinyint(1) unsigned NOT NULL DEFAULT '0',
102-
`is_free` tinyint(1) unsigned NOT NULL DEFAULT '0',
103-
`shipping_external` tinyint(1) unsigned NOT NULL DEFAULT '0',
104-
`need_range` tinyint(1) unsigned NOT NULL DEFAULT '0',
105-
`external_module_name` varchar(64) DEFAULT NULL,
106-
`shipping_method` int(2) NOT NULL DEFAULT '0',
107-
`position` int(10) unsigned NOT NULL default '0',
108-
`max_width` int(10) DEFAULT 0,
109-
`max_height` int(10) DEFAULT 0,
110-
`max_depth` int(10) DEFAULT 0,
111-
`max_weight` int(10) DEFAULT 0,
112-
`grade` int(10) DEFAULT 0,
92+
`id_carrier` int(10) unsigned NOT NULL AUTO_INCREMENT,
93+
`id_reference` int(10) unsigned NOT NULL,
94+
`id_tax_rules_group` int(10) unsigned DEFAULT '0',
95+
`name` varchar(64) NOT NULL,
96+
`url` varchar(255) DEFAULT NULL,
97+
`active` tinyint(1) unsigned NOT NULL DEFAULT '0',
98+
`deleted` tinyint(1) unsigned NOT NULL DEFAULT '0',
99+
`shipping_handling` tinyint(1) unsigned NOT NULL DEFAULT '1',
100+
`range_behavior` tinyint(1) unsigned NOT NULL DEFAULT '0',
101+
`is_module` tinyint(1) unsigned NOT NULL DEFAULT '0',
102+
`is_free` tinyint(1) unsigned NOT NULL DEFAULT '0',
103+
`shipping_external` tinyint(1) unsigned NOT NULL DEFAULT '0',
104+
`need_range` tinyint(1) unsigned NOT NULL DEFAULT '0',
105+
`external_module_name` varchar(64) DEFAULT NULL,
106+
`shipping_method` int(2) NOT NULL DEFAULT '0',
107+
`position` int(10) unsigned NOT NULL default '0',
108+
`max_width` int(10) DEFAULT 0,
109+
`max_height` int(10) DEFAULT 0,
110+
`max_depth` int(10) DEFAULT 0,
111+
`max_weight` int(10) DEFAULT 0,
112+
`grade` int(10) DEFAULT 0,
113113
PRIMARY KEY (`id_carrier`),
114114
KEY `deleted` (`deleted`, `active`),
115115
KEY `id_tax_rules_group` (`id_tax_rules_group`)
116116
) ENGINE = ENGINE_TYPE DEFAULT CHARSET = utf8
117117
---
118118
CREATE TABLE IF NOT EXISTS `PREFIX_specific_price_rule` (
119-
`id_specific_price_rule` int(10) unsigned NOT NULL AUTO_INCREMENT,
120-
`name` VARCHAR(255) NOT NULL,
121-
`id_shop` int(11) unsigned NOT NULL DEFAULT '1',
122-
`id_currency` int(10) unsigned NOT NULL,
123-
`id_country` int(10) unsigned NOT NULL,
124-
`id_group` int(10) unsigned NOT NULL,
125-
`from_quantity` mediumint(8) unsigned NOT NULL,
126-
`price` DECIMAL(20, 6),
127-
`reduction` decimal(20, 6) NOT NULL,
119+
`id_specific_price_rule` int(10) unsigned NOT NULL AUTO_INCREMENT,
120+
`name` VARCHAR(255) NOT NULL,
121+
`id_shop` int(11) unsigned NOT NULL DEFAULT '1',
122+
`id_currency` int(10) unsigned NOT NULL,
123+
`id_country` int(10) unsigned NOT NULL,
124+
`id_group` int(10) unsigned NOT NULL,
125+
`from_quantity` mediumint(8) unsigned NOT NULL,
126+
`price` DECIMAL(20, 6),
127+
`reduction` decimal(20, 6) NOT NULL,
128128
`reduction_type` enum('amount', 'percentage') NOT NULL,
129129
`from` datetime NOT NULL,
130130
`to` datetime NOT NULL,
@@ -456,7 +456,7 @@
456456
ALTER TABLE
457457
`PREFIX_employee`
458458
ADD
459-
`bo_color` varchar(32) default NULL AFTER `stats_date_to`
459+
`bo_color` varchar(32) default NULL AFTER `stats_date_to`
460460
---
461461
INSERT INTO `PREFIX_cms_category_lang`
462462
VALUES
@@ -490,7 +490,7 @@
490490
ALTER TABLE
491491
`PREFIX_contact`
492492
ADD
493-
`customer_service` tinyint(1) NOT NULL DEFAULT 0 AFTER `email`
493+
`customer_service` tinyint(1) NOT NULL DEFAULT 0 AFTER `email`
494494
---
495495
INSERT INTO `PREFIX_specific_price` (
496496
`id_product`, `id_shop`, `id_currency`,
@@ -787,12 +787,12 @@
787787
ALTER TABLE
788788
`test_modify`
789789
MODIFY
790-
`id` INT(11) UNSIGNED NOT NULL;
790+
`id` INT(11) UNSIGNED NOT NULL;
791791
---
792792
ALTER TABLE
793793
`test_change`
794794
CHANGE
795-
`id` `_id` BIGINT(20) UNSIGNED NULL;
795+
`id` `_id` BIGINT(20) UNSIGNED NULL;
796796
---
797797
SELECT
798798
*
@@ -952,7 +952,7 @@
952952
a
953953
) AS filtered,
954954
CONVERT(
955-
VARCHAR(20),
955+
VARCHAR(20),
956956
AVG(SalesYTD) OVER (
957957
PARTITION BY
958958
TerritoryID

0 commit comments

Comments
 (0)