Skip to content

Commit a321d11

Browse files
authored
Merge pull request #93 from rinu/force-uppercase
Force uppercase SQL keywords
2 parents eb67a95 + 7bb0ca4 commit a321d11

File tree

7 files changed

+206
-205
lines changed

7 files changed

+206
-205
lines changed

src/Tokenizer.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,7 @@ private function createNextToken(string $string, ?Token $previous = null): Token
909909
) {
910910
return new Token(
911911
Token::TOKEN_TYPE_RESERVED_TOPLEVEL,
912-
substr($string, 0, strlen($matches[1]))
912+
substr($upper, 0, strlen($matches[1]))
913913
);
914914
}
915915

@@ -923,7 +923,7 @@ private function createNextToken(string $string, ?Token $previous = null): Token
923923
) {
924924
return new Token(
925925
Token::TOKEN_TYPE_RESERVED_NEWLINE,
926-
substr($string, 0, strlen($matches[1]))
926+
substr($upper, 0, strlen($matches[1]))
927927
);
928928
}
929929

@@ -937,7 +937,7 @@ private function createNextToken(string $string, ?Token $previous = null): Token
937937
) {
938938
return new Token(
939939
Token::TOKEN_TYPE_RESERVED,
940-
substr($string, 0, strlen($matches[1]))
940+
substr($upper, 0, strlen($matches[1]))
941941
);
942942
}
943943
}
@@ -949,7 +949,7 @@ private function createNextToken(string $string, ?Token $previous = null): Token
949949
if (preg_match('/^(' . $this->regexFunction . '[(]|\s|[)])/', $upper, $matches)) {
950950
return new Token(
951951
Token::TOKEN_TYPE_RESERVED,
952-
substr($string, 0, strlen($matches[1]) - 1)
952+
substr($upper, 0, strlen($matches[1]) - 1)
953953
);
954954
}
955955

