Skip to content

Commit a98a55e

Browse files
authored
Merge pull request #104 from mvorisek/revert_upper
Revert uppercasing keywords in tokenizer
2 parents 9d5c0e0 + 339ea6b commit a98a55e

7 files changed

+205
-206
lines changed

src/Tokenizer.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,7 @@ private function createNextToken(string $string, Token|null $previous = null): T
898898
) {
899899
return new Token(
900900
Token::TOKEN_TYPE_RESERVED_TOPLEVEL,
901-
substr($upper, 0, strlen($matches[1])),
901+
substr($string, 0, strlen($matches[1])),
902902
);
903903
}
904904

@@ -912,7 +912,7 @@ private function createNextToken(string $string, Token|null $previous = null): T
912912
) {
913913
return new Token(
914914
Token::TOKEN_TYPE_RESERVED_NEWLINE,
915-
substr($upper, 0, strlen($matches[1])),
915+
substr($string, 0, strlen($matches[1])),
916916
);
917917
}
918918

@@ -926,7 +926,7 @@ private function createNextToken(string $string, Token|null $previous = null): T
926926
) {
927927
return new Token(
928928
Token::TOKEN_TYPE_RESERVED,
929-
substr($upper, 0, strlen($matches[1])),
929+
substr($string, 0, strlen($matches[1])),
930930
);
931931
}
932932
}
@@ -938,7 +938,7 @@ private function createNextToken(string $string, Token|null $previous = null): T
938938
if (preg_match('/^(' . $this->regexFunction . '[(]|\s|[)])/', $upper, $matches)) {
939939
return new Token(
940940
Token::TOKEN_TYPE_RESERVED,
941-
substr($upper, 0, strlen($matches[1]) - 1),
941+
substr($string, 0, strlen($matches[1]) - 1),
942942
);
943943
}
944944

tests/clihighlight.txt

