From 8090cb10c2ff7e0d2890ef8cea7800205d0d8407 Mon Sep 17 00:00:00 2001 From: Sinri Edogawa Date: Tue, 11 Feb 2020 17:14:02 +0800 Subject: [PATCH] Fix #156 - Parser mistakes with comments --- src/Components/Expression.php | 1 + src/Components/ExpressionArray.php | 14 ++++++++++++-- src/Parser.php | 1 + src/Statement.php | 2 ++ 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/Components/Expression.php b/src/Components/Expression.php index 2cf119b2a..62b9b1c1b 100644 --- a/src/Components/Expression.php +++ b/src/Components/Expression.php @@ -154,6 +154,7 @@ public function __construct($database = null, $table = null, $column = null, $al * @param array $options parameters for parsing * * @return Expression|null + * @throws \PhpMyAdmin\SqlParser\Exceptions\ParserException */ public static function parse(Parser $parser, TokensList $list, array $options = array()) { diff --git a/src/Components/ExpressionArray.php b/src/Components/ExpressionArray.php index cdec66baf..add9e2872 100644 --- a/src/Components/ExpressionArray.php +++ b/src/Components/ExpressionArray.php @@ -26,6 +26,7 @@ class ExpressionArray extends Component * @param array $options parameters for parsing * * @return Expression[] + * @throws \PhpMyAdmin\SqlParser\Exceptions\ParserException */ public static function parse(Parser $parser, TokensList $list, array $options = array()) { @@ -106,12 +107,21 @@ public static function parse(Parser $parser, TokensList $list, array $options = --$list->idx; + // TODO verify #156 Hotfix + if (is_array($ret)) { + $expr = $ret[count($ret) - 1]->expr; + if (preg_match('/\s*--\s.*$/', $expr, $matches)) { + $found = $matches[0]; + $ret[count($ret) - 1]->expr = substr($expr, 0, strlen($expr) - strlen($found)); + } + } + return $ret; } /** - * @param ExpressionArray[] $component the component to be built - * @param array $options parameters for building + * @param Expression[] $component the component to be built + * @param array $options parameters for building * * @return string */ diff --git a/src/Parser.php b/src/Parser.php index ab3e1b773..f09a210d6 100644 --- a/src/Parser.php +++ b/src/Parser.php @@ -379,6 +379,7 @@ public function __construct($list = null, $strict = false) /** * Builds the parse trees. + * @throws ParserException */ public function parse() { diff --git a/src/Statement.php b/src/Statement.php index adadb252c..4b47ea5f8 100644 --- a/src/Statement.php +++ b/src/Statement.php @@ -193,6 +193,7 @@ public function build() * * @param Parser $parser the instance that requests parsing * @param TokensList $list the list of tokens to be parsed + * @throws Exceptions\ParserException */ public function parse(Parser $parser, TokensList $list) { @@ -472,6 +473,7 @@ public function __toString() * @param TokensList $list the list of tokens to be parsed * * @return bool + * @throws Exceptions\ParserException */ public function validateClauseOrder($parser, $list) {