Skip to content

Commit

Permalink
Merge pull request #93 from rinu/force-uppercase
Browse files Browse the repository at this point in the history
Force uppercase SQL keywords
  • Loading branch information
greg0ire authored Aug 16, 2023
2 parents eb67a95 + 7bb0ca4 commit a321d11
Show file tree
Hide file tree
Showing 7 changed files with 206 additions and 205 deletions.
8 changes: 4 additions & 4 deletions src/Tokenizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ private function createNextToken(string $string, ?Token $previous = null): Token
) {
return new Token(
Token::TOKEN_TYPE_RESERVED_TOPLEVEL,
substr($string, 0, strlen($matches[1]))
substr($upper, 0, strlen($matches[1]))
);
}

Expand All @@ -923,7 +923,7 @@ private function createNextToken(string $string, ?Token $previous = null): Token
) {
return new Token(
Token::TOKEN_TYPE_RESERVED_NEWLINE,
substr($string, 0, strlen($matches[1]))
substr($upper, 0, strlen($matches[1]))
);
}

Expand All @@ -937,7 +937,7 @@ private function createNextToken(string $string, ?Token $previous = null): Token
) {
return new Token(
Token::TOKEN_TYPE_RESERVED,
substr($string, 0, strlen($matches[1]))
substr($upper, 0, strlen($matches[1]))
);
}
}
Expand All @@ -949,7 +949,7 @@ private function createNextToken(string $string, ?Token $previous = null): Token
if (preg_match('/^(' . $this->regexFunction . '[(]|\s|[)])/', $upper, $matches)) {
return new Token(
Token::TOKEN_TYPE_RESERVED,
substr($string, 0, strlen($matches[1]) - 1)
substr($upper, 0, strlen($matches[1]) - 1)
);
}

