Skip to content

Commit

Permalink
Fix lexing /** comment start
Browse files Browse the repository at this point in the history
Signed-off-by: Maximilian Krög <[email protected]>
  • Loading branch information
MoonE committed Nov 6, 2024
1 parent 8426c68 commit 3060cf5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 92 deletions.
2 changes: 1 addition & 1 deletion src/Lexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
101 changes: 10 additions & 91 deletions tests/data/lexer/lexEmptyCStyleComment.out
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -369,7 +288,7 @@
"position": null
}
],
"count": 40,
"count": 31,
"idx": 0
},
"delimiter": ";",
Expand Down

0 comments on commit 3060cf5

Please sign in to comment.