Skip to content

Commit 61cee30

Browse files
committed
don't treat CR/LF as part of line-comments after all
1 parent 3fd27ac commit 61cee30

2 files changed

Lines changed: 12 additions & 12 deletions

File tree

src/SQLTokenizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ protected function token()
144144
protected function comment()
145145
{
146146
if ($start = $this->consume('--')) {
147-
$comment = $this->consume(".*?(\n|\r\n|\$)");
147+
$comment = $this->consume("[^\r\n]*");
148148

149149
return "{$start}{$comment}";
150150
}

test/test.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function () {
4242
test(
4343
'comments',
4444
function () {
45-
eq(SQLTokenizer::tokenize("-- one\nSELECT -- two\n1; -- three\n-- four"), [["-- one\n", "SELECT", " ", "-- two\n", "1"], ["-- three\n", "-- four"]]);
45+
eq(SQLTokenizer::tokenize("-- one\nSELECT -- two\n1; -- three\n-- four"), [["-- one", "\n", "SELECT", " ", "-- two", "\n", "1"], ["-- three", "\n", "-- four"]]);
4646
eq(SQLTokenizer::tokenize("/* one\ntwo */\nSELECT 1;/* three\nfour */\nSELECT 2;"), [["/* one\ntwo */", "\n", "SELECT", " ", "1"], ["/* three\nfour */", "\n", "SELECT", " ", "2"]]);
4747
}
4848
);
@@ -51,8 +51,7 @@ function () {
5151
'split statements',
5252
function () {
5353
eq(SQLSplitter::split("SELECT 1; SELECT 2;"), ["SELECT 1", "SELECT 2"]);
54-
eq(SQLSplitter::split("-- one\nSELECT -- two\n1; -- three\n-- four"), ["SELECT 1"]);
55-
eq(SQLSplitter::split("-- one\r\nSELECT -- two\r\n1; -- three\r\n-- four\r\n"), ["SELECT 1"]);
54+
eq(SQLSplitter::split("-- one\nSELECT -- two\n1; -- three\n-- four"), ["SELECT \n1"]);
5655
eq(SQLSplitter::split("-- one\nSELECT -- two\n1; -- three\n-- four", false), ["-- one\nSELECT -- two\n1", "-- three\n-- four"]);
5756
eq(SQLSplitter::split("/* one\ntwo */\nSELECT 1;/* three\nfour */\nSELECT 2;"), ["SELECT 1", "SELECT 2"]);
5857
eq(SQLSplitter::split("/* one\ntwo */\nSELECT 1;\n/* three\nfour */\nSELECT 2;", false), ["/* one\ntwo */\nSELECT 1", "/* three\nfour */\nSELECT 2"]);
@@ -223,10 +222,11 @@ function (string $sql) {
223222
DELIMITER $$
224223
225224
CREATE PROCEDURE dorepeat(p1 INT)
226-
BEGIN
227-
SET @x = 0; -- comment
228-
REPEAT SET @x = @x + 1; UNTIL @x > p1 END REPEAT;
229-
END $$
225+
BEGIN
226+
SET @x = 0;-- comment
227+
REPEAT SET @x = @x + 1; UNTIL @x > p1 END REPEAT;
228+
END
229+
$$
230230
231231
DELIMITER ;
232232
-- comment
@@ -236,10 +236,10 @@ function (string $sql) {
236236

237237
$mysql_statements = <<<SQL
238238
CREATE PROCEDURE dorepeat(p1 INT)
239-
BEGIN
240-
SET @x = 0;
241-
REPEAT SET @x = @x + 1; UNTIL @x > p1 END REPEAT;
242-
END
239+
BEGIN
240+
SET @x = 0;
241+
REPEAT SET @x = @x + 1; UNTIL @x > p1 END REPEAT;
242+
END
243243
-----
244244
CALL dorepeat(1000)
245245
-----

0 commit comments

Comments
 (0)