Skip to content

Fix #156 - Parser mistakes with comments #291

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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