tests/clihighlight.html

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
SELECT
22
customer_id,
33
customer_name,
4-
[37mCOUNT[0m(order_id[0m) [37mas[0m total[0m
4+
[37mCOUNT[0m(order_id[0m) [37mAS[0m total[0m
55
FROM
66
customers
77
INNER JOIN orders ON customers.customer_id = orders.customer_id
@@ -21,12 +21,12 @@
2121
(
2222
SELECT
2323
customer_id,
24-
[37mcount[0m(order_id[0m) [37mAs[0m total[0m
24+
[37mCOUNT[0m(order_id[0m) [37mAS[0m total[0m
2525
FROM
2626
orders
2727
GROUP BY
2828
customer_id
29-
) [37mAs[0m ordersummary[0m
29+
) [37mAS[0m ordersummary[0m
3030
WHERE
3131
customers.customer_id = ordersummary.customer_id
3232
---
@@ -44,30 +44,30 @@
4444
NAMES 'utf8';
4545
---
4646
CREATE TABLE `PREFIX_address` (
47-
[35;1m`id_address`[0m int[0m([32;1m10[0m) [37munsigned[0m [37mNOT[0m [37mNULL[0m [37mauto_increment[0m,[0m
48-
[35;1m`id_country`[0m int[0m([32;1m10[0m) [37munsigned[0m [37mNOT[0m [37mNULL[0m,[0m
49-
[35;1m`id_state`[0m int[0m([32;1m10[0m) [37munsigned[0m [37mdefault[0m [37mNULL[0m,[0m
50-
[35;1m`id_customer`[0m int[0m([32;1m10[0m) [37munsigned[0m [37mNOT[0m [37mNULL[0m [37mdefault[0m [34;1m'0'[0m,[0m
51-
[35;1m`id_manufacturer`[0m int[0m([32;1m10[0m) [37munsigned[0m [37mNOT[0m [37mNULL[0m [37mdefault[0m [34;1m'0'[0m,[0m
52-
[35;1m`id_supplier`[0m int[0m([32;1m10[0m) [37munsigned[0m [37mNOT[0m [37mNULL[0m [37mdefault[0m [34;1m'0'[0m,[0m
53-
[35;1m`id_warehouse`[0m int[0m([32;1m10[0m) [37munsigned[0m [37mNOT[0m [37mNULL[0m [37mdefault[0m [34;1m'0'[0m,[0m
47+
[35;1m`id_address`[0m int[0m([32;1m10[0m) [37mUNSIGNED[0m [37mNOT[0m [37mNULL[0m [37mAUTO_INCREMENT[0m,[0m
48+
[35;1m`id_country`[0m int[0m([32;1m10[0m) [37mUNSIGNED[0m [37mNOT[0m [37mNULL[0m,[0m
49+
[35;1m`id_state`[0m int[0m([32;1m10[0m) [37mUNSIGNED[0m [37mDEFAULT[0m [37mNULL[0m,[0m
50+
[35;1m`id_customer`[0m int[0m([32;1m10[0m) [37mUNSIGNED[0m [37mNOT[0m [37mNULL[0m [37mDEFAULT[0m [34;1m'0'[0m,[0m
51+
[35;1m`id_manufacturer`[0m int[0m([32;1m10[0m) [37mUNSIGNED[0m [37mNOT[0m [37mNULL[0m [37mDEFAULT[0m [34;1m'0'[0m,[0m
52+
[35;1m`id_supplier`[0m int[0m([32;1m10[0m) [37mUNSIGNED[0m [37mNOT[0m [37mNULL[0m [37mDEFAULT[0m [34;1m'0'[0m,[0m
53+
[35;1m`id_warehouse`[0m int[0m([32;1m10[0m) [37mUNSIGNED[0m [37mNOT[0m [37mNULL[0m [37mDEFAULT[0m [34;1m'0'[0m,[0m
5454
`alias` varchar(32) NOT NULL,
55-
[35;1m`company`[0m varchar[0m([32;1m64[0m) [37mdefault[0m [37mNULL[0m,[0m
55+
[35;1m`company`[0m varchar[0m([32;1m64[0m) [37mDEFAULT[0m [37mNULL[0m,[0m
5656
`lastname` varchar(32) NOT NULL,
5757
`firstname` varchar(32) NOT NULL,
5858
`address1` varchar(128) NOT NULL,
59-
[35;1m`address2`[0m varchar[0m([32;1m128[0m) [37mdefault[0m [37mNULL[0m,[0m
60-
[35;1m`postcode`[0m varchar[0m([32;1m12[0m) [37mdefault[0m [37mNULL[0m,[0m
59+
[35;1m`address2`[0m varchar[0m([32;1m128[0m) [37mDEFAULT[0m [37mNULL[0m,[0m
60+
[35;1m`postcode`[0m varchar[0m([32;1m12[0m) [37mDEFAULT[0m [37mNULL[0m,[0m
6161
`city` varchar(64) NOT NULL,
6262
`other` text,
63-
[35;1m`phone`[0m varchar[0m([32;1m16[0m) [37mdefault[0m [37mNULL[0m,[0m
64-
[35;1m`phone_mobile`[0m varchar[0m([32;1m16[0m) [37mdefault[0m [37mNULL[0m,[0m
65-
[35;1m`vat_number`[0m varchar[0m([32;1m32[0m) [37mdefault[0m [37mNULL[0m,[0m
63+
[35;1m`phone`[0m varchar[0m([32;1m16[0m) [37mDEFAULT[0m [37mNULL[0m,[0m
64+
[35;1m`phone_mobile`[0m varchar[0m([32;1m16[0m) [37mDEFAULT[0m [37mNULL[0m,[0m
65+
[35;1m`vat_number`[0m varchar[0m([32;1m32[0m) [37mDEFAULT[0m [37mNULL[0m,[0m
6666
`dni` varchar(16) DEFAULT NULL,
6767
`date_add` datetime NOT NULL,
6868
`date_upd` datetime NOT NULL,
69-
[35;1m`active`[0m tinyint[0m([32;1m1[0m) [37munsigned[0m [37mNOT[0m [37mNULL[0m [37mdefault[0m [34;1m'1'[0m,[0m
70-
[35;1m`deleted`[0m tinyint[0m([32;1m1[0m) [37munsigned[0m [37mNOT[0m [37mNULL[0m [37mdefault[0m [34;1m'0'[0m,[0m
69+
[35;1m`active`[0m tinyint[0m([32;1m1[0m) [37mUNSIGNED[0m [37mNOT[0m [37mNULL[0m [37mDEFAULT[0m [34;1m'1'[0m,[0m
70+
[35;1m`deleted`[0m tinyint[0m([32;1m1[0m) [37mUNSIGNED[0m [37mNOT[0m [37mNULL[0m [37mDEFAULT[0m [34;1m'0'[0m,[0m
7171
PRIMARY KEY (`id_address`),
7272
KEY `address_customer` (`id_customer`),
7373
KEY `id_country` (`id_country`),
@@ -78,31 +78,31 @@
7878
) ENGINE = ENGINE_TYPE DEFAULT CHARSET = utf8
7979
---
8080
CREATE TABLE `PREFIX_alias` (
81-
[35;1m`id_alias`[0m int[0m([32;1m10[0m) [37munsigned[0m [37mNOT[0m [37mNULL[0m [37mauto_increment[0m,[0m
81+
[35;1m`id_alias`[0m int[0m([32;1m10[0m) [37mUNSIGNED[0m [37mNOT[0m [37mNULL[0m [37mAUTO_INCREMENT[0m,[0m
8282
`alias` varchar(255) NOT NULL,
8383
`search` varchar(255) NOT NULL,
84-
[35;1m`active`[0m tinyint[0m([32;1m1[0m) [37mNOT[0m [37mNULL[0m [37mdefault[0m [34;1m'1'[0m,[0m
84+
[35;1m`active`[0m tinyint[0m([32;1m1[0m) [37mNOT[0m [37mNULL[0m [37mDEFAULT[0m [34;1m'1'[0m,[0m
8585
PRIMARY KEY (`id_alias`),
8686
UNIQUE KEY `alias` (`alias`)
8787
) ENGINE = ENGINE_TYPE DEFAULT CHARSET = utf8
8888
---
8989
CREATE TABLE `PREFIX_carrier` (
90-
[35;1m`id_carrier`[0m int[0m([32;1m10[0m) [37munsigned[0m [37mNOT[0m [37mNULL[0m [37mAUTO_INCREMENT[0m,[0m
91-
[35;1m`id_reference`[0m int[0m([32;1m10[0m) [37munsigned[0m [37mNOT[0m [37mNULL[0m,[0m
92-
[35;1m`id_tax_rules_group`[0m int[0m([32;1m10[0m) [37munsigned[0m [37mDEFAULT[0m [34;1m'0'[0m,[0m
90+
[35;1m`id_carrier`[0m int[0m([32;1m10[0m) [37mUNSIGNED[0m [37mNOT[0m [37mNULL[0m [37mAUTO_INCREMENT[0m,[0m
91+
[35;1m`id_reference`[0m int[0m([32;1m10[0m) [37mUNSIGNED[0m [37mNOT[0m [37mNULL[0m,[0m
92+
[35;1m`id_tax_rules_group`[0m int[0m([32;1m10[0m) [37mUNSIGNED[0m [37mDEFAULT[0m [34;1m'0'[0m,[0m
9393
`name` varchar(64) NOT NULL,
9494
`url` varchar(255) DEFAULT NULL,
95-
[35;1m`active`[0m tinyint[0m([32;1m1[0m) [37munsigned[0m [37mNOT[0m [37mNULL[0m [37mDEFAULT[0m [34;1m'0'[0m,[0m
96-
[35;1m`deleted`[0m tinyint[0m([32;1m1[0m) [37munsigned[0m [37mNOT[0m [37mNULL[0m [37mDEFAULT[0m [34;1m'0'[0m,[0m
97-
[35;1m`shipping_handling`[0m tinyint[0m([32;1m1[0m) [37munsigned[0m [37mNOT[0m [37mNULL[0m [37mDEFAULT[0m [34;1m'1'[0m,[0m
98-
[35;1m`range_behavior`[0m tinyint[0m([32;1m1[0m) [37munsigned[0m [37mNOT[0m [37mNULL[0m [37mDEFAULT[0m [34;1m'0'[0m,[0m
99-
[35;1m`is_module`[0m tinyint[0m([32;1m1[0m) [37munsigned[0m [37mNOT[0m [37mNULL[0m [37mDEFAULT[0m [34;1m'0'[0m,[0m
100-
[35;1m`is_free`[0m tinyint[0m([32;1m1[0m) [37munsigned[0m [37mNOT[0m [37mNULL[0m [37mDEFAULT[0m [34;1m'0'[0m,[0m
101-
[35;1m`shipping_external`[0m tinyint[0m([32;1m1[0m) [37munsigned[0m [37mNOT[0m [37mNULL[0m [37mDEFAULT[0m [34;1m'0'[0m,[0m
102-
[35;1m`need_range`[0m tinyint[0m([32;1m1[0m) [37munsigned[0m [37mNOT[0m [37mNULL[0m [37mDEFAULT[0m [34;1m'0'[0m,[0m
95+
[35;1m`active`[0m tinyint[0m([32;1m1[0m) [37mUNSIGNED[0m [37mNOT[0m [37mNULL[0m [37mDEFAULT[0m [34;1m'0'[0m,[0m
96+
[35;1m`deleted`[0m tinyint[0m([32;1m1[0m) [37mUNSIGNED[0m [37mNOT[0m [37mNULL[0m [37mDEFAULT[0m [34;1m'0'[0m,[0m
97+
[35;1m`shipping_handling`[0m tinyint[0m([32;1m1[0m) [37mUNSIGNED[0m [37mNOT[0m [37mNULL[0m [37mDEFAULT[0m [34;1m'1'[0m,[0m
98+
[35;1m`range_behavior`[0m tinyint[0m([32;1m1[0m) [37mUNSIGNED[0m [37mNOT[0m [37mNULL[0m [37mDEFAULT[0m [34;1m'0'[0m,[0m
99+
[35;1m`is_module`[0m tinyint[0m([32;1m1[0m) [37mUNSIGNED[0m [37mNOT[0m [37mNULL[0m [37mDEFAULT[0m [34;1m'0'[0m,[0m
100+
[35;1m`is_free`[0m tinyint[0m([32;1m1[0m) [37mUNSIGNED[0m [37mNOT[0m [37mNULL[0m [37mDEFAULT[0m [34;1m'0'[0m,[0m
101+
[35;1m`shipping_external`[0m tinyint[0m([32;1m1[0m) [37mUNSIGNED[0m [37mNOT[0m [37mNULL[0m [37mDEFAULT[0m [34;1m'0'[0m,[0m
102+
[35;1m`need_range`[0m tinyint[0m([32;1m1[0m) [37mUNSIGNED[0m [37mNOT[0m [37mNULL[0m [37mDEFAULT[0m [34;1m'0'[0m,[0m
103103
`external_module_name` varchar(64) DEFAULT NULL,
104104
`shipping_method` int(2) NOT NULL DEFAULT '0',
105-
[35;1m`position`[0m int[0m([32;1m10[0m) [37munsigned[0m [37mNOT[0m [37mNULL[0m [37mdefault[0m [34;1m'0'[0m,[0m
105+
[35;1m`position`[0m int[0m([32;1m10[0m) [37mUNSIGNED[0m [37mNOT[0m [37mNULL[0m [37mDEFAULT[0m [34;1m'0'[0m,[0m
106106
`max_width` int(10) DEFAULT 0,
107107
`max_height` int(10) DEFAULT 0,
108108
`max_depth` int(10) DEFAULT 0,
@@ -114,13 +114,13 @@
114114
) ENGINE = ENGINE_TYPE DEFAULT CHARSET = utf8
115115
---
116116
CREATE TABLE IF NOT EXISTS `PREFIX_specific_price_rule` (
117-
[35;1m`id_specific_price_rule`[0m int[0m([32;1m10[0m) [37munsigned[0m [37mNOT[0m [37mNULL[0m [37mAUTO_INCREMENT[0m,[0m
117+
[35;1m`id_specific_price_rule`[0m int[0m([32;1m10[0m) [37mUNSIGNED[0m [37mNOT[0m [37mNULL[0m [37mAUTO_INCREMENT[0m,[0m
118118
`name` VARCHAR(255) NOT NULL,
119-
[35;1m`id_shop`[0m int[0m([32;1m11[0m) [37munsigned[0m [37mNOT[0m [37mNULL[0m [37mDEFAULT[0m [34;1m'1'[0m,[0m
120-
[35;1m`id_currency`[0m int[0m([32;1m10[0m) [37munsigned[0m [37mNOT[0m [37mNULL[0m,[0m
121-
[35;1m`id_country`[0m int[0m([32;1m10[0m) [37munsigned[0m [37mNOT[0m [37mNULL[0m,[0m
122-
[35;1m`id_group`[0m int[0m([32;1m10[0m) [37munsigned[0m [37mNOT[0m [37mNULL[0m,[0m
123-
[35;1m`from_quantity`[0m mediumint[0m([32;1m8[0m) [37munsigned[0m [37mNOT[0m [37mNULL[0m,[0m
119+
[35;1m`id_shop`[0m int[0m([32;1m11[0m) [37mUNSIGNED[0m [37mNOT[0m [37mNULL[0m [37mDEFAULT[0m [34;1m'1'[0m,[0m
120+
[35;1m`id_currency`[0m int[0m([32;1m10[0m) [37mUNSIGNED[0m [37mNOT[0m [37mNULL[0m,[0m
121+
[35;1m`id_country`[0m int[0m([32;1m10[0m) [37mUNSIGNED[0m [37mNOT[0m [37mNULL[0m,[0m
122+
[35;1m`id_group`[0m int[0m([32;1m10[0m) [37mUNSIGNED[0m [37mNOT[0m [37mNULL[0m,[0m
123+
[35;1m`from_quantity`[0m mediumint[0m([32;1m8[0m) [37mUNSIGNED[0m [37mNOT[0m [37mNULL[0m,[0m
124124
`price` DECIMAL(20, 6),
125125
`reduction` decimal(20, 6) NOT NULL,
126126
`reduction_type` enum('amount', 'percentage') NOT NULL,
@@ -454,7 +454,7 @@
454454
ALTER TABLE
455455
`PREFIX_employee`
456456
ADD
457-
[35;1m`bo_color`[0m varchar[0m([32;1m32[0m) [37mdefault[0m [37mNULL[0m [37mAFTER[0m [35;1m`stats_date_to`[0m
457+
[35;1m`bo_color`[0m varchar[0m([32;1m32[0m) [37mDEFAULT[0m [37mNULL[0m [37mAFTER[0m [35;1m`stats_date_to`[0m
458458
---
459459
INSERT INTO `PREFIX_cms_category_lang`
460460
VALUES
@@ -779,16 +779,16 @@
779779
2,
780780
3
781781
WHERE
782-
a[0m [37min[0m ([32;1m1[0m,[0m [32;1m2[0m,[0m [32;1m3[0m,[0m [32;1m4[0m,[0m [32;1m5[0m)
783-
[37mand[0m b[0m =[0m [32;1m5[0m;[0m
782+
a[0m [37mIN[0m ([32;1m1[0m,[0m [32;1m2[0m,[0m [32;1m3[0m,[0m [32;1m4[0m,[0m [32;1m5[0m)
783+
[37mAND[0m b[0m =[0m [32;1m5[0m;[0m
784784
---
785785
SELECT
786-
count[0m -[0m [32;1m50[0m
786+
[35;1m`count`[0m -[0m [32;1m50[0m
787787
WHERE
788788
a - 50 = b
789789
WHERE
790790
1
791-
[37mand[0m -[0m[32;1m50[0m
791+
[37mAND[0m -[0m[32;1m50[0m
792792
WHERE
793793
-50 = a
794794
WHERE
@@ -799,11 +799,11 @@
799799
-50
800800
WHERE
801801
1
802-
[37mand[0m -[0m[32;1m50[0m;[0m
802+
[37mAND[0m -[0m[32;1m50[0m;[0m
803803
---
804804
SELECT
805805
@
806-
[37mand[0m b[0m;[0m
806+
[37mAND[0m b[0m;[0m
807807
---
808808
SELECT
809809
@"weird variable name";
@@ -823,15 +823,15 @@
823823
a
824824
FROM
825825
b
826-
[37mLEFT OUTER JOIN[0m c[0m [37mon[0m (d[0m =[0m f[0m);[0m
826+
[37mLEFT OUTER JOIN[0m c[0m [37mON[0m (d[0m =[0m f[0m);[0m
827827
---
828828
WITH
829829
cte AS (
830830
SELECT
831831
a,
832832
b
833833
FROM
834-
[37mtable[0m
834+
[35;1m`table`[0m
835835
),
836836
RECURSIVE fibonacci (n, fib_n, next_fib_n) AS (
837837
SELECT

0 commit comments

Comments
 (0)