Expand Down
94 changes: 47 additions & 47 deletions tests/clihighlight.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
SELECT
customer_id,
customer_name,
[37mCOUNT[0m(order_id[0m) [37mas[0m total[0m
[37mCOUNT[0m(order_id[0m) [37mAS[0m total[0m
FROM
customers
INNER JOIN orders ON customers.customer_id = orders.customer_id
Expand All @@ -21,12 +21,12 @@
(
SELECT
customer_id,
[37mcount[0m(order_id[0m) [37mAs[0m total[0m
[37mCOUNT[0m(order_id[0m) [37mAS[0m total[0m
FROM
orders
GROUP BY
customer_id
) [37mAs[0m ordersummary[0m
) [37mAS[0m ordersummary[0m
WHERE
customers.customer_id = ordersummary.customer_id
---
Expand All @@ -44,30 +44,30 @@
NAMES 'utf8';
---
CREATE TABLE `PREFIX_address` (
[35;1m`id_address`[0m int[0m([32;1m10[0m) [37munsigned[0m [37mNOT[0m [37mNULL[0m [37mauto_increment[0m,[0m
[35;1m`id_country`[0m int[0m([32;1m10[0m) [37munsigned[0m [37mNOT[0m [37mNULL[0m,[0m
[35;1m`id_state`[0m int[0m([32;1m10[0m) [37munsigned[0m [37mdefault[0m [37mNULL[0m,[0m
[35;1m`id_customer`[0m int[0m([32;1m10[0m) [37munsigned[0m [37mNOT[0m [37mNULL[0m [37mdefault[0m [34;1m'0'[0m,[0m
[35;1m`id_manufacturer`[0m int[0m([32;1m10[0m) [37munsigned[0m [37mNOT[0m [37mNULL[0m [37mdefault[0m [34;1m'0'[0m,[0m
[35;1m`id_supplier`[0m int[0m([32;1m10[0m) [37munsigned[0m [37mNOT[0m [37mNULL[0m [37mdefault[0m [34;1m'0'[0m,[0m
[35;1m`id_warehouse`[0m int[0m([32;1m10[0m) [37munsigned[0m [37mNOT[0m [37mNULL[0m [37mdefault[0m [34;1m'0'[0m,[0m
[35;1m`id_address`[0m int[0m([32;1m10[0m) [37mUNSIGNED[0m [37mNOT[0m [37mNULL[0m [37mAUTO_INCREMENT[0m,[0m
[35;1m`id_country`[0m int[0m([32;1m10[0m) [37mUNSIGNED[0m [37mNOT[0m [37mNULL[0m,[0m
[35;1m`id_state`[0m int[0m([32;1m10[0m) [37mUNSIGNED[0m [37mDEFAULT[0m [37mNULL[0m,[0m
[35;1m`id_customer`[0m int[0m([32;1m10[0m) [37mUNSIGNED[0m [37mNOT[0m [37mNULL[0m [37mDEFAULT[0m [34;1m'0'[0m,[0m
[35;1m`id_manufacturer`[0m int[0m([32;1m10[0m) [37mUNSIGNED[0m [37mNOT[0m [37mNULL[0m [37mDEFAULT[0m [34;1m'0'[0m,[0m
[35;1m`id_supplier`[0m int[0m([32;1m10[0m) [37mUNSIGNED[0m [37mNOT[0m [37mNULL[0m [37mDEFAULT[0m [34;1m'0'[0m,[0m
[35;1m`id_warehouse`[0m int[0m([32;1m10[0m) [37mUNSIGNED[0m [37mNOT[0m [37mNULL[0m [37mDEFAULT[0m [34;1m'0'[0m,[0m
`alias` varchar(32) NOT NULL,
[35;1m`company`[0m varchar[0m([32;1m64[0m) [37mdefault[0m [37mNULL[0m,[0m
[35;1m`company`[0m varchar[0m([32;1m64[0m) [37mDEFAULT[0m [37mNULL[0m,[0m
`lastname` varchar(32) NOT NULL,
`firstname` varchar(32) NOT NULL,
`address1` varchar(128) NOT NULL,
[35;1m`address2`[0m varchar[0m([32;1m128[0m) [37mdefault[0m [37mNULL[0m,[0m
[35;1m`postcode`[0m varchar[0m([32;1m12[0m) [37mdefault[0m [37mNULL[0m,[0m
[35;1m`address2`[0m varchar[0m([32;1m128[0m) [37mDEFAULT[0m [37mNULL[0m,[0m
[35;1m`postcode`[0m varchar[0m([32;1m12[0m) [37mDEFAULT[0m [37mNULL[0m,[0m
`city` varchar(64) NOT NULL,
`other` text,
[35;1m`phone`[0m varchar[0m([32;1m16[0m) [37mdefault[0m [37mNULL[0m,[0m
[35;1m`phone_mobile`[0m varchar[0m([32;1m16[0m) [37mdefault[0m [37mNULL[0m,[0m
[35;1m`vat_number`[0m varchar[0m([32;1m32[0m) [37mdefault[0m [37mNULL[0m,[0m
[35;1m`phone`[0m varchar[0m([32;1m16[0m) [37mDEFAULT[0m [37mNULL[0m,[0m
[35;1m`phone_mobile`[0m varchar[0m([32;1m16[0m) [37mDEFAULT[0m [37mNULL[0m,[0m
[35;1m`vat_number`[0m varchar[0m([32;1m32[0m) [37mDEFAULT[0m [37mNULL[0m,[0m
`dni` varchar(16) DEFAULT NULL,
`date_add` datetime NOT NULL,
`date_upd` datetime NOT NULL,
[35;1m`active`[0m tinyint[0m([32;1m1[0m) [37munsigned[0m [37mNOT[0m [37mNULL[0m [37mdefault[0m [34;1m'1'[0m,[0m
[35;1m`deleted`[0m tinyint[0m([32;1m1[0m) [37munsigned[0m [37mNOT[0m [37mNULL[0m [37mdefault[0m [34;1m'0'[0m,[0m
[35;1m`active`[0m tinyint[0m([32;1m1[0m) [37mUNSIGNED[0m [37mNOT[0m [37mNULL[0m [37mDEFAULT[0m [34;1m'1'[0m,[0m
[35;1m`deleted`[0m tinyint[0m([32;1m1[0m) [37mUNSIGNED[0m [37mNOT[0m [37mNULL[0m [37mDEFAULT[0m [34;1m'0'[0m,[0m
PRIMARY KEY (`id_address`),
KEY `address_customer` (`id_customer`),
KEY `id_country` (`id_country`),
Expand All @@ -78,31 +78,31 @@
) ENGINE = ENGINE_TYPE DEFAULT CHARSET = utf8
---
CREATE TABLE `PREFIX_alias` (
[35;1m`id_alias`[0m int[0m([32;1m10[0m) [37munsigned[0m [37mNOT[0m [37mNULL[0m [37mauto_increment[0m,[0m
[35;1m`id_alias`[0m int[0m([32;1m10[0m) [37mUNSIGNED[0m [37mNOT[0m [37mNULL[0m [37mAUTO_INCREMENT[0m,[0m
`alias` varchar(255) NOT NULL,
`search` varchar(255) NOT NULL,
[35;1m`active`[0m tinyint[0m([32;1m1[0m) [37mNOT[0m [37mNULL[0m [37mdefault[0m [34;1m'1'[0m,[0m
[35;1m`active`[0m tinyint[0m([32;1m1[0m) [37mNOT[0m [37mNULL[0m [37mDEFAULT[0m [34;1m'1'[0m,[0m
PRIMARY KEY (`id_alias`),
UNIQUE KEY `alias` (`alias`)
) ENGINE = ENGINE_TYPE DEFAULT CHARSET = utf8
---
CREATE TABLE `PREFIX_carrier` (
[35;1m`id_carrier`[0m int[0m([32;1m10[0m) [37munsigned[0m [37mNOT[0m [37mNULL[0m [37mAUTO_INCREMENT[0m,[0m
[35;1m`id_reference`[0m int[0m([32;1m10[0m) [37munsigned[0m [37mNOT[0m [37mNULL[0m,[0m
[35;1m`id_tax_rules_group`[0m int[0m([32;1m10[0m) [37munsigned[0m [37mDEFAULT[0m [34;1m'0'[0m,[0m
[35;1m`id_carrier`[0m int[0m([32;1m10[0m) [37mUNSIGNED[0m [37mNOT[0m [37mNULL[0m [37mAUTO_INCREMENT[0m,[0m
[35;1m`id_reference`[0m int[0m([32;1m10[0m) [37mUNSIGNED[0m [37mNOT[0m [37mNULL[0m,[0m
[35;1m`id_tax_rules_group`[0m int[0m([32;1m10[0m) [37mUNSIGNED[0m [37mDEFAULT[0m [34;1m'0'[0m,[0m
`name` varchar(64) NOT NULL,
`url` varchar(255) DEFAULT NULL,
[35;1m`active`[0m tinyint[0m([32;1m1[0m) [37munsigned[0m [37mNOT[0m [37mNULL[0m [37mDEFAULT[0m [34;1m'0'[0m,[0m
[35;1m`deleted`[0m tinyint[0m([32;1m1[0m) [37munsigned[0m [37mNOT[0m [37mNULL[0m [37mDEFAULT[0m [34;1m'0'[0m,[0m
[35;1m`shipping_handling`[0m tinyint[0m([32;1m1[0m) [37munsigned[0m [37mNOT[0m [37mNULL[0m [37mDEFAULT[0m [34;1m'1'[0m,[0m
[35;1m`range_behavior`[0m tinyint[0m([32;1m1[0m) [37munsigned[0m [37mNOT[0m [37mNULL[0m [37mDEFAULT[0m [34;1m'0'[0m,[0m
[35;1m`is_module`[0m tinyint[0m([32;1m1[0m) [37munsigned[0m [37mNOT[0m [37mNULL[0m [37mDEFAULT[0m [34;1m'0'[0m,[0m
[35;1m`is_free`[0m tinyint[0m([32;1m1[0m) [37munsigned[0m [37mNOT[0m [37mNULL[0m [37mDEFAULT[0m [34;1m'0'[0m,[0m
[35;1m`shipping_external`[0m tinyint[0m([32;1m1[0m) [37munsigned[0m [37mNOT[0m [37mNULL[0m [37mDEFAULT[0m [34;1m'0'[0m,[0m
[35;1m`need_range`[0m tinyint[0m([32;1m1[0m) [37munsigned[0m [37mNOT[0m [37mNULL[0m [37mDEFAULT[0m [34;1m'0'[0m,[0m
[35;1m`active`[0m tinyint[0m([32;1m1[0m) [37mUNSIGNED[0m [37mNOT[0m [37mNULL[0m [37mDEFAULT[0m [34;1m'0'[0m,[0m
[35;1m`deleted`[0m tinyint[0m([32;1m1[0m) [37mUNSIGNED[0m [37mNOT[0m [37mNULL[0m [37mDEFAULT[0m [34;1m'0'[0m,[0m
[35;1m`shipping_handling`[0m tinyint[0m([32;1m1[0m) [37mUNSIGNED[0m [37mNOT[0m [37mNULL[0m [37mDEFAULT[0m [34;1m'1'[0m,[0m
[35;1m`range_behavior`[0m tinyint[0m([32;1m1[0m) [37mUNSIGNED[0m [37mNOT[0m [37mNULL[0m [37mDEFAULT[0m [34;1m'0'[0m,[0m
[35;1m`is_module`[0m tinyint[0m([32;1m1[0m) [37mUNSIGNED[0m [37mNOT[0m [37mNULL[0m [37mDEFAULT[0m [34;1m'0'[0m,[0m
[35;1m`is_free`[0m tinyint[0m([32;1m1[0m) [37mUNSIGNED[0m [37mNOT[0m [37mNULL[0m [37mDEFAULT[0m [34;1m'0'[0m,[0m
[35;1m`shipping_external`[0m tinyint[0m([32;1m1[0m) [37mUNSIGNED[0m [37mNOT[0m [37mNULL[0m [37mDEFAULT[0m [34;1m'0'[0m,[0m
[35;1m`need_range`[0m tinyint[0m([32;1m1[0m) [37mUNSIGNED[0m [37mNOT[0m [37mNULL[0m [37mDEFAULT[0m [34;1m'0'[0m,[0m
`external_module_name` varchar(64) DEFAULT NULL,
`shipping_method` int(2) NOT NULL DEFAULT '0',
[35;1m`position`[0m int[0m([32;1m10[0m) [37munsigned[0m [37mNOT[0m [37mNULL[0m [37mdefault[0m [34;1m'0'[0m,[0m
[35;1m`position`[0m int[0m([32;1m10[0m) [37mUNSIGNED[0m [37mNOT[0m [37mNULL[0m [37mDEFAULT[0m [34;1m'0'[0m,[0m
`max_width` int(10) DEFAULT 0,
`max_height` int(10) DEFAULT 0,
`max_depth` int(10) DEFAULT 0,
Expand All @@ -114,13 +114,13 @@
) ENGINE = ENGINE_TYPE DEFAULT CHARSET = utf8
---
CREATE TABLE IF NOT EXISTS `PREFIX_specific_price_rule` (
[35;1m`id_specific_price_rule`[0m int[0m([32;1m10[0m) [37munsigned[0m [37mNOT[0m [37mNULL[0m [37mAUTO_INCREMENT[0m,[0m
[35;1m`id_specific_price_rule`[0m int[0m([32;1m10[0m) [37mUNSIGNED[0m [37mNOT[0m [37mNULL[0m [37mAUTO_INCREMENT[0m,[0m
`name` VARCHAR(255) NOT NULL,
[35;1m`id_shop`[0m int[0m([32;1m11[0m) [37munsigned[0m [37mNOT[0m [37mNULL[0m [37mDEFAULT[0m [34;1m'1'[0m,[0m
[35;1m`id_currency`[0m int[0m([32;1m10[0m) [37munsigned[0m [37mNOT[0m [37mNULL[0m,[0m
[35;1m`id_country`[0m int[0m([32;1m10[0m) [37munsigned[0m [37mNOT[0m [37mNULL[0m,[0m
[35;1m`id_group`[0m int[0m([32;1m10[0m) [37munsigned[0m [37mNOT[0m [37mNULL[0m,[0m
[35;1m`from_quantity`[0m mediumint[0m([32;1m8[0m) [37munsigned[0m [37mNOT[0m [37mNULL[0m,[0m
[35;1m`id_shop`[0m int[0m([32;1m11[0m) [37mUNSIGNED[0m [37mNOT[0m [37mNULL[0m [37mDEFAULT[0m [34;1m'1'[0m,[0m
[35;1m`id_currency`[0m int[0m([32;1m10[0m) [37mUNSIGNED[0m [37mNOT[0m [37mNULL[0m,[0m
[35;1m`id_country`[0m int[0m([32;1m10[0m) [37mUNSIGNED[0m [37mNOT[0m [37mNULL[0m,[0m
[35;1m`id_group`[0m int[0m([32;1m10[0m) [37mUNSIGNED[0m [37mNOT[0m [37mNULL[0m,[0m
[35;1m`from_quantity`[0m mediumint[0m([32;1m8[0m) [37mUNSIGNED[0m [37mNOT[0m [37mNULL[0m,[0m
`price` DECIMAL(20, 6),
`reduction` decimal(20, 6) NOT NULL,
`reduction_type` enum('amount', 'percentage') NOT NULL,
Expand Down Expand Up @@ -454,7 +454,7 @@
ALTER TABLE
`PREFIX_employee`
ADD
[35;1m`bo_color`[0m varchar[0m([32;1m32[0m) [37mdefault[0m [37mNULL[0m [37mAFTER[0m [35;1m`stats_date_to`[0m
[35;1m`bo_color`[0m varchar[0m([32;1m32[0m) [37mDEFAULT[0m [37mNULL[0m [37mAFTER[0m [35;1m`stats_date_to`[0m
---
INSERT INTO `PREFIX_cms_category_lang`
VALUES
Expand Down Expand Up @@ -779,16 +779,16 @@
2,
3
WHERE
a[0m [37min[0m ([32;1m1[0m,[0m [32;1m2[0m,[0m [32;1m3[0m,[0m [32;1m4[0m,[0m [32;1m5[0m)
[37mand[0m b[0m =[0m [32;1m5[0m;[0m
a[0m [37mIN[0m ([32;1m1[0m,[0m [32;1m2[0m,[0m [32;1m3[0m,[0m [32;1m4[0m,[0m [32;1m5[0m)
[37mAND[0m b[0m =[0m [32;1m5[0m;[0m
---
SELECT
count[0m -[0m [32;1m50[0m
[35;1m`count`[0m -[0m [32;1m50[0m
WHERE
a - 50 = b
WHERE
1
[37mand[0m -[0m[32;1m50[0m
[37mAND[0m -[0m[32;1m50[0m
WHERE
-50 = a
WHERE
Expand All @@ -799,11 +799,11 @@
-50
WHERE
1
[37mand[0m -[0m[32;1m50[0m;[0m
[37mAND[0m -[0m[32;1m50[0m;[0m
---
SELECT
@
[37mand[0m b[0m;[0m
[37mAND[0m b[0m;[0m
---
SELECT
@"weird variable name";
Expand All @@ -823,15 +823,15 @@
a
FROM
b
[37mLEFT OUTER JOIN[0m c[0m [37mon[0m (d[0m =[0m f[0m);[0m
[37mLEFT OUTER JOIN[0m c[0m [37mON[0m (d[0m =[0m f[0m);[0m
---
WITH
cte AS (
SELECT
a,
b
FROM
[37mtable[0m
[35;1m`table`[0m
),
RECURSIVE fibonacci (n, fib_n, next_fib_n) AS (
SELECT
Expand Down
Loading

0 comments on commit a321d11

Please sign in to comment.