Skip to content

Commit

Permalink
Fix #156 - Parser mistakes with comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sinri authored and williamdes committed Mar 20, 2020
1 parent 741014d commit 8090cb1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/Components/Expression.php
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
Expand Down
14 changes: 12 additions & 2 deletions src/Components/ExpressionArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
Expand Down Expand Up @@ -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
*/
Expand Down
1 change: 1 addition & 0 deletions src/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ public function __construct($list = null, $strict = false)

/**
* Builds the parse trees.
* @throws ParserException
*/
public function parse()
{
Expand Down
2 changes: 2 additions & 0 deletions src/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit 8090cb1

Please sign in to comment.