Skip to content

Commit

Permalink
Replace Lexer with TokenType in various functions
Browse files Browse the repository at this point in the history
  • Loading branch information
philippeaellig committed Jun 13, 2024
1 parent 1a60a33 commit e0687da
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 77 deletions.
26 changes: 13 additions & 13 deletions src/Oro/ORM/Query/AST/Functions/Cast.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace Oro\ORM\Query\AST\Functions;

use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\TokenType;

class Cast extends AbstractPlatformAwareFunctionNode
{
Expand Down Expand Up @@ -35,30 +35,30 @@ class Cast extends AbstractPlatformAwareFunctionNode
*/
public function parse(Parser $parser): void
{
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
$parser->match(TokenType::T_IDENTIFIER);
$parser->match(TokenType::T_OPEN_PARENTHESIS);
$this->parameters[self::PARAMETER_KEY] = $parser->ArithmeticExpression();

$parser->match(Lexer::T_AS);
$parser->match(TokenType::T_AS);

$parser->match(Lexer::T_IDENTIFIER);
$lexer = $parser->getLexer();
$parser->match(TokenType::T_IDENTIFIER);
$lexer = $parser->getTokenType();
$type = $lexer->token['value'];

if ($lexer->isNextToken(Lexer::T_OPEN_PARENTHESIS)) {
$parser->match(Lexer::T_OPEN_PARENTHESIS);
if ($lexer->isNextToken(TokenType::T_OPEN_PARENTHESIS)) {
$parser->match(TokenType::T_OPEN_PARENTHESIS);
$parameter = $parser->Literal();
$parameters = [
$parameter->value
];
if ($lexer->isNextToken(Lexer::T_COMMA)) {
while ($lexer->isNextToken(Lexer::T_COMMA)) {
$parser->match(Lexer::T_COMMA);
if ($lexer->isNextToken(TokenType::T_COMMA)) {
while ($lexer->isNextToken(TokenType::T_COMMA)) {
$parser->match(TokenType::T_COMMA);
$parameter = $parser->Literal();
$parameters[] = $parameter->value;
}
}
$parser->match(Lexer::T_CLOSE_PARENTHESIS);
$parser->match(TokenType::T_CLOSE_PARENTHESIS);
$type .= '(' . \implode(', ', $parameters) . ')';
}

Expand All @@ -75,7 +75,7 @@ public function parse(Parser $parser): void

$this->parameters[self::TYPE_KEY] = $type;

$parser->match(Lexer::T_CLOSE_PARENTHESIS);
$parser->match(TokenType::T_CLOSE_PARENTHESIS);
}

protected function isSupportedType(string $type): bool
Expand Down
12 changes: 6 additions & 6 deletions src/Oro/ORM/Query/AST/Functions/DateTime/ConvertTz.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace Oro\ORM\Query\AST\Functions\DateTime;

use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\TokenType;
use Oro\ORM\Query\AST\Functions\AbstractPlatformAwareFunctionNode;

class ConvertTz extends AbstractPlatformAwareFunctionNode
Expand All @@ -18,13 +18,13 @@ class ConvertTz extends AbstractPlatformAwareFunctionNode
*/
public function parse(Parser $parser): void
{
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
$parser->match(TokenType::T_IDENTIFIER);
$parser->match(TokenType::T_OPEN_PARENTHESIS);
$this->parameters[self::VALUE_KEY] = $parser->ArithmeticPrimary();
$parser->match(Lexer::T_COMMA);
$parser->match(TokenType::T_COMMA);
$this->parameters[self::FROM_TZ_KEY] = $parser->ArithmeticPrimary();
$parser->match(Lexer::T_COMMA);
$parser->match(TokenType::T_COMMA);
$this->parameters[self::TO_TZ_KEY] = $parser->ArithmeticPrimary();
$parser->match(Lexer::T_CLOSE_PARENTHESIS);
$parser->match(TokenType::T_CLOSE_PARENTHESIS);
}
}
10 changes: 5 additions & 5 deletions src/Oro/ORM/Query/AST/Functions/Numeric/Pow.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace Oro\ORM\Query\AST\Functions\Numeric;

use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\TokenType;
use Oro\ORM\Query\AST\Functions\AbstractPlatformAwareFunctionNode;

class Pow extends AbstractPlatformAwareFunctionNode
Expand All @@ -17,11 +17,11 @@ class Pow extends AbstractPlatformAwareFunctionNode
*/
public function parse(Parser $parser): void
{
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
$parser->match(TokenType::T_IDENTIFIER);
$parser->match(TokenType::T_OPEN_PARENTHESIS);
$this->parameters[self::VALUE_KEY] = $parser->SimpleArithmeticExpression();
$parser->match(Lexer::T_COMMA);
$parser->match(TokenType::T_COMMA);
$this->parameters[self::POWER_KEY] = $parser->ArithmeticPrimary();
$parser->match(Lexer::T_CLOSE_PARENTHESIS);
$parser->match(TokenType::T_CLOSE_PARENTHESIS);
}
}
14 changes: 7 additions & 7 deletions src/Oro/ORM/Query/AST/Functions/Numeric/Round.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace Oro\ORM\Query\AST\Functions\Numeric;

use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\TokenType;
use Oro\ORM\Query\AST\Functions\AbstractPlatformAwareFunctionNode;

class Round extends AbstractPlatformAwareFunctionNode
Expand All @@ -17,17 +17,17 @@ class Round extends AbstractPlatformAwareFunctionNode
*/
public function parse(Parser $parser): void
{
$lexer = $parser->getLexer();
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
$lexer = $parser->getTokenType();
$parser->match(TokenType::T_IDENTIFIER);
$parser->match(TokenType::T_OPEN_PARENTHESIS);
$this->parameters[self::VALUE] = $parser->SimpleArithmeticExpression();

// parse second parameter if available
if (Lexer::T_COMMA === $lexer->lookahead['type']) {
$parser->match(Lexer::T_COMMA);
if (TokenType::T_COMMA === $lexer->lookahead['type']) {
$parser->match(TokenType::T_COMMA);
$this->parameters[self::PRECISION] = $parser->ArithmeticPrimary();
}

$parser->match(Lexer::T_CLOSE_PARENTHESIS);
$parser->match(TokenType::T_CLOSE_PARENTHESIS);
}
}
8 changes: 4 additions & 4 deletions src/Oro/ORM/Query/AST/Functions/Numeric/Sign.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace Oro\ORM\Query\AST\Functions\Numeric;

use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\TokenType;
use Oro\ORM\Query\AST\Functions\AbstractPlatformAwareFunctionNode;

class Sign extends AbstractPlatformAwareFunctionNode
Expand All @@ -16,9 +16,9 @@ class Sign extends AbstractPlatformAwareFunctionNode
*/
public function parse(Parser $parser): void
{
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
$parser->match(TokenType::T_IDENTIFIER);
$parser->match(TokenType::T_OPEN_PARENTHESIS);
$this->parameters[self::PARAMETER_KEY] = $parser->SimpleArithmeticExpression();
$parser->match(Lexer::T_CLOSE_PARENTHESIS);
$parser->match(TokenType::T_CLOSE_PARENTHESIS);
}
}
16 changes: 8 additions & 8 deletions src/Oro/ORM/Query/AST/Functions/Numeric/TimestampDiff.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace Oro\ORM\Query\AST\Functions\Numeric;

use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\TokenType;
use Oro\ORM\Query\AST\Functions\AbstractPlatformAwareFunctionNode;

class TimestampDiff extends AbstractPlatformAwareFunctionNode
Expand Down Expand Up @@ -33,11 +33,11 @@ class TimestampDiff extends AbstractPlatformAwareFunctionNode
*/
public function parse(Parser $parser): void
{
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(TokenType::T_IDENTIFIER);
$parser->match(TokenType::T_OPEN_PARENTHESIS);
$parser->match(TokenType::T_IDENTIFIER);

$lexer = $parser->getLexer();
$lexer = $parser->getTokenType();
$unit = strtoupper(trim($lexer->token['value']));
if (!$this->isSupportedUnit($unit)) {
$parser->syntaxError(
Expand All @@ -51,11 +51,11 @@ public function parse(Parser $parser): void
}

$this->parameters[self::UNIT_KEY] = $unit;
$parser->match(Lexer::T_COMMA);
$parser->match(TokenType::T_COMMA);
$this->parameters[self::VAL1_KEY] = $parser->ArithmeticPrimary();
$parser->match(Lexer::T_COMMA);
$parser->match(TokenType::T_COMMA);
$this->parameters[self::VAL2_KEY] = $parser->ArithmeticPrimary();
$parser->match(Lexer::T_CLOSE_PARENTHESIS);
$parser->match(TokenType::T_CLOSE_PARENTHESIS);
}

protected function isSupportedUnit(string $unit): bool
Expand Down
8 changes: 4 additions & 4 deletions src/Oro/ORM/Query/AST/Functions/SimpleFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace Oro\ORM\Query\AST\Functions;

use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\TokenType;

class SimpleFunction extends AbstractPlatformAwareFunctionNode
{
Expand All @@ -15,9 +15,9 @@ class SimpleFunction extends AbstractPlatformAwareFunctionNode
*/
public function parse(Parser $parser): void
{
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
$parser->match(TokenType::T_IDENTIFIER);
$parser->match(TokenType::T_OPEN_PARENTHESIS);
$this->parameters[self::PARAMETER_KEY] = $parser->ArithmeticPrimary();
$parser->match(Lexer::T_CLOSE_PARENTHESIS);
$parser->match(TokenType::T_CLOSE_PARENTHESIS);
}
}
14 changes: 7 additions & 7 deletions src/Oro/ORM/Query/AST/Functions/String/ConcatWs.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace Oro\ORM\Query\AST\Functions\String;

use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\TokenType;

use Oro\ORM\Query\AST\Functions\AbstractPlatformAwareFunctionNode;

Expand All @@ -18,20 +18,20 @@ class ConcatWs extends AbstractPlatformAwareFunctionNode
*/
public function parse(Parser $parser): void
{
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
$parser->match(TokenType::T_IDENTIFIER);
$parser->match(TokenType::T_OPEN_PARENTHESIS);

$this->parameters[self::SEPARATOR_KEY] = $parser->StringPrimary();

$parser->match(Lexer::T_COMMA);
$parser->match(TokenType::T_COMMA);

$this->parameters[self::STRINGS_KEY][] = $parser->StringPrimary();

while ($parser->getLexer()->isNextToken(Lexer::T_COMMA)) {
$parser->match(Lexer::T_COMMA);
while ($parser->getTokenType()->isNextToken(TokenType::T_COMMA)) {
$parser->match(TokenType::T_COMMA);
$this->parameters[self::STRINGS_KEY][] = $parser->StringPrimary();
}

$parser->match(Lexer::T_CLOSE_PARENTHESIS);
$parser->match(TokenType::T_CLOSE_PARENTHESIS);
}
}
10 changes: 5 additions & 5 deletions src/Oro/ORM/Query/AST/Functions/String/DateFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Oro\ORM\Query\AST\Functions\String;

use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\TokenType;
use Doctrine\ORM\Query\Parser;
use Oro\ORM\Query\AST\Functions\AbstractPlatformAwareFunctionNode;

Expand Down Expand Up @@ -81,17 +81,17 @@ class DateFormat extends AbstractPlatformAwareFunctionNode
*/
public function parse(Parser $parser): void
{
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
$parser->match(TokenType::T_IDENTIFIER);
$parser->match(TokenType::T_OPEN_PARENTHESIS);

$this->parameters[self::DATE_KEY] = $parser->ArithmeticPrimary();

$parser->match(Lexer::T_COMMA);
$parser->match(TokenType::T_COMMA);

$this->parameters[self::FORMAT_KEY] = $parser->StringPrimary();
$this->validateFormat($parser);

$parser->match(Lexer::T_CLOSE_PARENTHESIS);
$parser->match(TokenType::T_CLOSE_PARENTHESIS);
}

private function validateFormat(Parser $parser): void
Expand Down
24 changes: 12 additions & 12 deletions src/Oro/ORM/Query/AST/Functions/String/GroupConcat.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace Oro\ORM\Query\AST\Functions\String;

use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\TokenType;
use Oro\ORM\Query\AST\Functions\AbstractPlatformAwareFunctionNode;

class GroupConcat extends AbstractPlatformAwareFunctionNode
Expand All @@ -20,12 +20,12 @@ class GroupConcat extends AbstractPlatformAwareFunctionNode
*/
public function parse(Parser $parser): void
{
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
$parser->match(TokenType::T_IDENTIFIER);
$parser->match(TokenType::T_OPEN_PARENTHESIS);

$lexer = $parser->getLexer();
if ($lexer->isNextToken(Lexer::T_DISTINCT)) {
$parser->match(Lexer::T_DISTINCT);
$lexer = $parser->getTokenType();
if ($lexer->isNextToken(TokenType::T_DISTINCT)) {
$parser->match(TokenType::T_DISTINCT);

$this->parameters[self::DISTINCT_KEY] = true;
}
Expand All @@ -34,24 +34,24 @@ public function parse(Parser $parser): void
$this->parameters[self::PARAMETER_KEY] = [];
$this->parameters[self::PARAMETER_KEY][] = $parser->StringPrimary();

while ($lexer->isNextToken(Lexer::T_COMMA)) {
$parser->match(Lexer::T_COMMA);
while ($lexer->isNextToken(TokenType::T_COMMA)) {
$parser->match(TokenType::T_COMMA);
$this->parameters[self::PARAMETER_KEY][] = $parser->StringPrimary();
}

if ($lexer->isNextToken(Lexer::T_ORDER)) {
if ($lexer->isNextToken(TokenType::T_ORDER)) {
$this->parameters[self::ORDER_KEY] = $parser->OrderByClause();
}

if ($lexer->isNextToken(Lexer::T_IDENTIFIER)) {
if ($lexer->isNextToken(TokenType::T_IDENTIFIER)) {
if (\strtolower($lexer->lookahead['value']) !== 'separator') {
$parser->syntaxError('separator');
}
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(TokenType::T_IDENTIFIER);

$this->parameters[self::SEPARATOR_KEY] = $parser->StringPrimary();
}

$parser->match(Lexer::T_CLOSE_PARENTHESIS);
$parser->match(TokenType::T_CLOSE_PARENTHESIS);
}
}
12 changes: 6 additions & 6 deletions src/Oro/ORM/Query/AST/Functions/String/Replace.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace Oro\ORM\Query\AST\Functions\String;

use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\TokenType;

use Oro\ORM\Query\AST\Functions\AbstractPlatformAwareFunctionNode;

Expand All @@ -19,19 +19,19 @@ class Replace extends AbstractPlatformAwareFunctionNode
*/
public function parse(Parser $parser): void
{
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
$parser->match(TokenType::T_IDENTIFIER);
$parser->match(TokenType::T_OPEN_PARENTHESIS);

$this->parameters[self::SUBJECT_KEY] = $parser->StringPrimary();

$parser->match(Lexer::T_COMMA);
$parser->match(TokenType::T_COMMA);

$this->parameters[self::FROM_KEY] = $parser->StringPrimary();

$parser->match(Lexer::T_COMMA);
$parser->match(TokenType::T_COMMA);

$this->parameters[self::TO_KEY] = $parser->StringPrimary();

$parser->match(Lexer::T_CLOSE_PARENTHESIS);
$parser->match(TokenType::T_CLOSE_PARENTHESIS);
}
}

0 comments on commit e0687da

Please sign in to comment.