diff --git a/src/PHPSQLParser/lexer/PHPSQLLexer.php b/src/PHPSQLParser/lexer/PHPSQLLexer.php index ceef9b45..a211851c 100644 --- a/src/PHPSQLParser/lexer/PHPSQLLexer.php +++ b/src/PHPSQLParser/lexer/PHPSQLLexer.php @@ -87,11 +87,11 @@ public function split($sql) { $tokens = preg_split($this->splitters->getSplittersRegexPattern(), $sql, null, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); + $tokens = $this->concatComments($tokens); $tokens = $this->concatEscapeSequences($tokens); $tokens = $this->balanceBackticks($tokens); $tokens = $this->concatColReferences($tokens); $tokens = $this->balanceParenthesis($tokens); - $tokens = $this->concatComments($tokens); $tokens = $this->concatUserDefinedVariables($tokens); $tokens = $this->concatScientificNotations($tokens); $tokens = $this->concatNegativeNumbers($tokens); @@ -240,6 +240,11 @@ protected function concatComments($tokens) { $inline = true; } + if (($comment === false) && (substr($token, 0, 1) === "#")) { + $comment = $i; + $inline = true; + } + if (($comment === false) && ($token === "/*")) { $comment = $i; $inline = false; diff --git a/tests/cases/parser/issue233Test.php b/tests/cases/parser/issue233Test.php new file mode 100644 index 00000000..f82c0867 --- /dev/null +++ b/tests/cases/parser/issue233Test.php @@ -0,0 +1,21 @@ +parsed; + $expected = getExpectedValue(dirname(__FILE__), 'issue233.serialized'); + $this->assertEquals($expected, $p, 'comment with single quote'); + } +} + diff --git a/tests/expected/parser/issue233.serialized b/tests/expected/parser/issue233.serialized new file mode 100644 index 00000000..f9f19702 --- /dev/null +++ b/tests/expected/parser/issue233.serialized @@ -0,0 +1 @@ +a:2:{s:6:"CREATE";a:4:{s:9:"expr_type";s:5:"table";s:10:"not-exists";b:0;s:9:"base_expr";s:5:"TABLE";s:8:"sub_tree";a:1:{i:0;a:2:{s:9:"expr_type";s:8:"reserved";s:9:"base_expr";s:5:"TABLE";}}}s:5:"TABLE";a:5:{s:9:"base_expr";s:6:"moomoo";s:4:"name";s:6:"moomoo";s:9:"no_quotes";a:2:{s:5:"delim";b:0;s:5:"parts";a:1:{i:0;s:6:"moomoo";}}s:10:"create-def";a:3:{s:9:"expr_type";s:18:"bracket_expression";s:9:"base_expr";s:18:" (cow VARCHAR(20))";s:8:"sub_tree";a:1:{i:0;a:3:{s:9:"expr_type";s:10:"column-def";s:9:"base_expr";s:15:"cow VARCHAR(20)";s:8:"sub_tree";a:2:{i:0;a:3:{s:9:"expr_type";s:6:"colref";s:9:"base_expr";s:3:"cow";s:9:"no_quotes";a:2:{s:5:"delim";b:0;s:5:"parts";a:1:{i:0;s:3:"cow";}}}i:1;a:7:{s:9:"expr_type";s:11:"column-type";s:9:"base_expr";s:11:"VARCHAR(20)";s:8:"sub_tree";a:2:{i:0;a:3:{s:9:"expr_type";s:9:"data-type";s:9:"base_expr";s:7:"VARCHAR";s:6:"length";s:2:"20";}i:1;a:3:{s:9:"expr_type";s:18:"bracket_expression";s:9:"base_expr";s:4:"(20)";s:8:"sub_tree";a:1:{i:0;a:2:{s:9:"expr_type";s:5:"const";s:9:"base_expr";s:2:"20";}}}}s:6:"unique";b:0;s:8:"nullable";b:1;s:8:"auto_inc";b:0;s:7:"primary";b:0;}}}}}s:7:"options";b:0;}} \ No newline at end of file