Skip to content

Commit 8090cb1

Browse files
sinriwilliamdes
authored andcommitted
Fix #156 - Parser mistakes with comments
1 parent 741014d commit 8090cb1

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

src/Components/Expression.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ public function __construct($database = null, $table = null, $column = null, $al
154154
* @param array $options parameters for parsing
155155
*
156156
* @return Expression|null
157+
* @throws \PhpMyAdmin\SqlParser\Exceptions\ParserException
157158
*/
158159
public static function parse(Parser $parser, TokensList $list, array $options = array())
159160
{

src/Components/ExpressionArray.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class ExpressionArray extends Component
2626
* @param array $options parameters for parsing
2727
*
2828
* @return Expression[]
29+
* @throws \PhpMyAdmin\SqlParser\Exceptions\ParserException
2930
*/
3031
public static function parse(Parser $parser, TokensList $list, array $options = array())
3132
{
@@ -106,12 +107,21 @@ public static function parse(Parser $parser, TokensList $list, array $options =
106107

107108
--$list->idx;
108109

110+
// TODO verify #156 Hotfix
111+
if (is_array($ret)) {
112+
$expr = $ret[count($ret) - 1]->expr;
113+
if (preg_match('/\s*--\s.*$/', $expr, $matches)) {
114+
$found = $matches[0];
115+
$ret[count($ret) - 1]->expr = substr($expr, 0, strlen($expr) - strlen($found));
116+
}
117+
}
118+
109119
return $ret;
110120
}
111121

112122
/**
113-
* @param ExpressionArray[] $component the component to be built
114-
* @param array $options parameters for building
123+
* @param Expression[] $component the component to be built
124+
* @param array $options parameters for building
115125
*
116126
* @return string
117127
*/

src/Parser.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ public function __construct($list = null, $strict = false)
379379

380380
/**
381381
* Builds the parse trees.
382+
* @throws ParserException
382383
*/
383384
public function parse()
384385
{

src/Statement.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ public function build()
193193
*
194194
* @param Parser $parser the instance that requests parsing
195195
* @param TokensList $list the list of tokens to be parsed
196+
* @throws Exceptions\ParserException
196197
*/
197198
public function parse(Parser $parser, TokensList $list)
198199
{
@@ -472,6 +473,7 @@ public function __toString()
472473
* @param TokensList $list the list of tokens to be parsed
473474
*
474475
* @return bool
476+
* @throws Exceptions\ParserException
475477
*/
476478
public function validateClauseOrder($parser, $list)
477479
{

0 commit comments

Comments
 (0)