From 3060cf58eb3234139a8f44a9551a5c2fd8e855dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Kr=C3=B6g?= Date: Wed, 6 Nov 2024 22:57:47 +0100 Subject: [PATCH] Fix lexing /** comment start MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maximilian Krög --- src/Lexer.php | 2 +- tests/data/lexer/lexEmptyCStyleComment.out | 101 ++------------------- 2 files changed, 11 insertions(+), 92 deletions(-) diff --git a/src/Lexer.php b/src/Lexer.php index 5a051a28..782dda66 100644 --- a/src/Lexer.php +++ b/src/Lexer.php @@ -677,7 +677,7 @@ public function parseComment() // - "SELECT */* comment */ FROM ..." // - "SELECT 2*/* comment */3 AS `six`;" $next = $this->last + 1; - if (($next < $this->len) && $this->str[$next] === '*') { + if (($next < $this->len) && $this->str[$next] === '*' && $token === '*/') { // Conflict in "*/*": first "*" was not for ending a comment. // Stop here and let other parsing method define the true behavior of that first star. $this->last = $iBak; diff --git a/tests/data/lexer/lexEmptyCStyleComment.out b/tests/data/lexer/lexEmptyCStyleComment.out index f970fe6a..09a95d1f 100644 --- a/tests/data/lexer/lexEmptyCStyleComment.out +++ b/tests/data/lexer/lexEmptyCStyleComment.out @@ -28,30 +28,12 @@ }, { "@type": "PhpMyAdmin\\SqlParser\\Token", - "token": "/", - "value": "/", - "keyword": null, - "type": 2, - "flags": 1, - "position": 7 - }, - { - "@type": "PhpMyAdmin\\SqlParser\\Token", - "token": "*", - "value": "*", - "keyword": null, - "type": 2, - "flags": 1, - "position": 8 - }, - { - "@type": "PhpMyAdmin\\SqlParser\\Token", - "token": "*/", - "value": "*/", + "token": "/**/", + "value": "/**/", "keyword": null, "type": 4, "flags": 2, - "position": 9 + "position": 7 }, { "@type": "PhpMyAdmin\\SqlParser\\Token", @@ -154,39 +136,12 @@ }, { "@type": "PhpMyAdmin\\SqlParser\\Token", - "token": "/", - "value": "/", - "keyword": null, - "type": 2, - "flags": 1, - "position": 36 - }, - { - "@type": "PhpMyAdmin\\SqlParser\\Token", - "token": "*", - "value": "*", - "keyword": null, - "type": 2, - "flags": 1, - "position": 37 - }, - { - "@type": "PhpMyAdmin\\SqlParser\\Token", - "token": "*", - "value": "*", - "keyword": null, - "type": 2, - "flags": 1, - "position": 38 - }, - { - "@type": "PhpMyAdmin\\SqlParser\\Token", - "token": "*/", - "value": "*/", + "token": "/***/", + "value": "/***/", "keyword": null, "type": 4, "flags": 2, - "position": 39 + "position": 36 }, { "@type": "PhpMyAdmin\\SqlParser\\Token", @@ -235,48 +190,12 @@ }, { "@type": "PhpMyAdmin\\SqlParser\\Token", - "token": "/", - "value": "/", - "keyword": null, - "type": 2, - "flags": 1, - "position": 51 - }, - { - "@type": "PhpMyAdmin\\SqlParser\\Token", - "token": "*", - "value": "*", - "keyword": null, - "type": 2, - "flags": 1, - "position": 52 - }, - { - "@type": "PhpMyAdmin\\SqlParser\\Token", - "token": "*", - "value": "*", - "keyword": null, - "type": 2, - "flags": 1, - "position": 53 - }, - { - "@type": "PhpMyAdmin\\SqlParser\\Token", - "token": " ", - "value": " ", - "keyword": null, - "type": 3, - "flags": 0, - "position": 54 - }, - { - "@type": "PhpMyAdmin\\SqlParser\\Token", - "token": "*/", - "value": "*/", + "token": "/** */", + "value": "/** */", "keyword": null, "type": 4, "flags": 2, - "position": 55 + "position": 51 }, { "@type": "PhpMyAdmin\\SqlParser\\Token", @@ -369,7 +288,7 @@ "position": null } ], - "count": 40, + "count": 31, "idx": 0 }, "delimiter": ";",