+47-47
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
SELECT
22
customer_id,
33
customer_name,
4-
COUNT(order_id) AS total
4+
COUNT(order_id) as total
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-
COUNT(order_id) AS total
24+
count(order_id) As total
2525
FROM
2626
orders
2727
GROUP BY
2828
customer_id
29-
) AS ordersummary
29+
) As ordersummary
3030
WHERE
3131
customers.customer_id = ordersummary.customer_id
3232
---
@@ -44,30 +44,30 @@
4444
NAMES 'utf8';
4545
---
4646
CREATE TABLE `PREFIX_address` (
47-
`id_address` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
48-
`id_country` int(10) UNSIGNED NOT NULL,
49-
`id_state` int(10) UNSIGNED DEFAULT NULL,
50-
`id_customer` int(10) UNSIGNED NOT NULL DEFAULT '0',
51-
`id_manufacturer` int(10) UNSIGNED NOT NULL DEFAULT '0',
52-
`id_supplier` int(10) UNSIGNED NOT NULL DEFAULT '0',
53-
`id_warehouse` int(10) UNSIGNED NOT NULL DEFAULT '0',
47+
`id_address` int(10) unsigned NOT NULL auto_increment,
48+
`id_country` int(10) unsigned NOT NULL,
49+
`id_state` int(10) unsigned default NULL,
50+
`id_customer` int(10) unsigned NOT NULL default '0',
51+
`id_manufacturer` int(10) unsigned NOT NULL default '0',
52+
`id_supplier` int(10) unsigned NOT NULL default '0',
53+
`id_warehouse` int(10) unsigned NOT NULL default '0',
5454
`alias` varchar(32) NOT NULL,
55-
`company` varchar(64) DEFAULT NULL,
55+
`company` varchar(64) default NULL,
5656
`lastname` varchar(32) NOT NULL,
5757
`firstname` varchar(32) NOT NULL,
5858
`address1` varchar(128) NOT NULL,
59-
`address2` varchar(128) DEFAULT NULL,
60-
`postcode` varchar(12) DEFAULT NULL,
59+
`address2` varchar(128) default NULL,
60+
`postcode` varchar(12) default NULL,
6161
`city` varchar(64) NOT NULL,
6262
`other` text,
63-
`phone` varchar(16) DEFAULT NULL,
64-
`phone_mobile` varchar(16) DEFAULT NULL,
65-
`vat_number` varchar(32) DEFAULT NULL,
63+
`phone` varchar(16) default NULL,
64+
`phone_mobile` varchar(16) default NULL,
65+
`vat_number` varchar(32) default NULL,
6666
`dni` varchar(16) DEFAULT NULL,
6767
`date_add` datetime NOT NULL,
6868
`date_upd` datetime NOT NULL,
69-
`active` tinyint(1) UNSIGNED NOT NULL DEFAULT '1',
70-
`deleted` tinyint(1) UNSIGNED NOT NULL DEFAULT '0',
69+
`active` tinyint(1) unsigned NOT NULL default '1',
70+
`deleted` tinyint(1) unsigned NOT NULL default '0',
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-
`id_alias` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
81+
`id_alias` int(10) unsigned NOT NULL auto_increment,
8282
`alias` varchar(255) NOT NULL,
8383
`search` varchar(255) NOT NULL,
84-
`active` tinyint(1) NOT NULL DEFAULT '1',
84+
`active` tinyint(1) NOT NULL default '1',
8585
PRIMARY KEY (`id_alias`),
8686
UNIQUE KEY `alias` (`alias`)
8787
) ENGINE = ENGINE_TYPE DEFAULT CHARSET = utf8
8888
---
8989
CREATE TABLE `PREFIX_carrier` (
90-
`id_carrier` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
91-
`id_reference` int(10) UNSIGNED NOT NULL,
92-
`id_tax_rules_group` int(10) UNSIGNED DEFAULT '0',
90+
`id_carrier` int(10) unsigned NOT NULL AUTO_INCREMENT,
91+
`id_reference` int(10) unsigned NOT NULL,
92+
`id_tax_rules_group` int(10) unsigned DEFAULT '0',
9393
`name` varchar(64) NOT NULL,
9494
`url` varchar(255) DEFAULT NULL,
95-
`active` tinyint(1) UNSIGNED NOT NULL DEFAULT '0',
96-
`deleted` tinyint(1) UNSIGNED NOT NULL DEFAULT '0',
97-
`shipping_handling` tinyint(1) UNSIGNED NOT NULL DEFAULT '1',
98-
`range_behavior` tinyint(1) UNSIGNED NOT NULL DEFAULT '0',
99-
`is_module` tinyint(1) UNSIGNED NOT NULL DEFAULT '0',
100-
`is_free` tinyint(1) UNSIGNED NOT NULL DEFAULT '0',
101-
`shipping_external` tinyint(1) UNSIGNED NOT NULL DEFAULT '0',
102-
`need_range` tinyint(1) UNSIGNED NOT NULL DEFAULT '0',
95+
`active` tinyint(1) unsigned NOT NULL DEFAULT '0',
96+
`deleted` tinyint(1) unsigned NOT NULL DEFAULT '0',
97+
`shipping_handling` tinyint(1) unsigned NOT NULL DEFAULT '1',
98+
`range_behavior` tinyint(1) unsigned NOT NULL DEFAULT '0',
99+
`is_module` tinyint(1) unsigned NOT NULL DEFAULT '0',
100+
`is_free` tinyint(1) unsigned NOT NULL DEFAULT '0',
101+
`shipping_external` tinyint(1) unsigned NOT NULL DEFAULT '0',
102+
`need_range` tinyint(1) unsigned NOT NULL DEFAULT '0',
103103
`external_module_name` varchar(64) DEFAULT NULL,
104104
`shipping_method` int(2) NOT NULL DEFAULT '0',
105-
`position` int(10) UNSIGNED NOT NULL DEFAULT '0',
105+
`position` int(10) unsigned NOT NULL default '0',
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-
`id_specific_price_rule` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
117+
`id_specific_price_rule` int(10) unsigned NOT NULL AUTO_INCREMENT,
118118
`name` VARCHAR(255) NOT NULL,
119-
`id_shop` int(11) UNSIGNED NOT NULL DEFAULT '1',
120-
`id_currency` int(10) UNSIGNED NOT NULL,
121-
`id_country` int(10) UNSIGNED NOT NULL,
122-
`id_group` int(10) UNSIGNED NOT NULL,
123-
`from_quantity` mediumint(8) UNSIGNED NOT NULL,
119+
`id_shop` int(11) unsigned NOT NULL DEFAULT '1',
120+
`id_currency` int(10) unsigned NOT NULL,
121+
`id_country` int(10) unsigned NOT NULL,
122+
`id_group` int(10) unsigned NOT NULL,
123+
`from_quantity` mediumint(8) unsigned NOT NULL,
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-
`bo_color` varchar(32) DEFAULT NULL AFTER `stats_date_to`
457+
`bo_color` varchar(32) default NULL AFTER `stats_date_to`
458458
---
459459
INSERT INTO `PREFIX_cms_category_lang`
460460
VALUES
@@ -810,16 +810,16 @@
810810
2,
811811
3
812812
WHERE
813-
a IN (1, 2, 3, 4, 5)
814-
AND b = 5;
813+
a in (1, 2, 3, 4, 5)
814+
and b = 5;
815815
---
816816
SELECT
817-
`count` - 50
817+
count - 50
818818
WHERE
819819
a - 50 = b
820820
WHERE
821821
1
822-
AND -50
822+
and -50
823823
WHERE
824824
-50 = a
825825
WHERE
@@ -830,11 +830,11 @@
830830
-50
831831
WHERE
832832
1
833-
AND -50;
833+
and -50;
834834
---
835835
SELECT
836836
@
837-
AND b;
837+
and b;
838838
---
839839
SELECT
840840
@"weird variable name";
@@ -854,15 +854,15 @@
854854
a
855855
FROM
856856
b
857-
LEFT OUTER JOIN c ON (d = f);
857+
LEFT OUTER JOIN c on (d = f);
858858
---
859859
WITH
860860
cte AS (
861861
SELECT
862862
a,
863863
b
864864
FROM
865-
`table`
865+
table
866866
),
867867
RECURSIVE fibonacci (n, fib_n, next_fib_n) AS (
868868
SELECT

0 commit comments

Comments
 (0)