Skip to content

Commit

Permalink
Merge pull request #61 from MaximilianKresse/fix/formatting
Browse files Browse the repository at this point in the history
Fixed formatting of MODIFY and CHANGE
  • Loading branch information
greg0ire authored Jul 30, 2020
2 parents 5514662 + 96221ff commit 56070be
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 29 deletions.
5 changes: 3 additions & 2 deletions src/Tokenizer.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ final class Tokenizer
private $reserved = [
'ACCESSIBLE',
'ACTION',
'AFTER',
'AGAINST',
'AGGREGATE',
'ALGORITHM',
Expand Down Expand Up @@ -174,7 +175,6 @@ final class Tokenizer
'MINUTE_SECOND',
'MIN_ROWS',
'MODE',
'MODIFY',
'MONTH',
'MRG_MYISAM',
'MYISAM',
Expand Down Expand Up @@ -319,7 +319,8 @@ final class Tokenizer
'UPDATE',
'HAVING',
'ADD',
'AFTER',
'CHANGE',
'MODIFY',
'ALTER TABLE',
'DELETE FROM',
'UNION ALL',
Expand Down
22 changes: 13 additions & 9 deletions tests/clihighlight.html
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -454,9 +454,7 @@
ALTER TABLE
`PREFIX_employee`
ADD
`bo_color` varchar(32) default NULL
AFTER
`stats_date_to`
`bo_color` varchar(32) default NULL AFTER `stats_date_to`
---
INSERT INTO `PREFIX_cms_category_lang`
VALUES
Expand All @@ -477,16 +475,12 @@
ALTER TABLE
`PREFIX_customer`
ADD
`note` text
AFTER
`secure_key`
`note` text AFTER `secure_key`
---
ALTER TABLE
`PREFIX_contact`
ADD
`customer_service` tinyint(1) NOT NULL DEFAULT 0
AFTER
`email`
`customer_service` tinyint(1) NOT NULL DEFAULT 0 AFTER `email`
---
INSERT INTO `PREFIX_specific_price` (
`id_product`, `id_shop`, `id_currency`,
Expand Down Expand Up @@ -757,6 +751,16 @@
(SomeOtherColumn = 2);
WARNING: unclosed parentheses or section
---
ALTER TABLE
`test_modify`
MODIFY
`id` INT(11) UNSIGNED NOT NULL;
---
ALTER TABLE
`test_change`
CHANGE
`id` `_id` BIGINT(20) UNSIGNED NULL;
---
SELECT
*
LIMIT
Expand Down
4 changes: 4 additions & 0 deletions tests/compress.html
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@
---
SELECT Test FROM Test WHERE ( MyColumn = 1 )) AND ((( SomeOtherColumn = 2);
---
ALTER TABLE `test_modify` MODIFY `id` INT(11) UNSIGNED NOT NULL;
---
ALTER TABLE `test_change` CHANGE `id` `_id` BIGINT(20) UNSIGNED NULL;
---
SELECT * LIMIT 1; SELECT a,b,c,d FROM e LIMIT 1, 2; SELECT 1,2,3 WHERE a in (1,2,3,4,5) and b=5;
---
SELECT count - 50 WHERE a-50 = b WHERE 1 and - 50 WHERE -50 = a WHERE a = -50 WHERE 1 - 50 WHERE 1 and -50;
Expand Down
22 changes: 13 additions & 9 deletions tests/format-highlight.html
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -454,9 +454,7 @@
<pre style="color: black; background-color: white;"><span style="font-weight:bold;">ALTER TABLE</span>
<span style="color: purple;">`PREFIX_employee`</span>
<span style="font-weight:bold;">ADD</span>
<span style="color: purple;">`bo_color`</span> <span style="color: #333;">varchar</span>(<span style="color: green;">32</span>) <span style="font-weight:bold;">default</span> <span style="font-weight:bold;">NULL</span>
<span style="font-weight:bold;">AFTER</span>
<span style="color: purple;">`stats_date_to`</span></pre>
<span style="color: purple;">`bo_color`</span> <span style="color: #333;">varchar</span>(<span style="color: green;">32</span>) <span style="font-weight:bold;">default</span> <span style="font-weight:bold;">NULL</span> <span style="font-weight:bold;">AFTER</span> <span style="color: purple;">`stats_date_to`</span></pre>
---
<pre style="color: black; background-color: white;"><span style="font-weight:bold;">INSERT</span> <span style="font-weight:bold;">INTO</span> <span style="color: purple;">`PREFIX_cms_category_lang`</span>
<span style="font-weight:bold;">VALUES</span>
Expand All @@ -477,16 +475,12 @@
<pre style="color: black; background-color: white;"><span style="font-weight:bold;">ALTER TABLE</span>
<span style="color: purple;">`PREFIX_customer`</span>
<span style="font-weight:bold;">ADD</span>
<span style="color: purple;">`note`</span> <span style="color: #333;">text</span>
<span style="font-weight:bold;">AFTER</span>
<span style="color: purple;">`secure_key`</span></pre>
<span style="color: purple;">`note`</span> <span style="color: #333;">text</span> <span style="font-weight:bold;">AFTER</span> <span style="color: purple;">`secure_key`</span></pre>
---
<pre style="color: black; background-color: white;"><span style="font-weight:bold;">ALTER TABLE</span>
<span style="color: purple;">`PREFIX_contact`</span>
<span style="font-weight:bold;">ADD</span>
<span style="color: purple;">`customer_service`</span> <span style="color: #333;">tinyint</span>(<span style="color: green;">1</span>) <span style="font-weight:bold;">NOT</span> <span style="font-weight:bold;">NULL</span> <span style="font-weight:bold;">DEFAULT</span> <span style="color: green;">0</span>
<span style="font-weight:bold;">AFTER</span>
<span style="color: purple;">`email`</span></pre>
<span style="color: purple;">`customer_service`</span> <span style="color: #333;">tinyint</span>(<span style="color: green;">1</span>) <span style="font-weight:bold;">NOT</span> <span style="font-weight:bold;">NULL</span> <span style="font-weight:bold;">DEFAULT</span> <span style="color: green;">0</span> <span style="font-weight:bold;">AFTER</span> <span style="color: purple;">`email`</span></pre>
---
<pre style="color: black; background-color: white;"><span style="font-weight:bold;">INSERT</span> <span style="font-weight:bold;">INTO</span> <span style="color: purple;">`PREFIX_specific_price`</span> (
<span style="color: purple;">`id_product`</span><span >,</span> <span style="color: purple;">`id_shop`</span><span >,</span> <span style="color: purple;">`id_currency`</span><span >,</span>
Expand Down Expand Up @@ -757,6 +751,16 @@
(<span style="color: #333;">SomeOtherColumn</span> <span >=</span> <span style="color: green;">2</span>)<span >;</span>
<span style="background-color: red;">WARNING: unclosed parentheses or section</span></pre>
---
<pre style="color: black; background-color: white;"><span style="font-weight:bold;">ALTER TABLE</span>
<span style="color: purple;">`test_modify`</span>
<span style="font-weight:bold;">MODIFY</span>
<span style="color: purple;">`id`</span> <span style="color: #333;">INT</span>(<span style="color: green;">11</span>) <span style="font-weight:bold;">UNSIGNED</span> <span style="font-weight:bold;">NOT</span> <span style="font-weight:bold;">NULL</span><span >;</span></pre>
---
<pre style="color: black; background-color: white;"><span style="font-weight:bold;">ALTER TABLE</span>
<span style="color: purple;">`test_change`</span>
<span style="font-weight:bold;">CHANGE</span>
<span style="color: purple;">`id`</span> <span style="color: purple;">`_id`</span> <span style="color: #333;">BIGINT</span>(<span style="color: green;">20</span>) <span style="font-weight:bold;">UNSIGNED</span> <span style="font-weight:bold;">NULL</span><span >;</span></pre>
---
<pre style="color: black; background-color: white;"><span style="font-weight:bold;">SELECT</span>
<span >*</span>
<span style="font-weight:bold;">LIMIT</span>
Expand Down
22 changes: 13 additions & 9 deletions tests/format.html
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -454,9 +454,7 @@
ALTER TABLE
`PREFIX_employee`
ADD
`bo_color` varchar(32) default NULL
AFTER
`stats_date_to`
`bo_color` varchar(32) default NULL AFTER `stats_date_to`
---
INSERT INTO `PREFIX_cms_category_lang`
VALUES
Expand All @@ -477,16 +475,12 @@
ALTER TABLE
`PREFIX_customer`
ADD
`note` text
AFTER
`secure_key`
`note` text AFTER `secure_key`
---
ALTER TABLE
`PREFIX_contact`
ADD
`customer_service` tinyint(1) NOT NULL DEFAULT 0
AFTER
`email`
`customer_service` tinyint(1) NOT NULL DEFAULT 0 AFTER `email`
---
INSERT INTO `PREFIX_specific_price` (
`id_product`, `id_shop`, `id_currency`,
Expand Down Expand Up @@ -755,6 +749,16 @@
(
(SomeOtherColumn = 2); WARNING: unclosed parentheses or section
---
ALTER TABLE
`test_modify`
MODIFY
`id` INT(11) UNSIGNED NOT NULL;
---
ALTER TABLE
`test_change`
CHANGE
`id` `_id` BIGINT(20) UNSIGNED NULL;
---
SELECT
*
LIMIT
Expand Down
4 changes: 4 additions & 0 deletions tests/highlight.html
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,10 @@
(
<span style="color: #333;">MyColumn</span> <span >=</span> <span style="color: green;">1</span> )) <span style="font-weight:bold;">AND</span> ((( <span style="color: #333;">SomeOtherColumn</span> <span >=</span> <span style="color: green;">2</span>)<span >;</span></pre>
---
<pre style="color: black; background-color: white;"><span style="font-weight:bold;">ALTER TABLE</span> <span style="color: purple;">`test_modify`</span> <span style="font-weight:bold;">MODIFY</span> <span style="color: purple;">`id`</span> <span style="color: #333;">INT</span>(<span style="color: green;">11</span>) <span style="font-weight:bold;">UNSIGNED</span> <span style="font-weight:bold;">NOT</span> <span style="font-weight:bold;">NULL</span><span >;</span></pre>
---
<pre style="color: black; background-color: white;"><span style="font-weight:bold;">ALTER TABLE</span> <span style="color: purple;">`test_change`</span> <span style="font-weight:bold;">CHANGE</span> <span style="color: purple;">`id`</span> <span style="color: purple;">`_id`</span> <span style="color: #333;">BIGINT</span>(<span style="color: green;">20</span>) <span style="font-weight:bold;">UNSIGNED</span> <span style="font-weight:bold;">NULL</span><span >;</span></pre>
---
<pre style="color: black; background-color: white;"><span style="font-weight:bold;">SELECT</span> <span >*</span> <span style="font-weight:bold;">LIMIT</span> <span style="color: green;">1</span><span >;</span> <span style="font-weight:bold;">SELECT</span> <span style="color: #333;">a</span><span >,</span><span style="color: #333;">b</span><span >,</span><span style="color: #333;">c</span><span >,</span><span style="color: #333;">d</span> <span style="font-weight:bold;">FROM</span> <span style="color: #333;">e</span> <span style="font-weight:bold;">LIMIT</span> <span style="color: green;">1</span><span >,</span> <span style="color: green;">2</span><span >;</span> <span style="font-weight:bold;">SELECT</span> <span style="color: green;">1</span><span >,</span><span style="color: green;">2</span><span >,</span><span style="color: green;">3</span> <span style="font-weight:bold;">WHERE</span> <span style="color: #333;">a</span> <span style="font-weight:bold;">in</span> (<span style="color: green;">1</span><span >,</span><span style="color: green;">2</span><span >,</span><span style="color: green;">3</span><span >,</span><span style="color: green;">4</span><span >,</span><span style="color: green;">5</span>) <span style="font-weight:bold;">and</span> <span style="color: #333;">b</span><span >=</span><span style="color: green;">5</span><span >;</span></pre>
---
<pre style="color: black; background-color: white;"><span style="font-weight:bold;">SELECT</span> <span style="color: #333;">count</span> <span >-</span> <span style="color: green;">50</span>
Expand Down
4 changes: 4 additions & 0 deletions tests/sql.sql
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,10 @@ SELECT Test FROM Test WHERE
(
MyColumn = 1 )) AND ((( SomeOtherColumn = 2);
---
ALTER TABLE `test_modify` MODIFY `id` INT(11) UNSIGNED NOT NULL;
---
ALTER TABLE `test_change` CHANGE `id` `_id` BIGINT(20) UNSIGNED NULL;
---
SELECT * LIMIT 1; SELECT a,b,c,d FROM e LIMIT 1, 2; SELECT 1,2,3 WHERE a in (1,2,3,4,5) and b=5;
---
SELECT count - 50
Expand Down

0 comments on commit 56070be

Please sign in to comment.