From 5049b615c510bb9c5bcc62df92c6fc622cb7fb57 Mon Sep 17 00:00:00 2001 From: Karoly Gossler Date: Wed, 7 Feb 2024 13:31:08 +0100 Subject: [PATCH] Add TokenType class (#11228) * Add TokenType class Co-authored-by: Alexander M. Turek * Deprecated Lexer constants in favour of TokenType * Replace all Lexer::T_ occurrences with TokenType::T_ * Add upgrade note * Fixed import Lexer => TokenType * Fixed deprecation phpdoc * Replaced int value with matching constant of TokenType * Update src/Query/Lexer.php --------- Co-authored-by: Alexander M. Turek --- UPGRADE.md | 6 + .../cookbook/dql-user-defined-functions.rst | 20 +- .../reference/dql-doctrine-query-language.rst | 8 +- psalm-baseline.xml | 2 +- src/Query/AST/Functions/AbsFunction.php | 8 +- src/Query/AST/Functions/BitAndFunction.php | 10 +- src/Query/AST/Functions/BitOrFunction.php | 10 +- src/Query/AST/Functions/ConcatFunction.php | 14 +- .../AST/Functions/CurrentDateFunction.php | 8 +- .../AST/Functions/CurrentTimeFunction.php | 8 +- .../Functions/CurrentTimestampFunction.php | 8 +- src/Query/AST/Functions/DateAddFunction.php | 12 +- src/Query/AST/Functions/DateDiffFunction.php | 10 +- src/Query/AST/Functions/IdentityFunction.php | 14 +- src/Query/AST/Functions/LengthFunction.php | 8 +- src/Query/AST/Functions/LocateFunction.php | 14 +- src/Query/AST/Functions/LowerFunction.php | 8 +- src/Query/AST/Functions/ModFunction.php | 10 +- src/Query/AST/Functions/SizeFunction.php | 8 +- src/Query/AST/Functions/SqrtFunction.php | 8 +- src/Query/AST/Functions/SubstringFunction.php | 14 +- src/Query/AST/Functions/TrimFunction.php | 20 +- src/Query/AST/Functions/UpperFunction.php | 8 +- src/Query/Lexer.php | 316 ++++++-- src/Query/Parser.php | 690 +++++++++--------- src/Query/TokenType.php | 99 +++ .../ORM/Functional/CustomFunctionsTest.php | 8 +- .../ORM/Functional/Ticket/GH7286Test.php | 10 +- tests/Tests/ORM/Query/LexerTest.php | 69 +- tests/Tests/ORM/Query/ParserTest.php | 28 +- .../ORM/Query/SelectSqlGenerationTest.php | 8 +- .../Tests/ORM/Query/TreeWalkerAdapterTest.php | 6 +- 32 files changed, 865 insertions(+), 605 deletions(-) create mode 100644 src/Query/TokenType.php diff --git a/UPGRADE.md b/UPGRADE.md index df40b151d24..a0a360d72d7 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,3 +1,9 @@ +# Upgrade to 2.19 + +## Deprecate `Doctrine\ORM\Query\Lexer::T_*` constants + +Use `Doctrine\ORM\Query\TokenType::T_*` instead. + # Upgrade to 2.17 ## Deprecate annotations classes for named queries diff --git a/docs/en/cookbook/dql-user-defined-functions.rst b/docs/en/cookbook/dql-user-defined-functions.rst index 9345a2535e9..b189ed59fcd 100644 --- a/docs/en/cookbook/dql-user-defined-functions.rst +++ b/docs/en/cookbook/dql-user-defined-functions.rst @@ -99,12 +99,12 @@ discuss it step by step: public function parse(\Doctrine\ORM\Query\Parser $parser) { - $parser->match(Lexer::T_IDENTIFIER); // (2) - $parser->match(Lexer::T_OPEN_PARENTHESIS); // (3) + $parser->match(TokenType::T_IDENTIFIER); // (2) + $parser->match(TokenType::T_OPEN_PARENTHESIS); // (3) $this->firstDateExpression = $parser->ArithmeticPrimary(); // (4) - $parser->match(Lexer::T_COMMA); // (5) + $parser->match(TokenType::T_COMMA); // (5) $this->secondDateExpression = $parser->ArithmeticPrimary(); // (6) - $parser->match(Lexer::T_CLOSE_PARENTHESIS); // (3) + $parser->match(TokenType::T_CLOSE_PARENTHESIS); // (3) } public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) @@ -183,23 +183,23 @@ I'll skip the blah and show the code for this function: public function parse(\Doctrine\ORM\Query\Parser $parser) { - $parser->match(Lexer::T_IDENTIFIER); - $parser->match(Lexer::T_OPEN_PARENTHESIS); + $parser->match(TokenType::T_IDENTIFIER); + $parser->match(TokenType::T_OPEN_PARENTHESIS); $this->firstDateExpression = $parser->ArithmeticPrimary(); - $parser->match(Lexer::T_COMMA); - $parser->match(Lexer::T_IDENTIFIER); + $parser->match(TokenType::T_COMMA); + $parser->match(TokenType::T_IDENTIFIER); $this->intervalExpression = $parser->ArithmeticPrimary(); - $parser->match(Lexer::T_IDENTIFIER); + $parser->match(TokenType::T_IDENTIFIER); /** @var Lexer $lexer */ $lexer = $parser->getLexer(); $this->unit = $lexer->token['value']; - $parser->match(Lexer::T_CLOSE_PARENTHESIS); + $parser->match(TokenType::T_CLOSE_PARENTHESIS); } public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) diff --git a/docs/en/reference/dql-doctrine-query-language.rst b/docs/en/reference/dql-doctrine-query-language.rst index a9a7d6d3a1c..571190072e3 100644 --- a/docs/en/reference/dql-doctrine-query-language.rst +++ b/docs/en/reference/dql-doctrine-query-language.rst @@ -812,7 +812,7 @@ classes have to implement the base class : namespace MyProject\Query\AST; use Doctrine\ORM\Query\AST\Functions\FunctionNode; - use Doctrine\ORM\Query\Lexer; + use Doctrine\ORM\Query\TokenType; class MysqlFloor extends FunctionNode { @@ -827,12 +827,12 @@ classes have to implement the base class : public function parse(\Doctrine\ORM\Query\Parser $parser) { - $parser->match(Lexer::T_IDENTIFIER); - $parser->match(Lexer::T_OPEN_PARENTHESIS); + $parser->match(TokenType::T_IDENTIFIER); + $parser->match(TokenType::T_OPEN_PARENTHESIS); $this->simpleArithmeticExpression = $parser->SimpleArithmeticExpression(); - $parser->match(Lexer::T_CLOSE_PARENTHESIS); + $parser->match(TokenType::T_CLOSE_PARENTHESIS); } } diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 34b44307ff3..d2e890f17b5 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -2046,7 +2046,7 @@ $AST instanceof AST\SelectStatement - $token === Lexer::T_IDENTIFIER + $token === TokenType::T_IDENTIFIER diff --git a/src/Query/AST/Functions/AbsFunction.php b/src/Query/AST/Functions/AbsFunction.php index c7c35a9dfda..5c0fd7fac15 100644 --- a/src/Query/AST/Functions/AbsFunction.php +++ b/src/Query/AST/Functions/AbsFunction.php @@ -5,9 +5,9 @@ namespace Doctrine\ORM\Query\AST\Functions; use Doctrine\ORM\Query\AST\SimpleArithmeticExpression; -use Doctrine\ORM\Query\Lexer; use Doctrine\ORM\Query\Parser; use Doctrine\ORM\Query\SqlWalker; +use Doctrine\ORM\Query\TokenType; /** * "ABS" "(" SimpleArithmeticExpression ")" @@ -30,11 +30,11 @@ public function getSql(SqlWalker $sqlWalker) /** @inheritDoc */ public function parse(Parser $parser) { - $parser->match(Lexer::T_IDENTIFIER); - $parser->match(Lexer::T_OPEN_PARENTHESIS); + $parser->match(TokenType::T_IDENTIFIER); + $parser->match(TokenType::T_OPEN_PARENTHESIS); $this->simpleArithmeticExpression = $parser->SimpleArithmeticExpression(); - $parser->match(Lexer::T_CLOSE_PARENTHESIS); + $parser->match(TokenType::T_CLOSE_PARENTHESIS); } } diff --git a/src/Query/AST/Functions/BitAndFunction.php b/src/Query/AST/Functions/BitAndFunction.php index 93edf48ae59..c278de5e36e 100644 --- a/src/Query/AST/Functions/BitAndFunction.php +++ b/src/Query/AST/Functions/BitAndFunction.php @@ -5,9 +5,9 @@ namespace Doctrine\ORM\Query\AST\Functions; use Doctrine\ORM\Query\AST\Node; -use Doctrine\ORM\Query\Lexer; use Doctrine\ORM\Query\Parser; use Doctrine\ORM\Query\SqlWalker; +use Doctrine\ORM\Query\TokenType; /** * "BIT_AND" "(" ArithmeticPrimary "," ArithmeticPrimary ")" @@ -36,13 +36,13 @@ public function getSql(SqlWalker $sqlWalker) /** @inheritDoc */ public function parse(Parser $parser) { - $parser->match(Lexer::T_IDENTIFIER); - $parser->match(Lexer::T_OPEN_PARENTHESIS); + $parser->match(TokenType::T_IDENTIFIER); + $parser->match(TokenType::T_OPEN_PARENTHESIS); $this->firstArithmetic = $parser->ArithmeticPrimary(); - $parser->match(Lexer::T_COMMA); + $parser->match(TokenType::T_COMMA); $this->secondArithmetic = $parser->ArithmeticPrimary(); - $parser->match(Lexer::T_CLOSE_PARENTHESIS); + $parser->match(TokenType::T_CLOSE_PARENTHESIS); } } diff --git a/src/Query/AST/Functions/BitOrFunction.php b/src/Query/AST/Functions/BitOrFunction.php index 94fea1d8ea3..a380009cceb 100644 --- a/src/Query/AST/Functions/BitOrFunction.php +++ b/src/Query/AST/Functions/BitOrFunction.php @@ -5,9 +5,9 @@ namespace Doctrine\ORM\Query\AST\Functions; use Doctrine\ORM\Query\AST\Node; -use Doctrine\ORM\Query\Lexer; use Doctrine\ORM\Query\Parser; use Doctrine\ORM\Query\SqlWalker; +use Doctrine\ORM\Query\TokenType; /** * "BIT_OR" "(" ArithmeticPrimary "," ArithmeticPrimary ")" @@ -36,13 +36,13 @@ public function getSql(SqlWalker $sqlWalker) /** @inheritDoc */ public function parse(Parser $parser) { - $parser->match(Lexer::T_IDENTIFIER); - $parser->match(Lexer::T_OPEN_PARENTHESIS); + $parser->match(TokenType::T_IDENTIFIER); + $parser->match(TokenType::T_OPEN_PARENTHESIS); $this->firstArithmetic = $parser->ArithmeticPrimary(); - $parser->match(Lexer::T_COMMA); + $parser->match(TokenType::T_COMMA); $this->secondArithmetic = $parser->ArithmeticPrimary(); - $parser->match(Lexer::T_CLOSE_PARENTHESIS); + $parser->match(TokenType::T_CLOSE_PARENTHESIS); } } diff --git a/src/Query/AST/Functions/ConcatFunction.php b/src/Query/AST/Functions/ConcatFunction.php index 8a67fbbb896..f25f0e69668 100644 --- a/src/Query/AST/Functions/ConcatFunction.php +++ b/src/Query/AST/Functions/ConcatFunction.php @@ -5,9 +5,9 @@ namespace Doctrine\ORM\Query\AST\Functions; use Doctrine\ORM\Query\AST\Node; -use Doctrine\ORM\Query\Lexer; use Doctrine\ORM\Query\Parser; use Doctrine\ORM\Query\SqlWalker; +use Doctrine\ORM\Query\TokenType; /** * "CONCAT" "(" StringPrimary "," StringPrimary {"," StringPrimary }* ")" @@ -42,22 +42,22 @@ public function getSql(SqlWalker $sqlWalker) /** @inheritDoc */ public function parse(Parser $parser) { - $parser->match(Lexer::T_IDENTIFIER); - $parser->match(Lexer::T_OPEN_PARENTHESIS); + $parser->match(TokenType::T_IDENTIFIER); + $parser->match(TokenType::T_OPEN_PARENTHESIS); $this->firstStringPrimary = $parser->StringPrimary(); $this->concatExpressions[] = $this->firstStringPrimary; - $parser->match(Lexer::T_COMMA); + $parser->match(TokenType::T_COMMA); $this->secondStringPrimary = $parser->StringPrimary(); $this->concatExpressions[] = $this->secondStringPrimary; - while ($parser->getLexer()->isNextToken(Lexer::T_COMMA)) { - $parser->match(Lexer::T_COMMA); + while ($parser->getLexer()->isNextToken(TokenType::T_COMMA)) { + $parser->match(TokenType::T_COMMA); $this->concatExpressions[] = $parser->StringPrimary(); } - $parser->match(Lexer::T_CLOSE_PARENTHESIS); + $parser->match(TokenType::T_CLOSE_PARENTHESIS); } } diff --git a/src/Query/AST/Functions/CurrentDateFunction.php b/src/Query/AST/Functions/CurrentDateFunction.php index ee7e733901c..c19c640c598 100644 --- a/src/Query/AST/Functions/CurrentDateFunction.php +++ b/src/Query/AST/Functions/CurrentDateFunction.php @@ -4,9 +4,9 @@ namespace Doctrine\ORM\Query\AST\Functions; -use Doctrine\ORM\Query\Lexer; use Doctrine\ORM\Query\Parser; use Doctrine\ORM\Query\SqlWalker; +use Doctrine\ORM\Query\TokenType; /** * "CURRENT_DATE" @@ -24,8 +24,8 @@ public function getSql(SqlWalker $sqlWalker) /** @inheritDoc */ public function parse(Parser $parser) { - $parser->match(Lexer::T_IDENTIFIER); - $parser->match(Lexer::T_OPEN_PARENTHESIS); - $parser->match(Lexer::T_CLOSE_PARENTHESIS); + $parser->match(TokenType::T_IDENTIFIER); + $parser->match(TokenType::T_OPEN_PARENTHESIS); + $parser->match(TokenType::T_CLOSE_PARENTHESIS); } } diff --git a/src/Query/AST/Functions/CurrentTimeFunction.php b/src/Query/AST/Functions/CurrentTimeFunction.php index e906cbe58eb..3595a0385d9 100644 --- a/src/Query/AST/Functions/CurrentTimeFunction.php +++ b/src/Query/AST/Functions/CurrentTimeFunction.php @@ -4,9 +4,9 @@ namespace Doctrine\ORM\Query\AST\Functions; -use Doctrine\ORM\Query\Lexer; use Doctrine\ORM\Query\Parser; use Doctrine\ORM\Query\SqlWalker; +use Doctrine\ORM\Query\TokenType; /** * "CURRENT_TIME" @@ -24,8 +24,8 @@ public function getSql(SqlWalker $sqlWalker) /** @inheritDoc */ public function parse(Parser $parser) { - $parser->match(Lexer::T_IDENTIFIER); - $parser->match(Lexer::T_OPEN_PARENTHESIS); - $parser->match(Lexer::T_CLOSE_PARENTHESIS); + $parser->match(TokenType::T_IDENTIFIER); + $parser->match(TokenType::T_OPEN_PARENTHESIS); + $parser->match(TokenType::T_CLOSE_PARENTHESIS); } } diff --git a/src/Query/AST/Functions/CurrentTimestampFunction.php b/src/Query/AST/Functions/CurrentTimestampFunction.php index 0bf1a801e25..349e32746df 100644 --- a/src/Query/AST/Functions/CurrentTimestampFunction.php +++ b/src/Query/AST/Functions/CurrentTimestampFunction.php @@ -4,9 +4,9 @@ namespace Doctrine\ORM\Query\AST\Functions; -use Doctrine\ORM\Query\Lexer; use Doctrine\ORM\Query\Parser; use Doctrine\ORM\Query\SqlWalker; +use Doctrine\ORM\Query\TokenType; /** * "CURRENT_TIMESTAMP" @@ -24,8 +24,8 @@ public function getSql(SqlWalker $sqlWalker) /** @inheritDoc */ public function parse(Parser $parser) { - $parser->match(Lexer::T_IDENTIFIER); - $parser->match(Lexer::T_OPEN_PARENTHESIS); - $parser->match(Lexer::T_CLOSE_PARENTHESIS); + $parser->match(TokenType::T_IDENTIFIER); + $parser->match(TokenType::T_OPEN_PARENTHESIS); + $parser->match(TokenType::T_CLOSE_PARENTHESIS); } } diff --git a/src/Query/AST/Functions/DateAddFunction.php b/src/Query/AST/Functions/DateAddFunction.php index efa7849e647..e980e8e8155 100644 --- a/src/Query/AST/Functions/DateAddFunction.php +++ b/src/Query/AST/Functions/DateAddFunction.php @@ -5,10 +5,10 @@ namespace Doctrine\ORM\Query\AST\Functions; use Doctrine\ORM\Query\AST\Node; -use Doctrine\ORM\Query\Lexer; use Doctrine\ORM\Query\Parser; use Doctrine\ORM\Query\QueryException; use Doctrine\ORM\Query\SqlWalker; +use Doctrine\ORM\Query\TokenType; use function strtolower; @@ -84,15 +84,15 @@ public function getSql(SqlWalker $sqlWalker) /** @inheritDoc */ public function parse(Parser $parser) { - $parser->match(Lexer::T_IDENTIFIER); - $parser->match(Lexer::T_OPEN_PARENTHESIS); + $parser->match(TokenType::T_IDENTIFIER); + $parser->match(TokenType::T_OPEN_PARENTHESIS); $this->firstDateExpression = $parser->ArithmeticPrimary(); - $parser->match(Lexer::T_COMMA); + $parser->match(TokenType::T_COMMA); $this->intervalExpression = $parser->ArithmeticPrimary(); - $parser->match(Lexer::T_COMMA); + $parser->match(TokenType::T_COMMA); $this->unit = $parser->StringPrimary(); - $parser->match(Lexer::T_CLOSE_PARENTHESIS); + $parser->match(TokenType::T_CLOSE_PARENTHESIS); } } diff --git a/src/Query/AST/Functions/DateDiffFunction.php b/src/Query/AST/Functions/DateDiffFunction.php index 181535265f4..209df00abd5 100644 --- a/src/Query/AST/Functions/DateDiffFunction.php +++ b/src/Query/AST/Functions/DateDiffFunction.php @@ -5,9 +5,9 @@ namespace Doctrine\ORM\Query\AST\Functions; use Doctrine\ORM\Query\AST\Node; -use Doctrine\ORM\Query\Lexer; use Doctrine\ORM\Query\Parser; use Doctrine\ORM\Query\SqlWalker; +use Doctrine\ORM\Query\TokenType; /** * "DATE_DIFF" "(" ArithmeticPrimary "," ArithmeticPrimary ")" @@ -34,13 +34,13 @@ public function getSql(SqlWalker $sqlWalker) /** @inheritDoc */ public function parse(Parser $parser) { - $parser->match(Lexer::T_IDENTIFIER); - $parser->match(Lexer::T_OPEN_PARENTHESIS); + $parser->match(TokenType::T_IDENTIFIER); + $parser->match(TokenType::T_OPEN_PARENTHESIS); $this->date1 = $parser->ArithmeticPrimary(); - $parser->match(Lexer::T_COMMA); + $parser->match(TokenType::T_COMMA); $this->date2 = $parser->ArithmeticPrimary(); - $parser->match(Lexer::T_CLOSE_PARENTHESIS); + $parser->match(TokenType::T_CLOSE_PARENTHESIS); } } diff --git a/src/Query/AST/Functions/IdentityFunction.php b/src/Query/AST/Functions/IdentityFunction.php index 10b8dc80582..e292c975afd 100644 --- a/src/Query/AST/Functions/IdentityFunction.php +++ b/src/Query/AST/Functions/IdentityFunction.php @@ -5,10 +5,10 @@ namespace Doctrine\ORM\Query\AST\Functions; use Doctrine\ORM\Query\AST\PathExpression; -use Doctrine\ORM\Query\Lexer; use Doctrine\ORM\Query\Parser; use Doctrine\ORM\Query\QueryException; use Doctrine\ORM\Query\SqlWalker; +use Doctrine\ORM\Query\TokenType; use function assert; use function reset; @@ -77,20 +77,20 @@ public function getSql(SqlWalker $sqlWalker) */ public function parse(Parser $parser) { - $parser->match(Lexer::T_IDENTIFIER); - $parser->match(Lexer::T_OPEN_PARENTHESIS); + $parser->match(TokenType::T_IDENTIFIER); + $parser->match(TokenType::T_OPEN_PARENTHESIS); $this->pathExpression = $parser->SingleValuedAssociationPathExpression(); - if ($parser->getLexer()->isNextToken(Lexer::T_COMMA)) { - $parser->match(Lexer::T_COMMA); - $parser->match(Lexer::T_STRING); + if ($parser->getLexer()->isNextToken(TokenType::T_COMMA)) { + $parser->match(TokenType::T_COMMA); + $parser->match(TokenType::T_STRING); $token = $parser->getLexer()->token; assert($token !== null); $this->fieldMapping = $token->value; } - $parser->match(Lexer::T_CLOSE_PARENTHESIS); + $parser->match(TokenType::T_CLOSE_PARENTHESIS); } } diff --git a/src/Query/AST/Functions/LengthFunction.php b/src/Query/AST/Functions/LengthFunction.php index 29b603c2484..42420af54f0 100644 --- a/src/Query/AST/Functions/LengthFunction.php +++ b/src/Query/AST/Functions/LengthFunction.php @@ -8,9 +8,9 @@ use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Query\AST\Node; use Doctrine\ORM\Query\AST\TypedExpression; -use Doctrine\ORM\Query\Lexer; use Doctrine\ORM\Query\Parser; use Doctrine\ORM\Query\SqlWalker; +use Doctrine\ORM\Query\TokenType; /** * "LENGTH" "(" StringPrimary ")" @@ -33,12 +33,12 @@ public function getSql(SqlWalker $sqlWalker) /** @inheritDoc */ public function parse(Parser $parser) { - $parser->match(Lexer::T_IDENTIFIER); - $parser->match(Lexer::T_OPEN_PARENTHESIS); + $parser->match(TokenType::T_IDENTIFIER); + $parser->match(TokenType::T_OPEN_PARENTHESIS); $this->stringPrimary = $parser->StringPrimary(); - $parser->match(Lexer::T_CLOSE_PARENTHESIS); + $parser->match(TokenType::T_CLOSE_PARENTHESIS); } public function getReturnType(): Type diff --git a/src/Query/AST/Functions/LocateFunction.php b/src/Query/AST/Functions/LocateFunction.php index 20badbc91eb..2942f06107d 100644 --- a/src/Query/AST/Functions/LocateFunction.php +++ b/src/Query/AST/Functions/LocateFunction.php @@ -6,9 +6,9 @@ use Doctrine\ORM\Query\AST\Node; use Doctrine\ORM\Query\AST\SimpleArithmeticExpression; -use Doctrine\ORM\Query\Lexer; use Doctrine\ORM\Query\Parser; use Doctrine\ORM\Query\SqlWalker; +use Doctrine\ORM\Query\TokenType; /** * "LOCATE" "(" StringPrimary "," StringPrimary ["," SimpleArithmeticExpression]")" @@ -48,22 +48,22 @@ public function getSql(SqlWalker $sqlWalker) /** @inheritDoc */ public function parse(Parser $parser) { - $parser->match(Lexer::T_IDENTIFIER); - $parser->match(Lexer::T_OPEN_PARENTHESIS); + $parser->match(TokenType::T_IDENTIFIER); + $parser->match(TokenType::T_OPEN_PARENTHESIS); $this->firstStringPrimary = $parser->StringPrimary(); - $parser->match(Lexer::T_COMMA); + $parser->match(TokenType::T_COMMA); $this->secondStringPrimary = $parser->StringPrimary(); $lexer = $parser->getLexer(); - if ($lexer->isNextToken(Lexer::T_COMMA)) { - $parser->match(Lexer::T_COMMA); + if ($lexer->isNextToken(TokenType::T_COMMA)) { + $parser->match(TokenType::T_COMMA); $this->simpleArithmeticExpression = $parser->SimpleArithmeticExpression(); } - $parser->match(Lexer::T_CLOSE_PARENTHESIS); + $parser->match(TokenType::T_CLOSE_PARENTHESIS); } } diff --git a/src/Query/AST/Functions/LowerFunction.php b/src/Query/AST/Functions/LowerFunction.php index 0b7fcf83b88..e6c73cde4d9 100644 --- a/src/Query/AST/Functions/LowerFunction.php +++ b/src/Query/AST/Functions/LowerFunction.php @@ -5,9 +5,9 @@ namespace Doctrine\ORM\Query\AST\Functions; use Doctrine\ORM\Query\AST\Node; -use Doctrine\ORM\Query\Lexer; use Doctrine\ORM\Query\Parser; use Doctrine\ORM\Query\SqlWalker; +use Doctrine\ORM\Query\TokenType; use function sprintf; @@ -33,11 +33,11 @@ public function getSql(SqlWalker $sqlWalker) /** @inheritDoc */ public function parse(Parser $parser) { - $parser->match(Lexer::T_IDENTIFIER); - $parser->match(Lexer::T_OPEN_PARENTHESIS); + $parser->match(TokenType::T_IDENTIFIER); + $parser->match(TokenType::T_OPEN_PARENTHESIS); $this->stringPrimary = $parser->StringPrimary(); - $parser->match(Lexer::T_CLOSE_PARENTHESIS); + $parser->match(TokenType::T_CLOSE_PARENTHESIS); } } diff --git a/src/Query/AST/Functions/ModFunction.php b/src/Query/AST/Functions/ModFunction.php index c0077d04080..ea6ee2e0d4e 100644 --- a/src/Query/AST/Functions/ModFunction.php +++ b/src/Query/AST/Functions/ModFunction.php @@ -5,9 +5,9 @@ namespace Doctrine\ORM\Query\AST\Functions; use Doctrine\ORM\Query\AST\SimpleArithmeticExpression; -use Doctrine\ORM\Query\Lexer; use Doctrine\ORM\Query\Parser; use Doctrine\ORM\Query\SqlWalker; +use Doctrine\ORM\Query\TokenType; /** * "MOD" "(" SimpleArithmeticExpression "," SimpleArithmeticExpression ")" @@ -34,15 +34,15 @@ public function getSql(SqlWalker $sqlWalker) /** @inheritDoc */ public function parse(Parser $parser) { - $parser->match(Lexer::T_IDENTIFIER); - $parser->match(Lexer::T_OPEN_PARENTHESIS); + $parser->match(TokenType::T_IDENTIFIER); + $parser->match(TokenType::T_OPEN_PARENTHESIS); $this->firstSimpleArithmeticExpression = $parser->SimpleArithmeticExpression(); - $parser->match(Lexer::T_COMMA); + $parser->match(TokenType::T_COMMA); $this->secondSimpleArithmeticExpression = $parser->SimpleArithmeticExpression(); - $parser->match(Lexer::T_CLOSE_PARENTHESIS); + $parser->match(TokenType::T_CLOSE_PARENTHESIS); } } diff --git a/src/Query/AST/Functions/SizeFunction.php b/src/Query/AST/Functions/SizeFunction.php index 70b7f6dadf3..4576f26d21f 100644 --- a/src/Query/AST/Functions/SizeFunction.php +++ b/src/Query/AST/Functions/SizeFunction.php @@ -6,9 +6,9 @@ use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Query\AST\PathExpression; -use Doctrine\ORM\Query\Lexer; use Doctrine\ORM\Query\Parser; use Doctrine\ORM\Query\SqlWalker; +use Doctrine\ORM\Query\TokenType; use function assert; @@ -105,11 +105,11 @@ public function getSql(SqlWalker $sqlWalker) /** @inheritDoc */ public function parse(Parser $parser) { - $parser->match(Lexer::T_IDENTIFIER); - $parser->match(Lexer::T_OPEN_PARENTHESIS); + $parser->match(TokenType::T_IDENTIFIER); + $parser->match(TokenType::T_OPEN_PARENTHESIS); $this->collectionPathExpression = $parser->CollectionValuedPathExpression(); - $parser->match(Lexer::T_CLOSE_PARENTHESIS); + $parser->match(TokenType::T_CLOSE_PARENTHESIS); } } diff --git a/src/Query/AST/Functions/SqrtFunction.php b/src/Query/AST/Functions/SqrtFunction.php index 4e3a87015f9..a5cf3038768 100644 --- a/src/Query/AST/Functions/SqrtFunction.php +++ b/src/Query/AST/Functions/SqrtFunction.php @@ -5,9 +5,9 @@ namespace Doctrine\ORM\Query\AST\Functions; use Doctrine\ORM\Query\AST\SimpleArithmeticExpression; -use Doctrine\ORM\Query\Lexer; use Doctrine\ORM\Query\Parser; use Doctrine\ORM\Query\SqlWalker; +use Doctrine\ORM\Query\TokenType; use function sprintf; @@ -33,11 +33,11 @@ public function getSql(SqlWalker $sqlWalker) /** @inheritDoc */ public function parse(Parser $parser) { - $parser->match(Lexer::T_IDENTIFIER); - $parser->match(Lexer::T_OPEN_PARENTHESIS); + $parser->match(TokenType::T_IDENTIFIER); + $parser->match(TokenType::T_OPEN_PARENTHESIS); $this->simpleArithmeticExpression = $parser->SimpleArithmeticExpression(); - $parser->match(Lexer::T_CLOSE_PARENTHESIS); + $parser->match(TokenType::T_CLOSE_PARENTHESIS); } } diff --git a/src/Query/AST/Functions/SubstringFunction.php b/src/Query/AST/Functions/SubstringFunction.php index 292248ea079..50031c7b361 100644 --- a/src/Query/AST/Functions/SubstringFunction.php +++ b/src/Query/AST/Functions/SubstringFunction.php @@ -6,9 +6,9 @@ use Doctrine\ORM\Query\AST\Node; use Doctrine\ORM\Query\AST\SimpleArithmeticExpression; -use Doctrine\ORM\Query\Lexer; use Doctrine\ORM\Query\Parser; use Doctrine\ORM\Query\SqlWalker; +use Doctrine\ORM\Query\TokenType; /** * "SUBSTRING" "(" StringPrimary "," SimpleArithmeticExpression "," SimpleArithmeticExpression ")" @@ -44,22 +44,22 @@ public function getSql(SqlWalker $sqlWalker) /** @inheritDoc */ public function parse(Parser $parser) { - $parser->match(Lexer::T_IDENTIFIER); - $parser->match(Lexer::T_OPEN_PARENTHESIS); + $parser->match(TokenType::T_IDENTIFIER); + $parser->match(TokenType::T_OPEN_PARENTHESIS); $this->stringPrimary = $parser->StringPrimary(); - $parser->match(Lexer::T_COMMA); + $parser->match(TokenType::T_COMMA); $this->firstSimpleArithmeticExpression = $parser->SimpleArithmeticExpression(); $lexer = $parser->getLexer(); - if ($lexer->isNextToken(Lexer::T_COMMA)) { - $parser->match(Lexer::T_COMMA); + if ($lexer->isNextToken(TokenType::T_COMMA)) { + $parser->match(TokenType::T_COMMA); $this->secondSimpleArithmeticExpression = $parser->SimpleArithmeticExpression(); } - $parser->match(Lexer::T_CLOSE_PARENTHESIS); + $parser->match(TokenType::T_CLOSE_PARENTHESIS); } } diff --git a/src/Query/AST/Functions/TrimFunction.php b/src/Query/AST/Functions/TrimFunction.php index 8c2b307faea..c2adeb121b9 100644 --- a/src/Query/AST/Functions/TrimFunction.php +++ b/src/Query/AST/Functions/TrimFunction.php @@ -6,9 +6,9 @@ use Doctrine\DBAL\Platforms\TrimMode; use Doctrine\ORM\Query\AST\Node; -use Doctrine\ORM\Query\Lexer; use Doctrine\ORM\Query\Parser; use Doctrine\ORM\Query\SqlWalker; +use Doctrine\ORM\Query\TokenType; use function assert; use function strcasecmp; @@ -62,25 +62,25 @@ public function parse(Parser $parser) { $lexer = $parser->getLexer(); - $parser->match(Lexer::T_IDENTIFIER); - $parser->match(Lexer::T_OPEN_PARENTHESIS); + $parser->match(TokenType::T_IDENTIFIER); + $parser->match(TokenType::T_OPEN_PARENTHESIS); $this->parseTrimMode($parser); - if ($lexer->isNextToken(Lexer::T_STRING)) { - $parser->match(Lexer::T_STRING); + if ($lexer->isNextToken(TokenType::T_STRING)) { + $parser->match(TokenType::T_STRING); assert($lexer->token !== null); $this->trimChar = $lexer->token->value; } if ($this->leading || $this->trailing || $this->both || $this->trimChar) { - $parser->match(Lexer::T_FROM); + $parser->match(TokenType::T_FROM); } $this->stringPrimary = $parser->StringPrimary(); - $parser->match(Lexer::T_CLOSE_PARENTHESIS); + $parser->match(TokenType::T_CLOSE_PARENTHESIS); } /** @psalm-return TrimMode::* */ @@ -108,7 +108,7 @@ private function parseTrimMode(Parser $parser): void $value = $lexer->lookahead->value; if (strcasecmp('leading', $value) === 0) { - $parser->match(Lexer::T_LEADING); + $parser->match(TokenType::T_LEADING); $this->leading = true; @@ -116,7 +116,7 @@ private function parseTrimMode(Parser $parser): void } if (strcasecmp('trailing', $value) === 0) { - $parser->match(Lexer::T_TRAILING); + $parser->match(TokenType::T_TRAILING); $this->trailing = true; @@ -124,7 +124,7 @@ private function parseTrimMode(Parser $parser): void } if (strcasecmp('both', $value) === 0) { - $parser->match(Lexer::T_BOTH); + $parser->match(TokenType::T_BOTH); $this->both = true; diff --git a/src/Query/AST/Functions/UpperFunction.php b/src/Query/AST/Functions/UpperFunction.php index d896c5af7f7..15273973f98 100644 --- a/src/Query/AST/Functions/UpperFunction.php +++ b/src/Query/AST/Functions/UpperFunction.php @@ -5,9 +5,9 @@ namespace Doctrine\ORM\Query\AST\Functions; use Doctrine\ORM\Query\AST\Node; -use Doctrine\ORM\Query\Lexer; use Doctrine\ORM\Query\Parser; use Doctrine\ORM\Query\SqlWalker; +use Doctrine\ORM\Query\TokenType; use function sprintf; @@ -33,11 +33,11 @@ public function getSql(SqlWalker $sqlWalker) /** @inheritDoc */ public function parse(Parser $parser) { - $parser->match(Lexer::T_IDENTIFIER); - $parser->match(Lexer::T_OPEN_PARENTHESIS); + $parser->match(TokenType::T_IDENTIFIER); + $parser->match(TokenType::T_OPEN_PARENTHESIS); $this->stringPrimary = $parser->StringPrimary(); - $parser->match(Lexer::T_CLOSE_PARENTHESIS); + $parser->match(TokenType::T_CLOSE_PARENTHESIS); } } diff --git a/src/Query/Lexer.php b/src/Query/Lexer.php index da68a6c6c1a..d4f0aefc255 100644 --- a/src/Query/Lexer.php +++ b/src/Query/Lexer.php @@ -21,95 +21,249 @@ /** * Scans a DQL query for tokens. * - * @extends AbstractLexer + * @extends AbstractLexer */ class Lexer extends AbstractLexer { // All tokens that are not valid identifiers must be < 100 - public const T_NONE = 1; - public const T_INTEGER = 2; - public const T_STRING = 3; - public const T_INPUT_PARAMETER = 4; - public const T_FLOAT = 5; - public const T_CLOSE_PARENTHESIS = 6; - public const T_OPEN_PARENTHESIS = 7; - public const T_COMMA = 8; - public const T_DIVIDE = 9; - public const T_DOT = 10; - public const T_EQUALS = 11; - public const T_GREATER_THAN = 12; - public const T_LOWER_THAN = 13; - public const T_MINUS = 14; - public const T_MULTIPLY = 15; - public const T_NEGATE = 16; - public const T_PLUS = 17; - public const T_OPEN_CURLY_BRACE = 18; - public const T_CLOSE_CURLY_BRACE = 19; + /** @deprecated use {@see TokenType::T_NONE} */ + public const T_NONE = TokenType::T_NONE; + + /** @deprecated use {@see TokenType::T_INTEGER} */ + public const T_INTEGER = TokenType::T_INTEGER; + + /** @deprecated use {@see TokenType::T_STRING} */ + public const T_STRING = TokenType::T_STRING; + + /** @deprecated use {@see TokenType::T_INPUT_PARAMETER} */ + public const T_INPUT_PARAMETER = TokenType::T_INPUT_PARAMETER; + + /** @deprecated use {@see TokenType::T_FLOAT} */ + public const T_FLOAT = TokenType::T_FLOAT; + + /** @deprecated use {@see TokenType::T_CLOSE_PARENTHESIS} */ + public const T_CLOSE_PARENTHESIS = TokenType::T_CLOSE_PARENTHESIS; + + /** @deprecated use {@see TokenType::T_OPEN_PARENTHESIS} */ + public const T_OPEN_PARENTHESIS = TokenType::T_OPEN_PARENTHESIS; + + /** @deprecated use {@see TokenType::T_COMMA} */ + public const T_COMMA = TokenType::T_COMMA; + + /** @deprecated use {@see TokenType::T_DIVIDE} */ + public const T_DIVIDE = TokenType::T_DIVIDE; + + /** @deprecated use {@see TokenType::T_DOT} */ + public const T_DOT = TokenType::T_DOT; + + /** @deprecated use {@see TokenType::T_EQUALS} */ + public const T_EQUALS = TokenType::T_EQUALS; + + /** @deprecated use {@see TokenType::T_GREATER_THAN} */ + public const T_GREATER_THAN = TokenType::T_GREATER_THAN; + + /** @deprecated use {@see TokenType::T_LOWER_THAN} */ + public const T_LOWER_THAN = TokenType::T_LOWER_THAN; + + /** @deprecated use {@see TokenType::T_MINUS} */ + public const T_MINUS = TokenType::T_MINUS; + + /** @deprecated use {@see TokenType::T_MULTIPLY} */ + public const T_MULTIPLY = TokenType::T_MULTIPLY; + + /** @deprecated use {@see TokenType::T_NEGATE} */ + public const T_NEGATE = TokenType::T_NEGATE; + + /** @deprecated use {@see TokenType::T_PLUS} */ + public const T_PLUS = TokenType::T_PLUS; + + /** @deprecated use {@see TokenType::T_OPEN_CURLY_BRACE} */ + public const T_OPEN_CURLY_BRACE = TokenType::T_OPEN_CURLY_BRACE; + + /** @deprecated use {@see TokenType::T_CLOSE_CURLY_BRACE} */ + public const T_CLOSE_CURLY_BRACE = TokenType::T_CLOSE_CURLY_BRACE; // All tokens that are identifiers or keywords that could be considered as identifiers should be >= 100 /** @deprecated No Replacement planned. */ - public const T_ALIASED_NAME = 100; - public const T_FULLY_QUALIFIED_NAME = 101; - public const T_IDENTIFIER = 102; + public const T_ALIASED_NAME = TokenType::T_ALIASED_NAME; + + /** @deprecated use {@see TokenType::T_FULLY_QUALIFIED_NAME} */ + public const T_FULLY_QUALIFIED_NAME = TokenType::T_FULLY_QUALIFIED_NAME; + + /** @deprecated use {@see TokenType::T_IDENTIFIER} */ + public const T_IDENTIFIER = TokenType::T_IDENTIFIER; // All keyword tokens should be >= 200 - public const T_ALL = 200; - public const T_AND = 201; - public const T_ANY = 202; - public const T_AS = 203; - public const T_ASC = 204; - public const T_AVG = 205; - public const T_BETWEEN = 206; - public const T_BOTH = 207; - public const T_BY = 208; - public const T_CASE = 209; - public const T_COALESCE = 210; - public const T_COUNT = 211; - public const T_DELETE = 212; - public const T_DESC = 213; - public const T_DISTINCT = 214; - public const T_ELSE = 215; - public const T_EMPTY = 216; - public const T_END = 217; - public const T_ESCAPE = 218; - public const T_EXISTS = 219; - public const T_FALSE = 220; - public const T_FROM = 221; - public const T_GROUP = 222; - public const T_HAVING = 223; - public const T_HIDDEN = 224; - public const T_IN = 225; - public const T_INDEX = 226; - public const T_INNER = 227; - public const T_INSTANCE = 228; - public const T_IS = 229; - public const T_JOIN = 230; - public const T_LEADING = 231; - public const T_LEFT = 232; - public const T_LIKE = 233; - public const T_MAX = 234; - public const T_MEMBER = 235; - public const T_MIN = 236; - public const T_NEW = 237; - public const T_NOT = 238; - public const T_NULL = 239; - public const T_NULLIF = 240; - public const T_OF = 241; - public const T_OR = 242; - public const T_ORDER = 243; - public const T_OUTER = 244; - public const T_PARTIAL = 245; - public const T_SELECT = 246; - public const T_SET = 247; - public const T_SOME = 248; - public const T_SUM = 249; - public const T_THEN = 250; - public const T_TRAILING = 251; - public const T_TRUE = 252; - public const T_UPDATE = 253; - public const T_WHEN = 254; - public const T_WHERE = 255; - public const T_WITH = 256; + /** @deprecated use {@see TokenType::T_ALL} */ + public const T_ALL = TokenType::T_ALL; + + /** @deprecated use {@see TokenType::T_AND} */ + public const T_AND = TokenType::T_AND; + + /** @deprecated use {@see TokenType::T_ANY} */ + public const T_ANY = TokenType::T_ANY; + + /** @deprecated use {@see TokenType::T_AS} */ + public const T_AS = TokenType::T_AS; + + /** @deprecated use {@see TokenType::T_ASC} */ + public const T_ASC = TokenType::T_ASC; + + /** @deprecated use {@see TokenType::T_AVG} */ + public const T_AVG = TokenType::T_AVG; + + /** @deprecated use {@see TokenType::T_BETWEEN} */ + public const T_BETWEEN = TokenType::T_BETWEEN; + + /** @deprecated use {@see TokenType::T_BOTH} */ + public const T_BOTH = TokenType::T_BOTH; + + /** @deprecated use {@see TokenType::T_BY} */ + public const T_BY = TokenType::T_BY; + + /** @deprecated use {@see TokenType::T_CASE} */ + public const T_CASE = TokenType::T_CASE; + + /** @deprecated use {@see TokenType::T_COALESCE} */ + public const T_COALESCE = TokenType::T_COALESCE; + + /** @deprecated use {@see TokenType::T_COUNT} */ + public const T_COUNT = TokenType::T_COUNT; + + /** @deprecated use {@see TokenType::T_DELETE} */ + public const T_DELETE = TokenType::T_DELETE; + + /** @deprecated use {@see TokenType::T_DESC} */ + public const T_DESC = TokenType::T_DESC; + + /** @deprecated use {@see TokenType::T_DISTINCT} */ + public const T_DISTINCT = TokenType::T_DISTINCT; + + /** @deprecated use {@see TokenType::T_ELSE} */ + public const T_ELSE = TokenType::T_ELSE; + + /** @deprecated use {@see TokenType::T_EMPTY} */ + public const T_EMPTY = TokenType::T_EMPTY; + + /** @deprecated use {@see TokenType::T_END} */ + public const T_END = TokenType::T_END; + + /** @deprecated use {@see TokenType::T_ESCAPE} */ + public const T_ESCAPE = TokenType::T_ESCAPE; + + /** @deprecated use {@see TokenType::T_EXISTS} */ + public const T_EXISTS = TokenType::T_EXISTS; + + /** @deprecated use {@see TokenType::T_FALSE} */ + public const T_FALSE = TokenType::T_FALSE; + + /** @deprecated use {@see TokenType::T_FROM} */ + public const T_FROM = TokenType::T_FROM; + + /** @deprecated use {@see TokenType::T_GROUP} */ + public const T_GROUP = TokenType::T_GROUP; + + /** @deprecated use {@see TokenType::T_HAVING} */ + public const T_HAVING = TokenType::T_HAVING; + + /** @deprecated use {@see TokenType::T_HIDDEN} */ + public const T_HIDDEN = TokenType::T_HIDDEN; + + /** @deprecated use {@see TokenType::T_IN} */ + public const T_IN = TokenType::T_IN; + + /** @deprecated use {@see TokenType::T_INDEX} */ + public const T_INDEX = TokenType::T_INDEX; + + /** @deprecated use {@see TokenType::T_INNER} */ + public const T_INNER = TokenType::T_INNER; + + /** @deprecated use {@see TokenType::T_INSTANCE} */ + public const T_INSTANCE = TokenType::T_INSTANCE; + + /** @deprecated use {@see TokenType::T_IS} */ + public const T_IS = TokenType::T_IS; + + /** @deprecated use {@see TokenType::T_JOIN} */ + public const T_JOIN = TokenType::T_JOIN; + + /** @deprecated use {@see TokenType::T_LEADING} */ + public const T_LEADING = TokenType::T_LEADING; + + /** @deprecated use {@see TokenType::T_LEFT} */ + public const T_LEFT = TokenType::T_LEFT; + + /** @deprecated use {@see TokenType::T_LIKE} */ + public const T_LIKE = TokenType::T_LIKE; + + /** @deprecated use {@see TokenType::T_MAX} */ + public const T_MAX = TokenType::T_MAX; + + /** @deprecated use {@see TokenType::T_MEMBER} */ + public const T_MEMBER = TokenType::T_MEMBER; + + /** @deprecated use {@see TokenType::T_MIN} */ + public const T_MIN = TokenType::T_MIN; + + /** @deprecated use {@see TokenType::T_NEW} */ + public const T_NEW = TokenType::T_NEW; + + /** @deprecated use {@see TokenType::T_NOT} */ + public const T_NOT = TokenType::T_NOT; + + /** @deprecated use {@see TokenType::T_NULL} */ + public const T_NULL = TokenType::T_NULL; + + /** @deprecated use {@see TokenType::T_NULLIF} */ + public const T_NULLIF = TokenType::T_NULLIF; + + /** @deprecated use {@see TokenType::T_OF} */ + public const T_OF = TokenType::T_OF; + + /** @deprecated use {@see TokenType::T_OR} */ + public const T_OR = TokenType::T_OR; + + /** @deprecated use {@see TokenType::T_ORDER} */ + public const T_ORDER = TokenType::T_ORDER; + + /** @deprecated use {@see TokenType::T_OUTER} */ + public const T_OUTER = TokenType::T_OUTER; + + /** @deprecated use {@see TokenType::T_PARTIAL} */ + public const T_PARTIAL = TokenType::T_PARTIAL; + + /** @deprecated use {@see TokenType::T_SELECT} */ + public const T_SELECT = TokenType::T_SELECT; + + /** @deprecated use {@see TokenType::T_SET} */ + public const T_SET = TokenType::T_SET; + + /** @deprecated use {@see TokenType::T_SOME} */ + public const T_SOME = TokenType::T_SOME; + + /** @deprecated use {@see TokenType::T_SUM} */ + public const T_SUM = TokenType::T_SUM; + + /** @deprecated use {@see TokenType::T_THEN} */ + public const T_THEN = TokenType::T_THEN; + + /** @deprecated use {@see TokenType::T_TRAILING} */ + public const T_TRAILING = TokenType::T_TRAILING; + + /** @deprecated use {@see TokenType::T_TRUE} */ + public const T_TRUE = TokenType::T_TRUE; + + /** @deprecated use {@see TokenType::T_UPDATE} */ + public const T_UPDATE = TokenType::T_UPDATE; + + /** @deprecated use {@see TokenType::T_WHEN} */ + public const T_WHEN = TokenType::T_WHEN; + + /** @deprecated use {@see TokenType::T_WHERE} */ + public const T_WHERE = TokenType::T_WHERE; + + /** @deprecated use {@see TokenType::T_WITH} */ + public const T_WITH = TokenType::T_WITH; /** * Creates a new query scanner object. @@ -169,7 +323,7 @@ protected function getType(&$value) // Recognize identifiers, aliased or qualified names case ctype_alpha($value[0]) || $value[0] === '_' || $value[0] === '\\': - $name = 'Doctrine\ORM\Query\Lexer::T_' . strtoupper($value); + $name = 'Doctrine\ORM\Query\TokenType::T_' . strtoupper($value); if (defined($name)) { $type = constant($name); diff --git a/src/Query/Parser.php b/src/Query/Parser.php index 7e69b4865d0..949a8f4ebdd 100644 --- a/src/Query/Parser.php +++ b/src/Query/Parser.php @@ -36,7 +36,7 @@ * Parses a DQL query, reports any errors in it, and generates an AST. * * @psalm-import-type AssociationMapping from ClassMetadata - * @psalm-type DqlToken = Token + * @psalm-type DqlToken = Token * @psalm-type QueryComponent = array{ * metadata?: ClassMetadata, * parent?: string|null, @@ -290,7 +290,7 @@ public function getAST() * If they match, updates the lookahead token; otherwise raises a syntax * error. * - * @param Lexer::T_* $token The token type. + * @param TokenType::T_* $token The token type. * * @return void * @@ -308,17 +308,17 @@ public function match($token) } // If parameter is not identifier (1-99) must be exact match - if ($token < Lexer::T_IDENTIFIER) { + if ($token < TokenType::T_IDENTIFIER) { $this->syntaxError($this->lexer->getLiteral($token)); } // If parameter is keyword (200+) must be exact match - if ($token > Lexer::T_IDENTIFIER) { + if ($token > TokenType::T_IDENTIFIER) { $this->syntaxError($this->lexer->getLiteral($token)); } // If parameter is T_IDENTIFIER, then matches T_IDENTIFIER (100) and keywords (200+) - if ($token === Lexer::T_IDENTIFIER && $lookaheadType < Lexer::T_IDENTIFIER) { + if ($token === TokenType::T_IDENTIFIER && $lookaheadType < TokenType::T_IDENTIFIER) { $this->syntaxError($this->lexer->getLiteral($token)); } @@ -510,11 +510,11 @@ private function peekBeyondClosingParenthesis(bool $resetPeek = true) while ($numUnmatched > 0 && $token !== null) { switch ($token->type) { - case Lexer::T_OPEN_PARENTHESIS: + case TokenType::T_OPEN_PARENTHESIS: ++$numUnmatched; break; - case Lexer::T_CLOSE_PARENTHESIS: + case TokenType::T_CLOSE_PARENTHESIS: --$numUnmatched; break; @@ -539,7 +539,7 @@ private function peekBeyondClosingParenthesis(bool $resetPeek = true) */ private function isMathOperator($token): bool { - return $token !== null && in_array($token->type, [Lexer::T_PLUS, Lexer::T_MINUS, Lexer::T_DIVIDE, Lexer::T_MULTIPLY], true); + return $token !== null && in_array($token->type, [TokenType::T_PLUS, TokenType::T_MINUS, TokenType::T_DIVIDE, TokenType::T_MULTIPLY], true); } /** @@ -555,13 +555,13 @@ private function isFunction(): bool $this->lexer->resetPeek(); - return $lookaheadType >= Lexer::T_IDENTIFIER && $peek !== null && $peek->type === Lexer::T_OPEN_PARENTHESIS; + return $lookaheadType >= TokenType::T_IDENTIFIER && $peek !== null && $peek->type === TokenType::T_OPEN_PARENTHESIS; } /** * Checks whether the given token type indicates an aggregate function. * - * @psalm-param Lexer::T_* $tokenType + * @psalm-param TokenType::T_* $tokenType * * @return bool TRUE if the token type is an aggregate function, FALSE otherwise. */ @@ -569,7 +569,7 @@ private function isAggregateFunction(int $tokenType): bool { return in_array( $tokenType, - [Lexer::T_AVG, Lexer::T_MIN, Lexer::T_MAX, Lexer::T_SUM, Lexer::T_COUNT], + [TokenType::T_AVG, TokenType::T_MIN, TokenType::T_MAX, TokenType::T_SUM, TokenType::T_COUNT], true ); } @@ -583,7 +583,7 @@ private function isNextAllAnySome(): bool return in_array( $this->lexer->lookahead->type, - [Lexer::T_ALL, Lexer::T_ANY, Lexer::T_SOME], + [TokenType::T_ALL, TokenType::T_ANY, TokenType::T_SOME], true ); } @@ -846,15 +846,15 @@ public function QueryLanguage() $this->lexer->moveNext(); switch ($this->lexer->lookahead->type ?? null) { - case Lexer::T_SELECT: + case TokenType::T_SELECT: $statement = $this->SelectStatement(); break; - case Lexer::T_UPDATE: + case TokenType::T_UPDATE: $statement = $this->UpdateStatement(); break; - case Lexer::T_DELETE: + case TokenType::T_DELETE: $statement = $this->DeleteStatement(); break; @@ -880,10 +880,10 @@ public function SelectStatement() { $selectStatement = new AST\SelectStatement($this->SelectClause(), $this->FromClause()); - $selectStatement->whereClause = $this->lexer->isNextToken(Lexer::T_WHERE) ? $this->WhereClause() : null; - $selectStatement->groupByClause = $this->lexer->isNextToken(Lexer::T_GROUP) ? $this->GroupByClause() : null; - $selectStatement->havingClause = $this->lexer->isNextToken(Lexer::T_HAVING) ? $this->HavingClause() : null; - $selectStatement->orderByClause = $this->lexer->isNextToken(Lexer::T_ORDER) ? $this->OrderByClause() : null; + $selectStatement->whereClause = $this->lexer->isNextToken(TokenType::T_WHERE) ? $this->WhereClause() : null; + $selectStatement->groupByClause = $this->lexer->isNextToken(TokenType::T_GROUP) ? $this->GroupByClause() : null; + $selectStatement->havingClause = $this->lexer->isNextToken(TokenType::T_HAVING) ? $this->HavingClause() : null; + $selectStatement->orderByClause = $this->lexer->isNextToken(TokenType::T_ORDER) ? $this->OrderByClause() : null; return $selectStatement; } @@ -897,7 +897,7 @@ public function UpdateStatement() { $updateStatement = new AST\UpdateStatement($this->UpdateClause()); - $updateStatement->whereClause = $this->lexer->isNextToken(Lexer::T_WHERE) ? $this->WhereClause() : null; + $updateStatement->whereClause = $this->lexer->isNextToken(TokenType::T_WHERE) ? $this->WhereClause() : null; return $updateStatement; } @@ -911,7 +911,7 @@ public function DeleteStatement() { $deleteStatement = new AST\DeleteStatement($this->DeleteClause()); - $deleteStatement->whereClause = $this->lexer->isNextToken(Lexer::T_WHERE) ? $this->WhereClause() : null; + $deleteStatement->whereClause = $this->lexer->isNextToken(TokenType::T_WHERE) ? $this->WhereClause() : null; return $deleteStatement; } @@ -923,7 +923,7 @@ public function DeleteStatement() */ public function IdentificationVariable() { - $this->match(Lexer::T_IDENTIFIER); + $this->match(TokenType::T_IDENTIFIER); assert($this->lexer->token !== null); $identVariable = $this->lexer->token->value; @@ -944,7 +944,7 @@ public function IdentificationVariable() */ public function AliasIdentificationVariable() { - $this->match(Lexer::T_IDENTIFIER); + $this->match(TokenType::T_IDENTIFIER); assert($this->lexer->token !== null); $aliasIdentVariable = $this->lexer->token->value; @@ -967,21 +967,21 @@ public function AliasIdentificationVariable() */ public function AbstractSchemaName() { - if ($this->lexer->isNextToken(Lexer::T_FULLY_QUALIFIED_NAME)) { - $this->match(Lexer::T_FULLY_QUALIFIED_NAME); + if ($this->lexer->isNextToken(TokenType::T_FULLY_QUALIFIED_NAME)) { + $this->match(TokenType::T_FULLY_QUALIFIED_NAME); assert($this->lexer->token !== null); return $this->lexer->token->value; } - if ($this->lexer->isNextToken(Lexer::T_IDENTIFIER)) { - $this->match(Lexer::T_IDENTIFIER); + if ($this->lexer->isNextToken(TokenType::T_IDENTIFIER)) { + $this->match(TokenType::T_IDENTIFIER); assert($this->lexer->token !== null); return $this->lexer->token->value; } - $this->match(Lexer::T_ALIASED_NAME); + $this->match(TokenType::T_ALIASED_NAME); assert($this->lexer->token !== null); @@ -1022,7 +1022,7 @@ private function validateAbstractSchemaName(string $schemaName): void */ public function AliasResultVariable() { - $this->match(Lexer::T_IDENTIFIER); + $this->match(TokenType::T_IDENTIFIER); assert($this->lexer->token !== null); $resultVariable = $this->lexer->token->value; @@ -1045,7 +1045,7 @@ public function AliasResultVariable() */ public function ResultVariable() { - $this->match(Lexer::T_IDENTIFIER); + $this->match(TokenType::T_IDENTIFIER); assert($this->lexer->token !== null); $resultVariable = $this->lexer->token->value; @@ -1075,8 +1075,8 @@ public function JoinAssociationPathExpression() ); } - $this->match(Lexer::T_DOT); - $this->match(Lexer::T_IDENTIFIER); + $this->match(TokenType::T_DOT); + $this->match(TokenType::T_IDENTIFIER); assert($this->lexer->token !== null); $field = $this->lexer->token->value; @@ -1108,15 +1108,15 @@ public function PathExpression($expectedTypes) $field = null; assert($this->lexer->token !== null); - if ($this->lexer->isNextToken(Lexer::T_DOT)) { - $this->match(Lexer::T_DOT); - $this->match(Lexer::T_IDENTIFIER); + if ($this->lexer->isNextToken(TokenType::T_DOT)) { + $this->match(TokenType::T_DOT); + $this->match(TokenType::T_IDENTIFIER); $field = $this->lexer->token->value; - while ($this->lexer->isNextToken(Lexer::T_DOT)) { - $this->match(Lexer::T_DOT); - $this->match(Lexer::T_IDENTIFIER); + while ($this->lexer->isNextToken(TokenType::T_DOT)) { + $this->match(TokenType::T_DOT); + $this->match(TokenType::T_IDENTIFIER); $field .= '.' . $this->lexer->token->value; } } @@ -1198,11 +1198,11 @@ public function CollectionValuedPathExpression() public function SelectClause() { $isDistinct = false; - $this->match(Lexer::T_SELECT); + $this->match(TokenType::T_SELECT); // Check for DISTINCT - if ($this->lexer->isNextToken(Lexer::T_DISTINCT)) { - $this->match(Lexer::T_DISTINCT); + if ($this->lexer->isNextToken(TokenType::T_DISTINCT)) { + $this->match(TokenType::T_DISTINCT); $isDistinct = true; } @@ -1211,8 +1211,8 @@ public function SelectClause() $selectExpressions = []; $selectExpressions[] = $this->SelectExpression(); - while ($this->lexer->isNextToken(Lexer::T_COMMA)) { - $this->match(Lexer::T_COMMA); + while ($this->lexer->isNextToken(TokenType::T_COMMA)) { + $this->match(TokenType::T_COMMA); $selectExpressions[] = $this->SelectExpression(); } @@ -1228,10 +1228,10 @@ public function SelectClause() public function SimpleSelectClause() { $isDistinct = false; - $this->match(Lexer::T_SELECT); + $this->match(TokenType::T_SELECT); - if ($this->lexer->isNextToken(Lexer::T_DISTINCT)) { - $this->match(Lexer::T_DISTINCT); + if ($this->lexer->isNextToken(TokenType::T_DISTINCT)) { + $this->match(TokenType::T_DISTINCT); $isDistinct = true; } @@ -1246,7 +1246,7 @@ public function SimpleSelectClause() */ public function UpdateClause() { - $this->match(Lexer::T_UPDATE); + $this->match(TokenType::T_UPDATE); assert($this->lexer->lookahead !== null); $token = $this->lexer->lookahead; @@ -1254,8 +1254,8 @@ public function UpdateClause() $this->validateAbstractSchemaName($abstractSchemaName); - if ($this->lexer->isNextToken(Lexer::T_AS)) { - $this->match(Lexer::T_AS); + if ($this->lexer->isNextToken(TokenType::T_AS)) { + $this->match(TokenType::T_AS); } $aliasIdentificationVariable = $this->AliasIdentificationVariable(); @@ -1274,13 +1274,13 @@ public function UpdateClause() $this->queryComponents[$aliasIdentificationVariable] = $queryComponent; - $this->match(Lexer::T_SET); + $this->match(TokenType::T_SET); $updateItems = []; $updateItems[] = $this->UpdateItem(); - while ($this->lexer->isNextToken(Lexer::T_COMMA)) { - $this->match(Lexer::T_COMMA); + while ($this->lexer->isNextToken(TokenType::T_COMMA)) { + $this->match(TokenType::T_COMMA); $updateItems[] = $this->UpdateItem(); } @@ -1298,10 +1298,10 @@ public function UpdateClause() */ public function DeleteClause() { - $this->match(Lexer::T_DELETE); + $this->match(TokenType::T_DELETE); - if ($this->lexer->isNextToken(Lexer::T_FROM)) { - $this->match(Lexer::T_FROM); + if ($this->lexer->isNextToken(TokenType::T_FROM)) { + $this->match(TokenType::T_FROM); } assert($this->lexer->lookahead !== null); @@ -1312,11 +1312,11 @@ public function DeleteClause() $deleteClause = new AST\DeleteClause($abstractSchemaName); - if ($this->lexer->isNextToken(Lexer::T_AS)) { - $this->match(Lexer::T_AS); + if ($this->lexer->isNextToken(TokenType::T_AS)) { + $this->match(TokenType::T_AS); } - $aliasIdentificationVariable = $this->lexer->isNextToken(Lexer::T_IDENTIFIER) + $aliasIdentificationVariable = $this->lexer->isNextToken(TokenType::T_IDENTIFIER) ? $this->AliasIdentificationVariable() : 'alias_should_have_been_set'; @@ -1345,13 +1345,13 @@ public function DeleteClause() */ public function FromClause() { - $this->match(Lexer::T_FROM); + $this->match(TokenType::T_FROM); $identificationVariableDeclarations = []; $identificationVariableDeclarations[] = $this->IdentificationVariableDeclaration(); - while ($this->lexer->isNextToken(Lexer::T_COMMA)) { - $this->match(Lexer::T_COMMA); + while ($this->lexer->isNextToken(TokenType::T_COMMA)) { + $this->match(TokenType::T_COMMA); $identificationVariableDeclarations[] = $this->IdentificationVariableDeclaration(); } @@ -1366,13 +1366,13 @@ public function FromClause() */ public function SubselectFromClause() { - $this->match(Lexer::T_FROM); + $this->match(TokenType::T_FROM); $identificationVariables = []; $identificationVariables[] = $this->SubselectIdentificationVariableDeclaration(); - while ($this->lexer->isNextToken(Lexer::T_COMMA)) { - $this->match(Lexer::T_COMMA); + while ($this->lexer->isNextToken(TokenType::T_COMMA)) { + $this->match(TokenType::T_COMMA); $identificationVariables[] = $this->SubselectIdentificationVariableDeclaration(); } @@ -1387,7 +1387,7 @@ public function SubselectFromClause() */ public function WhereClause() { - $this->match(Lexer::T_WHERE); + $this->match(TokenType::T_WHERE); return new AST\WhereClause($this->ConditionalExpression()); } @@ -1399,7 +1399,7 @@ public function WhereClause() */ public function HavingClause() { - $this->match(Lexer::T_HAVING); + $this->match(TokenType::T_HAVING); return new AST\HavingClause($this->ConditionalExpression()); } @@ -1411,13 +1411,13 @@ public function HavingClause() */ public function GroupByClause() { - $this->match(Lexer::T_GROUP); - $this->match(Lexer::T_BY); + $this->match(TokenType::T_GROUP); + $this->match(TokenType::T_BY); $groupByItems = [$this->GroupByItem()]; - while ($this->lexer->isNextToken(Lexer::T_COMMA)) { - $this->match(Lexer::T_COMMA); + while ($this->lexer->isNextToken(TokenType::T_COMMA)) { + $this->match(TokenType::T_COMMA); $groupByItems[] = $this->GroupByItem(); } @@ -1432,14 +1432,14 @@ public function GroupByClause() */ public function OrderByClause() { - $this->match(Lexer::T_ORDER); - $this->match(Lexer::T_BY); + $this->match(TokenType::T_ORDER); + $this->match(TokenType::T_BY); $orderByItems = []; $orderByItems[] = $this->OrderByItem(); - while ($this->lexer->isNextToken(Lexer::T_COMMA)) { - $this->match(Lexer::T_COMMA); + while ($this->lexer->isNextToken(TokenType::T_COMMA)) { + $this->match(TokenType::T_COMMA); $orderByItems[] = $this->OrderByItem(); } @@ -1459,10 +1459,10 @@ public function Subselect() $subselect = new AST\Subselect($this->SimpleSelectClause(), $this->SubselectFromClause()); - $subselect->whereClause = $this->lexer->isNextToken(Lexer::T_WHERE) ? $this->WhereClause() : null; - $subselect->groupByClause = $this->lexer->isNextToken(Lexer::T_GROUP) ? $this->GroupByClause() : null; - $subselect->havingClause = $this->lexer->isNextToken(Lexer::T_HAVING) ? $this->HavingClause() : null; - $subselect->orderByClause = $this->lexer->isNextToken(Lexer::T_ORDER) ? $this->OrderByClause() : null; + $subselect->whereClause = $this->lexer->isNextToken(TokenType::T_WHERE) ? $this->WhereClause() : null; + $subselect->groupByClause = $this->lexer->isNextToken(TokenType::T_GROUP) ? $this->GroupByClause() : null; + $subselect->havingClause = $this->lexer->isNextToken(TokenType::T_HAVING) ? $this->HavingClause() : null; + $subselect->orderByClause = $this->lexer->isNextToken(TokenType::T_ORDER) ? $this->OrderByClause() : null; // Decrease query nesting level $this->nestingLevel--; @@ -1479,7 +1479,7 @@ public function UpdateItem() { $pathExpr = $this->SingleValuedPathExpression(); - $this->match(Lexer::T_EQUALS); + $this->match(TokenType::T_EQUALS); return new AST\UpdateItem($pathExpr, $this->NewValue()); } @@ -1494,7 +1494,7 @@ public function GroupByItem() // We need to check if we are in a IdentificationVariable or SingleValuedPathExpression $glimpse = $this->lexer->glimpse(); - if ($glimpse !== null && $glimpse->type === Lexer::T_DOT) { + if ($glimpse !== null && $glimpse->type === TokenType::T_DOT) { return $this->SingleValuedPathExpression(); } @@ -1536,7 +1536,7 @@ public function OrderByItem() $expr = $this->SimpleArithmeticExpression(); break; - case $glimpse !== null && $glimpse->type === Lexer::T_DOT: + case $glimpse !== null && $glimpse->type === TokenType::T_DOT: $expr = $this->SingleValuedPathExpression(); break; @@ -1544,7 +1544,7 @@ public function OrderByItem() $expr = $this->ScalarExpression(); break; - case $this->lexer->lookahead->type === Lexer::T_CASE: + case $this->lexer->lookahead->type === TokenType::T_CASE: $expr = $this->CaseExpression(); break; @@ -1561,13 +1561,13 @@ public function OrderByItem() $item = new AST\OrderByItem($expr); switch (true) { - case $this->lexer->isNextToken(Lexer::T_DESC): - $this->match(Lexer::T_DESC); + case $this->lexer->isNextToken(TokenType::T_DESC): + $this->match(TokenType::T_DESC); $type = 'DESC'; break; - case $this->lexer->isNextToken(Lexer::T_ASC): - $this->match(Lexer::T_ASC); + case $this->lexer->isNextToken(TokenType::T_ASC): + $this->match(TokenType::T_ASC); break; default: @@ -1594,14 +1594,14 @@ public function OrderByItem() */ public function NewValue() { - if ($this->lexer->isNextToken(Lexer::T_NULL)) { - $this->match(Lexer::T_NULL); + if ($this->lexer->isNextToken(TokenType::T_NULL)) { + $this->match(TokenType::T_NULL); return null; } - if ($this->lexer->isNextToken(Lexer::T_INPUT_PARAMETER)) { - $this->match(Lexer::T_INPUT_PARAMETER); + if ($this->lexer->isNextToken(TokenType::T_INPUT_PARAMETER)) { + $this->match(TokenType::T_INPUT_PARAMETER); assert($this->lexer->token !== null); return new AST\InputParameter($this->lexer->token->value); @@ -1619,16 +1619,16 @@ public function IdentificationVariableDeclaration() { $joins = []; $rangeVariableDeclaration = $this->RangeVariableDeclaration(); - $indexBy = $this->lexer->isNextToken(Lexer::T_INDEX) + $indexBy = $this->lexer->isNextToken(TokenType::T_INDEX) ? $this->IndexBy() : null; $rangeVariableDeclaration->isRoot = true; while ( - $this->lexer->isNextToken(Lexer::T_LEFT) || - $this->lexer->isNextToken(Lexer::T_INNER) || - $this->lexer->isNextToken(Lexer::T_JOIN) + $this->lexer->isNextToken(TokenType::T_LEFT) || + $this->lexer->isNextToken(TokenType::T_INNER) || + $this->lexer->isNextToken(TokenType::T_JOIN) ) { $joins[] = $this->Join(); } @@ -1663,11 +1663,11 @@ public function SubselectIdentificationVariableDeclaration() $glimpse = $this->lexer->glimpse(); - if ($glimpse->type == Lexer::T_DOT) { + if ($glimpse->type == TokenType::T_DOT) { $associationPathExpression = $this->AssociationPathExpression(); - if ($this->lexer->isNextToken(Lexer::T_AS)) { - $this->match(Lexer::T_AS); + if ($this->lexer->isNextToken(TokenType::T_AS)) { + $this->match(TokenType::T_AS); } $aliasIdentificationVariable = $this->AliasIdentificationVariable(); @@ -1711,34 +1711,34 @@ public function Join() $joinType = AST\Join::JOIN_TYPE_INNER; switch (true) { - case $this->lexer->isNextToken(Lexer::T_LEFT): - $this->match(Lexer::T_LEFT); + case $this->lexer->isNextToken(TokenType::T_LEFT): + $this->match(TokenType::T_LEFT); $joinType = AST\Join::JOIN_TYPE_LEFT; // Possible LEFT OUTER join - if ($this->lexer->isNextToken(Lexer::T_OUTER)) { - $this->match(Lexer::T_OUTER); + if ($this->lexer->isNextToken(TokenType::T_OUTER)) { + $this->match(TokenType::T_OUTER); $joinType = AST\Join::JOIN_TYPE_LEFTOUTER; } break; - case $this->lexer->isNextToken(Lexer::T_INNER): - $this->match(Lexer::T_INNER); + case $this->lexer->isNextToken(TokenType::T_INNER): + $this->match(TokenType::T_INNER); break; default: // Do nothing } - $this->match(Lexer::T_JOIN); + $this->match(TokenType::T_JOIN); $next = $this->lexer->glimpse(); assert($next !== null); - $joinDeclaration = $next->type === Lexer::T_DOT ? $this->JoinAssociationDeclaration() : $this->RangeVariableDeclaration(); - $adhocConditions = $this->lexer->isNextToken(Lexer::T_WITH); + $joinDeclaration = $next->type === TokenType::T_DOT ? $this->JoinAssociationDeclaration() : $this->RangeVariableDeclaration(); + $adhocConditions = $this->lexer->isNextToken(TokenType::T_WITH); $join = new AST\Join($joinType, $joinDeclaration); // Describe non-root join declaration @@ -1748,7 +1748,7 @@ public function Join() // Check for ad-hoc Join conditions if ($adhocConditions) { - $this->match(Lexer::T_WITH); + $this->match(TokenType::T_WITH); $join->conditionalExpression = $this->ConditionalExpression(); } @@ -1765,7 +1765,7 @@ public function Join() */ public function RangeVariableDeclaration() { - if ($this->lexer->isNextToken(Lexer::T_OPEN_PARENTHESIS) && $this->lexer->glimpse()->type === Lexer::T_SELECT) { + if ($this->lexer->isNextToken(TokenType::T_OPEN_PARENTHESIS) && $this->lexer->glimpse()->type === TokenType::T_SELECT) { $this->semanticalError('Subquery is not supported here', $this->lexer->token); } @@ -1773,8 +1773,8 @@ public function RangeVariableDeclaration() $this->validateAbstractSchemaName($abstractSchemaName); - if ($this->lexer->isNextToken(Lexer::T_AS)) { - $this->match(Lexer::T_AS); + if ($this->lexer->isNextToken(TokenType::T_AS)) { + $this->match(TokenType::T_AS); } assert($this->lexer->lookahead !== null); @@ -1806,14 +1806,14 @@ public function JoinAssociationDeclaration() { $joinAssociationPathExpression = $this->JoinAssociationPathExpression(); - if ($this->lexer->isNextToken(Lexer::T_AS)) { - $this->match(Lexer::T_AS); + if ($this->lexer->isNextToken(TokenType::T_AS)) { + $this->match(TokenType::T_AS); } assert($this->lexer->lookahead !== null); $aliasIdentificationVariable = $this->AliasIdentificationVariable(); - $indexBy = $this->lexer->isNextToken(Lexer::T_INDEX) ? $this->IndexBy() : null; + $indexBy = $this->lexer->isNextToken(TokenType::T_INDEX) ? $this->IndexBy() : null; $identificationVariable = $joinAssociationPathExpression->identificationVariable; $field = $joinAssociationPathExpression->associationField; @@ -1850,44 +1850,44 @@ public function PartialObjectExpression() 'PARTIAL syntax in DQL is deprecated.' ); - $this->match(Lexer::T_PARTIAL); + $this->match(TokenType::T_PARTIAL); $partialFieldSet = []; $identificationVariable = $this->IdentificationVariable(); - $this->match(Lexer::T_DOT); - $this->match(Lexer::T_OPEN_CURLY_BRACE); - $this->match(Lexer::T_IDENTIFIER); + $this->match(TokenType::T_DOT); + $this->match(TokenType::T_OPEN_CURLY_BRACE); + $this->match(TokenType::T_IDENTIFIER); assert($this->lexer->token !== null); $field = $this->lexer->token->value; // First field in partial expression might be embeddable property - while ($this->lexer->isNextToken(Lexer::T_DOT)) { - $this->match(Lexer::T_DOT); - $this->match(Lexer::T_IDENTIFIER); + while ($this->lexer->isNextToken(TokenType::T_DOT)) { + $this->match(TokenType::T_DOT); + $this->match(TokenType::T_IDENTIFIER); $field .= '.' . $this->lexer->token->value; } $partialFieldSet[] = $field; - while ($this->lexer->isNextToken(Lexer::T_COMMA)) { - $this->match(Lexer::T_COMMA); - $this->match(Lexer::T_IDENTIFIER); + while ($this->lexer->isNextToken(TokenType::T_COMMA)) { + $this->match(TokenType::T_COMMA); + $this->match(TokenType::T_IDENTIFIER); $field = $this->lexer->token->value; - while ($this->lexer->isNextToken(Lexer::T_DOT)) { - $this->match(Lexer::T_DOT); - $this->match(Lexer::T_IDENTIFIER); + while ($this->lexer->isNextToken(TokenType::T_DOT)) { + $this->match(TokenType::T_DOT); + $this->match(TokenType::T_IDENTIFIER); $field .= '.' . $this->lexer->token->value; } $partialFieldSet[] = $field; } - $this->match(Lexer::T_CLOSE_CURLY_BRACE); + $this->match(TokenType::T_CLOSE_CURLY_BRACE); $partialObjectExpression = new AST\PartialObjectExpression($identificationVariable, $partialFieldSet); @@ -1908,22 +1908,22 @@ public function PartialObjectExpression() */ public function NewObjectExpression() { - $this->match(Lexer::T_NEW); + $this->match(TokenType::T_NEW); $className = $this->AbstractSchemaName(); // note that this is not yet validated $token = $this->lexer->token; - $this->match(Lexer::T_OPEN_PARENTHESIS); + $this->match(TokenType::T_OPEN_PARENTHESIS); $args[] = $this->NewObjectArg(); - while ($this->lexer->isNextToken(Lexer::T_COMMA)) { - $this->match(Lexer::T_COMMA); + while ($this->lexer->isNextToken(TokenType::T_COMMA)) { + $this->match(TokenType::T_COMMA); $args[] = $this->NewObjectArg(); } - $this->match(Lexer::T_CLOSE_PARENTHESIS); + $this->match(TokenType::T_CLOSE_PARENTHESIS); $expression = new AST\NewObjectExpression($className, $args); @@ -1949,10 +1949,10 @@ public function NewObjectArg() $peek = $this->lexer->glimpse(); assert($peek !== null); - if ($token->type === Lexer::T_OPEN_PARENTHESIS && $peek->type === Lexer::T_SELECT) { - $this->match(Lexer::T_OPEN_PARENTHESIS); + if ($token->type === TokenType::T_OPEN_PARENTHESIS && $peek->type === TokenType::T_SELECT) { + $this->match(TokenType::T_OPEN_PARENTHESIS); $expression = $this->Subselect(); - $this->match(Lexer::T_CLOSE_PARENTHESIS); + $this->match(TokenType::T_CLOSE_PARENTHESIS); return $expression; } @@ -1967,8 +1967,8 @@ public function NewObjectArg() */ public function IndexBy() { - $this->match(Lexer::T_INDEX); - $this->match(Lexer::T_BY); + $this->match(TokenType::T_INDEX); + $this->match(TokenType::T_BY); $pathExpr = $this->SingleValuedPathExpression(); // Add the INDEX BY info to the query component @@ -1992,23 +1992,23 @@ public function ScalarExpression() $peek = $this->lexer->glimpse(); switch (true) { - case $lookahead === Lexer::T_INTEGER: - case $lookahead === Lexer::T_FLOAT: + case $lookahead === TokenType::T_INTEGER: + case $lookahead === TokenType::T_FLOAT: // SimpleArithmeticExpression : (- u.value ) or ( + u.value ) or ( - 1 ) or ( + 1 ) - case $lookahead === Lexer::T_MINUS: - case $lookahead === Lexer::T_PLUS: + case $lookahead === TokenType::T_MINUS: + case $lookahead === TokenType::T_PLUS: return $this->SimpleArithmeticExpression(); - case $lookahead === Lexer::T_STRING: + case $lookahead === TokenType::T_STRING: return $this->StringPrimary(); - case $lookahead === Lexer::T_TRUE: - case $lookahead === Lexer::T_FALSE: + case $lookahead === TokenType::T_TRUE: + case $lookahead === TokenType::T_FALSE: $this->match($lookahead); return new AST\Literal(AST\Literal::BOOLEAN, $this->lexer->token->value); - case $lookahead === Lexer::T_INPUT_PARAMETER: + case $lookahead === TokenType::T_INPUT_PARAMETER: switch (true) { case $this->isMathOperator($peek): // :param + u.value @@ -2017,14 +2017,14 @@ public function ScalarExpression() default: return $this->InputParameter(); } - case $lookahead === Lexer::T_CASE: - case $lookahead === Lexer::T_COALESCE: - case $lookahead === Lexer::T_NULLIF: + case $lookahead === TokenType::T_CASE: + case $lookahead === TokenType::T_COALESCE: + case $lookahead === TokenType::T_NULLIF: // Since NULLIF and COALESCE can be identified as a function, // we need to check these before checking for FunctionDeclaration return $this->CaseExpression(); - case $lookahead === Lexer::T_OPEN_PARENTHESIS: + case $lookahead === TokenType::T_OPEN_PARENTHESIS: return $this->SimpleArithmeticExpression(); // this check must be done before checking for a filed path expression @@ -2043,7 +2043,7 @@ public function ScalarExpression() break; // it is no function, so it must be a field path - case $lookahead === Lexer::T_IDENTIFIER: + case $lookahead === TokenType::T_IDENTIFIER: $this->lexer->peek(); // lookahead => '.' $this->lexer->peek(); // lookahead => token after '.' $peek = $this->lexer->peek(); // lookahead => token after the token after the '.' @@ -2078,18 +2078,18 @@ public function CaseExpression() $lookahead = $this->lexer->lookahead->type; switch ($lookahead) { - case Lexer::T_NULLIF: + case TokenType::T_NULLIF: return $this->NullIfExpression(); - case Lexer::T_COALESCE: + case TokenType::T_COALESCE: return $this->CoalesceExpression(); - case Lexer::T_CASE: + case TokenType::T_CASE: $this->lexer->resetPeek(); $peek = $this->lexer->peek(); assert($peek !== null); - if ($peek->type === Lexer::T_WHEN) { + if ($peek->type === TokenType::T_WHEN) { return $this->GeneralCaseExpression(); } @@ -2110,20 +2110,20 @@ public function CaseExpression() */ public function CoalesceExpression() { - $this->match(Lexer::T_COALESCE); - $this->match(Lexer::T_OPEN_PARENTHESIS); + $this->match(TokenType::T_COALESCE); + $this->match(TokenType::T_OPEN_PARENTHESIS); // Process ScalarExpressions (1..N) $scalarExpressions = []; $scalarExpressions[] = $this->ScalarExpression(); - while ($this->lexer->isNextToken(Lexer::T_COMMA)) { - $this->match(Lexer::T_COMMA); + while ($this->lexer->isNextToken(TokenType::T_COMMA)) { + $this->match(TokenType::T_COMMA); $scalarExpressions[] = $this->ScalarExpression(); } - $this->match(Lexer::T_CLOSE_PARENTHESIS); + $this->match(TokenType::T_CLOSE_PARENTHESIS); return new AST\CoalesceExpression($scalarExpressions); } @@ -2135,14 +2135,14 @@ public function CoalesceExpression() */ public function NullIfExpression() { - $this->match(Lexer::T_NULLIF); - $this->match(Lexer::T_OPEN_PARENTHESIS); + $this->match(TokenType::T_NULLIF); + $this->match(TokenType::T_OPEN_PARENTHESIS); $firstExpression = $this->ScalarExpression(); - $this->match(Lexer::T_COMMA); + $this->match(TokenType::T_COMMA); $secondExpression = $this->ScalarExpression(); - $this->match(Lexer::T_CLOSE_PARENTHESIS); + $this->match(TokenType::T_CLOSE_PARENTHESIS); return new AST\NullIfExpression($firstExpression, $secondExpression); } @@ -2154,18 +2154,18 @@ public function NullIfExpression() */ public function GeneralCaseExpression() { - $this->match(Lexer::T_CASE); + $this->match(TokenType::T_CASE); // Process WhenClause (1..N) $whenClauses = []; do { $whenClauses[] = $this->WhenClause(); - } while ($this->lexer->isNextToken(Lexer::T_WHEN)); + } while ($this->lexer->isNextToken(TokenType::T_WHEN)); - $this->match(Lexer::T_ELSE); + $this->match(TokenType::T_ELSE); $scalarExpression = $this->ScalarExpression(); - $this->match(Lexer::T_END); + $this->match(TokenType::T_END); return new AST\GeneralCaseExpression($whenClauses, $scalarExpression); } @@ -2178,7 +2178,7 @@ public function GeneralCaseExpression() */ public function SimpleCaseExpression() { - $this->match(Lexer::T_CASE); + $this->match(TokenType::T_CASE); $caseOperand = $this->StateFieldPathExpression(); // Process SimpleWhenClause (1..N) @@ -2186,11 +2186,11 @@ public function SimpleCaseExpression() do { $simpleWhenClauses[] = $this->SimpleWhenClause(); - } while ($this->lexer->isNextToken(Lexer::T_WHEN)); + } while ($this->lexer->isNextToken(TokenType::T_WHEN)); - $this->match(Lexer::T_ELSE); + $this->match(TokenType::T_ELSE); $scalarExpression = $this->ScalarExpression(); - $this->match(Lexer::T_END); + $this->match(TokenType::T_END); return new AST\SimpleCaseExpression($caseOperand, $simpleWhenClauses, $scalarExpression); } @@ -2202,9 +2202,9 @@ public function SimpleCaseExpression() */ public function WhenClause() { - $this->match(Lexer::T_WHEN); + $this->match(TokenType::T_WHEN); $conditionalExpression = $this->ConditionalExpression(); - $this->match(Lexer::T_THEN); + $this->match(TokenType::T_THEN); return new AST\WhenClause($conditionalExpression, $this->ScalarExpression()); } @@ -2216,9 +2216,9 @@ public function WhenClause() */ public function SimpleWhenClause() { - $this->match(Lexer::T_WHEN); + $this->match(TokenType::T_WHEN); $conditionalExpression = $this->ScalarExpression(); - $this->match(Lexer::T_THEN); + $this->match(TokenType::T_THEN); return new AST\SimpleWhenClause($conditionalExpression, $this->ScalarExpression()); } @@ -2242,19 +2242,19 @@ public function SelectExpression() switch (true) { // ScalarExpression (u.name) - case $lookaheadType === Lexer::T_IDENTIFIER && $peek->type === Lexer::T_DOT: + case $lookaheadType === TokenType::T_IDENTIFIER && $peek->type === TokenType::T_DOT: $expression = $this->ScalarExpression(); break; // IdentificationVariable (u) - case $lookaheadType === Lexer::T_IDENTIFIER && $peek->type !== Lexer::T_OPEN_PARENTHESIS: + case $lookaheadType === TokenType::T_IDENTIFIER && $peek->type !== TokenType::T_OPEN_PARENTHESIS: $expression = $identVariable = $this->IdentificationVariable(); break; // CaseExpression (CASE ... or NULLIF(...) or COALESCE(...)) - case $lookaheadType === Lexer::T_CASE: - case $lookaheadType === Lexer::T_COALESCE: - case $lookaheadType === Lexer::T_NULLIF: + case $lookaheadType === TokenType::T_CASE: + case $lookaheadType === TokenType::T_COALESCE: + case $lookaheadType === TokenType::T_NULLIF: $expression = $this->CaseExpression(); break; @@ -2277,31 +2277,31 @@ public function SelectExpression() break; // PartialObjectExpression (PARTIAL u.{id, name}) - case $lookaheadType === Lexer::T_PARTIAL: + case $lookaheadType === TokenType::T_PARTIAL: $expression = $this->PartialObjectExpression(); $identVariable = $expression->identificationVariable; break; // Subselect - case $lookaheadType === Lexer::T_OPEN_PARENTHESIS && $peek->type === Lexer::T_SELECT: - $this->match(Lexer::T_OPEN_PARENTHESIS); + case $lookaheadType === TokenType::T_OPEN_PARENTHESIS && $peek->type === TokenType::T_SELECT: + $this->match(TokenType::T_OPEN_PARENTHESIS); $expression = $this->Subselect(); - $this->match(Lexer::T_CLOSE_PARENTHESIS); + $this->match(TokenType::T_CLOSE_PARENTHESIS); break; // Shortcut: ScalarExpression => SimpleArithmeticExpression - case $lookaheadType === Lexer::T_OPEN_PARENTHESIS: - case $lookaheadType === Lexer::T_INTEGER: - case $lookaheadType === Lexer::T_STRING: - case $lookaheadType === Lexer::T_FLOAT: + case $lookaheadType === TokenType::T_OPEN_PARENTHESIS: + case $lookaheadType === TokenType::T_INTEGER: + case $lookaheadType === TokenType::T_STRING: + case $lookaheadType === TokenType::T_FLOAT: // SimpleArithmeticExpression : (- u.value ) or ( + u.value ) - case $lookaheadType === Lexer::T_MINUS: - case $lookaheadType === Lexer::T_PLUS: + case $lookaheadType === TokenType::T_MINUS: + case $lookaheadType === TokenType::T_PLUS: $expression = $this->SimpleArithmeticExpression(); break; // NewObjectExpression (New ClassName(id, name)) - case $lookaheadType === Lexer::T_NEW: + case $lookaheadType === TokenType::T_NEW: $expression = $this->NewObjectExpression(); break; @@ -2315,23 +2315,23 @@ public function SelectExpression() // [["AS"] ["HIDDEN"] AliasResultVariable] $mustHaveAliasResultVariable = false; - if ($this->lexer->isNextToken(Lexer::T_AS)) { - $this->match(Lexer::T_AS); + if ($this->lexer->isNextToken(TokenType::T_AS)) { + $this->match(TokenType::T_AS); $mustHaveAliasResultVariable = true; } $hiddenAliasResultVariable = false; - if ($this->lexer->isNextToken(Lexer::T_HIDDEN)) { - $this->match(Lexer::T_HIDDEN); + if ($this->lexer->isNextToken(TokenType::T_HIDDEN)) { + $this->match(TokenType::T_HIDDEN); $hiddenAliasResultVariable = true; } $aliasResultVariable = null; - if ($mustHaveAliasResultVariable || $this->lexer->isNextToken(Lexer::T_IDENTIFIER)) { + if ($mustHaveAliasResultVariable || $this->lexer->isNextToken(TokenType::T_IDENTIFIER)) { assert($expression instanceof AST\Node || is_string($expression)); $token = $this->lexer->lookahead; $aliasResultVariable = $this->AliasResultVariable(); @@ -2370,14 +2370,14 @@ public function SimpleSelectExpression() assert($peek !== null); switch ($this->lexer->lookahead->type) { - case Lexer::T_IDENTIFIER: + case TokenType::T_IDENTIFIER: switch (true) { - case $peek->type === Lexer::T_DOT: + case $peek->type === TokenType::T_DOT: $expression = $this->StateFieldPathExpression(); return new AST\SimpleSelectExpression($expression); - case $peek->type !== Lexer::T_OPEN_PARENTHESIS: + case $peek->type !== TokenType::T_OPEN_PARENTHESIS: $expression = $this->IdentificationVariable(); return new AST\SimpleSelectExpression($expression); @@ -2402,8 +2402,8 @@ public function SimpleSelectExpression() break; - case Lexer::T_OPEN_PARENTHESIS: - if ($peek->type !== Lexer::T_SELECT) { + case TokenType::T_OPEN_PARENTHESIS: + if ($peek->type !== TokenType::T_SELECT) { // Shortcut: ScalarExpression => SimpleArithmeticExpression $expression = $this->SimpleArithmeticExpression(); @@ -2411,9 +2411,9 @@ public function SimpleSelectExpression() } // Subselect - $this->match(Lexer::T_OPEN_PARENTHESIS); + $this->match(TokenType::T_OPEN_PARENTHESIS); $expression = $this->Subselect(); - $this->match(Lexer::T_CLOSE_PARENTHESIS); + $this->match(TokenType::T_CLOSE_PARENTHESIS); return new AST\SimpleSelectExpression($expression); @@ -2426,11 +2426,11 @@ public function SimpleSelectExpression() $expression = $this->ScalarExpression(); $expr = new AST\SimpleSelectExpression($expression); - if ($this->lexer->isNextToken(Lexer::T_AS)) { - $this->match(Lexer::T_AS); + if ($this->lexer->isNextToken(TokenType::T_AS)) { + $this->match(TokenType::T_AS); } - if ($this->lexer->isNextToken(Lexer::T_IDENTIFIER)) { + if ($this->lexer->isNextToken(TokenType::T_IDENTIFIER)) { $token = $this->lexer->lookahead; $resultVariable = $this->AliasResultVariable(); $expr->fieldIdentificationVariable = $resultVariable; @@ -2456,8 +2456,8 @@ public function ConditionalExpression() $conditionalTerms = []; $conditionalTerms[] = $this->ConditionalTerm(); - while ($this->lexer->isNextToken(Lexer::T_OR)) { - $this->match(Lexer::T_OR); + while ($this->lexer->isNextToken(TokenType::T_OR)) { + $this->match(TokenType::T_OR); $conditionalTerms[] = $this->ConditionalTerm(); } @@ -2481,8 +2481,8 @@ public function ConditionalTerm() $conditionalFactors = []; $conditionalFactors[] = $this->ConditionalFactor(); - while ($this->lexer->isNextToken(Lexer::T_AND)) { - $this->match(Lexer::T_AND); + while ($this->lexer->isNextToken(TokenType::T_AND)) { + $this->match(TokenType::T_AND); $conditionalFactors[] = $this->ConditionalFactor(); } @@ -2505,8 +2505,8 @@ public function ConditionalFactor() { $not = false; - if ($this->lexer->isNextToken(Lexer::T_NOT)) { - $this->match(Lexer::T_NOT); + if ($this->lexer->isNextToken(TokenType::T_NOT)) { + $this->match(TokenType::T_NOT); $not = true; } @@ -2531,7 +2531,7 @@ public function ConditionalPrimary() { $condPrimary = new AST\ConditionalPrimary(); - if (! $this->lexer->isNextToken(Lexer::T_OPEN_PARENTHESIS)) { + if (! $this->lexer->isNextToken(TokenType::T_OPEN_PARENTHESIS)) { $condPrimary->simpleConditionalExpression = $this->SimpleConditionalExpression(); return $condPrimary; @@ -2543,7 +2543,7 @@ public function ConditionalPrimary() if ( $peek !== null && ( in_array($peek->value, ['=', '<', '<=', '<>', '>', '>=', '!='], true) || - in_array($peek->type, [Lexer::T_NOT, Lexer::T_BETWEEN, Lexer::T_LIKE, Lexer::T_IN, Lexer::T_IS, Lexer::T_EXISTS], true) || + in_array($peek->type, [TokenType::T_NOT, TokenType::T_BETWEEN, TokenType::T_LIKE, TokenType::T_IN, TokenType::T_IS, TokenType::T_EXISTS], true) || $this->isMathOperator($peek) ) ) { @@ -2552,9 +2552,9 @@ public function ConditionalPrimary() return $condPrimary; } - $this->match(Lexer::T_OPEN_PARENTHESIS); + $this->match(TokenType::T_OPEN_PARENTHESIS); $condPrimary->conditionalExpression = $this->ConditionalExpression(); - $this->match(Lexer::T_CLOSE_PARENTHESIS); + $this->match(TokenType::T_CLOSE_PARENTHESIS); return $condPrimary; } @@ -2579,7 +2579,7 @@ public function ConditionalPrimary() public function SimpleConditionalExpression() { assert($this->lexer->lookahead !== null); - if ($this->lexer->isNextToken(Lexer::T_EXISTS)) { + if ($this->lexer->isNextToken(TokenType::T_EXISTS)) { return $this->ExistsExpression(); } @@ -2587,13 +2587,13 @@ public function SimpleConditionalExpression() $peek = $this->lexer->glimpse(); $lookahead = $token; - if ($this->lexer->isNextToken(Lexer::T_NOT)) { + if ($this->lexer->isNextToken(TokenType::T_NOT)) { $token = $this->lexer->glimpse(); } assert($token !== null); assert($peek !== null); - if ($token->type === Lexer::T_IDENTIFIER || $token->type === Lexer::T_INPUT_PARAMETER || $this->isFunction()) { + if ($token->type === TokenType::T_IDENTIFIER || $token->type === TokenType::T_INPUT_PARAMETER || $this->isFunction()) { // Peek beyond the matching closing parenthesis. $beyond = $this->lexer->peek(); @@ -2603,12 +2603,12 @@ public function SimpleConditionalExpression() $token = $this->peekBeyondClosingParenthesis(false); assert($token !== null); - if ($token->type === Lexer::T_NOT) { + if ($token->type === TokenType::T_NOT) { $token = $this->lexer->peek(); assert($token !== null); } - if ($token->type === Lexer::T_IS) { + if ($token->type === TokenType::T_IS) { $lookahead = $this->lexer->peek(); } @@ -2627,7 +2627,7 @@ public function SimpleConditionalExpression() // Also peek beyond a NOT if there is one. assert($token !== null); - if ($token->type === Lexer::T_NOT) { + if ($token->type === TokenType::T_NOT) { $token = $this->lexer->peek(); assert($token !== null); } @@ -2638,39 +2638,39 @@ public function SimpleConditionalExpression() assert($lookahead !== null); // Also peek beyond a NOT if there is one. - if ($lookahead->type === Lexer::T_NOT) { + if ($lookahead->type === TokenType::T_NOT) { $lookahead = $this->lexer->peek(); } $this->lexer->resetPeek(); } - if ($token->type === Lexer::T_BETWEEN) { + if ($token->type === TokenType::T_BETWEEN) { return $this->BetweenExpression(); } - if ($token->type === Lexer::T_LIKE) { + if ($token->type === TokenType::T_LIKE) { return $this->LikeExpression(); } - if ($token->type === Lexer::T_IN) { + if ($token->type === TokenType::T_IN) { return $this->InExpression(); } - if ($token->type === Lexer::T_INSTANCE) { + if ($token->type === TokenType::T_INSTANCE) { return $this->InstanceOfExpression(); } - if ($token->type === Lexer::T_MEMBER) { + if ($token->type === TokenType::T_MEMBER) { return $this->CollectionMemberExpression(); } assert($lookahead !== null); - if ($token->type === Lexer::T_IS && $lookahead->type === Lexer::T_NULL) { + if ($token->type === TokenType::T_IS && $lookahead->type === TokenType::T_NULL) { return $this->NullComparisonExpression(); } - if ($token->type === Lexer::T_IS && $lookahead->type === Lexer::T_EMPTY) { + if ($token->type === TokenType::T_IS && $lookahead->type === TokenType::T_EMPTY) { return $this->EmptyCollectionComparisonExpression(); } @@ -2685,15 +2685,15 @@ public function SimpleConditionalExpression() public function EmptyCollectionComparisonExpression() { $pathExpression = $this->CollectionValuedPathExpression(); - $this->match(Lexer::T_IS); + $this->match(TokenType::T_IS); $not = false; - if ($this->lexer->isNextToken(Lexer::T_NOT)) { - $this->match(Lexer::T_NOT); + if ($this->lexer->isNextToken(TokenType::T_NOT)) { + $this->match(TokenType::T_NOT); $not = true; } - $this->match(Lexer::T_EMPTY); + $this->match(TokenType::T_EMPTY); return new AST\EmptyCollectionComparisonExpression( $pathExpression, @@ -2714,16 +2714,16 @@ public function CollectionMemberExpression() $not = false; $entityExpr = $this->EntityExpression(); - if ($this->lexer->isNextToken(Lexer::T_NOT)) { - $this->match(Lexer::T_NOT); + if ($this->lexer->isNextToken(TokenType::T_NOT)) { + $this->match(TokenType::T_NOT); $not = true; } - $this->match(Lexer::T_MEMBER); + $this->match(TokenType::T_MEMBER); - if ($this->lexer->isNextToken(Lexer::T_OF)) { - $this->match(Lexer::T_OF); + if ($this->lexer->isNextToken(TokenType::T_OF)) { + $this->match(TokenType::T_OF); } return new AST\CollectionMemberExpression( @@ -2743,23 +2743,23 @@ public function Literal() assert($this->lexer->lookahead !== null); assert($this->lexer->token !== null); switch ($this->lexer->lookahead->type) { - case Lexer::T_STRING: - $this->match(Lexer::T_STRING); + case TokenType::T_STRING: + $this->match(TokenType::T_STRING); return new AST\Literal(AST\Literal::STRING, $this->lexer->token->value); - case Lexer::T_INTEGER: - case Lexer::T_FLOAT: + case TokenType::T_INTEGER: + case TokenType::T_FLOAT: $this->match( - $this->lexer->isNextToken(Lexer::T_INTEGER) ? Lexer::T_INTEGER : Lexer::T_FLOAT + $this->lexer->isNextToken(TokenType::T_INTEGER) ? TokenType::T_INTEGER : TokenType::T_FLOAT ); return new AST\Literal(AST\Literal::NUMERIC, $this->lexer->token->value); - case Lexer::T_TRUE: - case Lexer::T_FALSE: + case TokenType::T_TRUE: + case TokenType::T_FALSE: $this->match( - $this->lexer->isNextToken(Lexer::T_TRUE) ? Lexer::T_TRUE : Lexer::T_FALSE + $this->lexer->isNextToken(TokenType::T_TRUE) ? TokenType::T_TRUE : TokenType::T_FALSE ); return new AST\Literal(AST\Literal::BOOLEAN, $this->lexer->token->value); @@ -2777,7 +2777,7 @@ public function Literal() public function InParameter() { assert($this->lexer->lookahead !== null); - if ($this->lexer->lookahead->type === Lexer::T_INPUT_PARAMETER) { + if ($this->lexer->lookahead->type === TokenType::T_INPUT_PARAMETER) { return $this->InputParameter(); } @@ -2791,7 +2791,7 @@ public function InParameter() */ public function InputParameter() { - $this->match(Lexer::T_INPUT_PARAMETER); + $this->match(TokenType::T_INPUT_PARAMETER); assert($this->lexer->token !== null); return new AST\InputParameter($this->lexer->token->value); @@ -2806,14 +2806,14 @@ public function ArithmeticExpression() { $expr = new AST\ArithmeticExpression(); - if ($this->lexer->isNextToken(Lexer::T_OPEN_PARENTHESIS)) { + if ($this->lexer->isNextToken(TokenType::T_OPEN_PARENTHESIS)) { $peek = $this->lexer->glimpse(); assert($peek !== null); - if ($peek->type === Lexer::T_SELECT) { - $this->match(Lexer::T_OPEN_PARENTHESIS); + if ($peek->type === TokenType::T_SELECT) { + $this->match(TokenType::T_OPEN_PARENTHESIS); $expr->subselect = $this->Subselect(); - $this->match(Lexer::T_CLOSE_PARENTHESIS); + $this->match(TokenType::T_CLOSE_PARENTHESIS); return $expr; } @@ -2834,8 +2834,8 @@ public function SimpleArithmeticExpression() $terms = []; $terms[] = $this->ArithmeticTerm(); - while (($isPlus = $this->lexer->isNextToken(Lexer::T_PLUS)) || $this->lexer->isNextToken(Lexer::T_MINUS)) { - $this->match($isPlus ? Lexer::T_PLUS : Lexer::T_MINUS); + while (($isPlus = $this->lexer->isNextToken(TokenType::T_PLUS)) || $this->lexer->isNextToken(TokenType::T_MINUS)) { + $this->match($isPlus ? TokenType::T_PLUS : TokenType::T_MINUS); assert($this->lexer->token !== null); $terms[] = $this->lexer->token->value; @@ -2861,8 +2861,8 @@ public function ArithmeticTerm() $factors = []; $factors[] = $this->ArithmeticFactor(); - while (($isMult = $this->lexer->isNextToken(Lexer::T_MULTIPLY)) || $this->lexer->isNextToken(Lexer::T_DIVIDE)) { - $this->match($isMult ? Lexer::T_MULTIPLY : Lexer::T_DIVIDE); + while (($isMult = $this->lexer->isNextToken(TokenType::T_MULTIPLY)) || $this->lexer->isNextToken(TokenType::T_DIVIDE)) { + $this->match($isMult ? TokenType::T_MULTIPLY : TokenType::T_DIVIDE); assert($this->lexer->token !== null); $factors[] = $this->lexer->token->value; @@ -2887,9 +2887,9 @@ public function ArithmeticFactor() { $sign = null; - $isPlus = $this->lexer->isNextToken(Lexer::T_PLUS); - if ($isPlus || $this->lexer->isNextToken(Lexer::T_MINUS)) { - $this->match($isPlus ? Lexer::T_PLUS : Lexer::T_MINUS); + $isPlus = $this->lexer->isNextToken(TokenType::T_PLUS); + if ($isPlus || $this->lexer->isNextToken(TokenType::T_MINUS)) { + $this->match($isPlus ? TokenType::T_PLUS : TokenType::T_MINUS); $sign = $isPlus; } @@ -2914,24 +2914,24 @@ public function ArithmeticFactor() */ public function ArithmeticPrimary() { - if ($this->lexer->isNextToken(Lexer::T_OPEN_PARENTHESIS)) { - $this->match(Lexer::T_OPEN_PARENTHESIS); + if ($this->lexer->isNextToken(TokenType::T_OPEN_PARENTHESIS)) { + $this->match(TokenType::T_OPEN_PARENTHESIS); $expr = $this->SimpleArithmeticExpression(); - $this->match(Lexer::T_CLOSE_PARENTHESIS); + $this->match(TokenType::T_CLOSE_PARENTHESIS); return new AST\ParenthesisExpression($expr); } assert($this->lexer->lookahead !== null); switch ($this->lexer->lookahead->type) { - case Lexer::T_COALESCE: - case Lexer::T_NULLIF: - case Lexer::T_CASE: + case TokenType::T_COALESCE: + case TokenType::T_NULLIF: + case TokenType::T_CASE: return $this->CaseExpression(); - case Lexer::T_IDENTIFIER: + case TokenType::T_IDENTIFIER: $peek = $this->lexer->glimpse(); if ($peek !== null && $peek->value === '(') { @@ -2948,7 +2948,7 @@ public function ArithmeticPrimary() return $this->StateFieldPathExpression(); - case Lexer::T_INPUT_PARAMETER: + case TokenType::T_INPUT_PARAMETER: return $this->InputParameter(); default: @@ -2973,10 +2973,10 @@ public function StringExpression() assert($peek !== null); // Subselect - if ($this->lexer->isNextToken(Lexer::T_OPEN_PARENTHESIS) && $peek->type === Lexer::T_SELECT) { - $this->match(Lexer::T_OPEN_PARENTHESIS); + if ($this->lexer->isNextToken(TokenType::T_OPEN_PARENTHESIS) && $peek->type === TokenType::T_SELECT) { + $this->match(TokenType::T_OPEN_PARENTHESIS); $expr = $this->Subselect(); - $this->match(Lexer::T_CLOSE_PARENTHESIS); + $this->match(TokenType::T_CLOSE_PARENTHESIS); return $expr; } @@ -2984,7 +2984,7 @@ public function StringExpression() assert($this->lexer->lookahead !== null); // ResultVariable (string) if ( - $this->lexer->isNextToken(Lexer::T_IDENTIFIER) && + $this->lexer->isNextToken(TokenType::T_IDENTIFIER) && isset($this->queryComponents[$this->lexer->lookahead->value]['resultVariable']) ) { return $this->ResultVariable(); @@ -3004,7 +3004,7 @@ public function StringPrimary() $lookaheadType = $this->lexer->lookahead->type; switch ($lookaheadType) { - case Lexer::T_IDENTIFIER: + case TokenType::T_IDENTIFIER: $peek = $this->lexer->glimpse(); assert($peek !== null); @@ -3020,18 +3020,18 @@ public function StringPrimary() $this->syntaxError("'.' or '('"); break; - case Lexer::T_STRING: - $this->match(Lexer::T_STRING); + case TokenType::T_STRING: + $this->match(TokenType::T_STRING); assert($this->lexer->token !== null); return new AST\Literal(AST\Literal::STRING, $this->lexer->token->value); - case Lexer::T_INPUT_PARAMETER: + case TokenType::T_INPUT_PARAMETER: return $this->InputParameter(); - case Lexer::T_CASE: - case Lexer::T_COALESCE: - case Lexer::T_NULLIF: + case TokenType::T_CASE: + case TokenType::T_COALESCE: + case TokenType::T_NULLIF: return $this->CaseExpression(); default: @@ -3056,7 +3056,7 @@ public function EntityExpression() $glimpse = $this->lexer->glimpse(); assert($glimpse !== null); - if ($this->lexer->isNextToken(Lexer::T_IDENTIFIER) && $glimpse->value === '.') { + if ($this->lexer->isNextToken(TokenType::T_IDENTIFIER) && $glimpse->value === '.') { return $this->SingleValuedAssociationPathExpression(); } @@ -3070,7 +3070,7 @@ public function EntityExpression() */ public function SimpleEntityExpression() { - if ($this->lexer->isNextToken(Lexer::T_INPUT_PARAMETER)) { + if ($this->lexer->isNextToken(TokenType::T_INPUT_PARAMETER)) { return $this->InputParameter(); } @@ -3089,23 +3089,23 @@ public function AggregateExpression() $lookaheadType = $this->lexer->lookahead->type; $isDistinct = false; - if (! in_array($lookaheadType, [Lexer::T_COUNT, Lexer::T_AVG, Lexer::T_MAX, Lexer::T_MIN, Lexer::T_SUM], true)) { + if (! in_array($lookaheadType, [TokenType::T_COUNT, TokenType::T_AVG, TokenType::T_MAX, TokenType::T_MIN, TokenType::T_SUM], true)) { $this->syntaxError('One of: MAX, MIN, AVG, SUM, COUNT'); } $this->match($lookaheadType); assert($this->lexer->token !== null); $functionName = $this->lexer->token->value; - $this->match(Lexer::T_OPEN_PARENTHESIS); + $this->match(TokenType::T_OPEN_PARENTHESIS); - if ($this->lexer->isNextToken(Lexer::T_DISTINCT)) { - $this->match(Lexer::T_DISTINCT); + if ($this->lexer->isNextToken(TokenType::T_DISTINCT)) { + $this->match(TokenType::T_DISTINCT); $isDistinct = true; } $pathExp = $this->SimpleArithmeticExpression(); - $this->match(Lexer::T_CLOSE_PARENTHESIS); + $this->match(TokenType::T_CLOSE_PARENTHESIS); return new AST\AggregateExpression($functionName, $pathExp, $isDistinct); } @@ -3121,17 +3121,17 @@ public function QuantifiedExpression() $lookaheadType = $this->lexer->lookahead->type; $value = $this->lexer->lookahead->value; - if (! in_array($lookaheadType, [Lexer::T_ALL, Lexer::T_ANY, Lexer::T_SOME], true)) { + if (! in_array($lookaheadType, [TokenType::T_ALL, TokenType::T_ANY, TokenType::T_SOME], true)) { $this->syntaxError('ALL, ANY or SOME'); } $this->match($lookaheadType); - $this->match(Lexer::T_OPEN_PARENTHESIS); + $this->match(TokenType::T_OPEN_PARENTHESIS); $qExpr = new AST\QuantifiedExpression($this->Subselect()); $qExpr->type = $value; - $this->match(Lexer::T_CLOSE_PARENTHESIS); + $this->match(TokenType::T_CLOSE_PARENTHESIS); return $qExpr; } @@ -3146,14 +3146,14 @@ public function BetweenExpression() $not = false; $arithExpr1 = $this->ArithmeticExpression(); - if ($this->lexer->isNextToken(Lexer::T_NOT)) { - $this->match(Lexer::T_NOT); + if ($this->lexer->isNextToken(TokenType::T_NOT)) { + $this->match(TokenType::T_NOT); $not = true; } - $this->match(Lexer::T_BETWEEN); + $this->match(TokenType::T_BETWEEN); $arithExpr2 = $this->ArithmeticExpression(); - $this->match(Lexer::T_AND); + $this->match(TokenType::T_AND); $arithExpr3 = $this->ArithmeticExpression(); return new AST\BetweenExpression($arithExpr1, $arithExpr2, $arithExpr3, $not); @@ -3187,15 +3187,15 @@ public function InExpression() $expression = $this->ArithmeticExpression(); $not = false; - if ($this->lexer->isNextToken(Lexer::T_NOT)) { - $this->match(Lexer::T_NOT); + if ($this->lexer->isNextToken(TokenType::T_NOT)) { + $this->match(TokenType::T_NOT); $not = true; } - $this->match(Lexer::T_IN); - $this->match(Lexer::T_OPEN_PARENTHESIS); + $this->match(TokenType::T_IN); + $this->match(TokenType::T_OPEN_PARENTHESIS); - if ($this->lexer->isNextToken(Lexer::T_SELECT)) { + if ($this->lexer->isNextToken(TokenType::T_SELECT)) { $inExpression = new AST\InSubselectExpression( $expression, $this->Subselect(), @@ -3204,8 +3204,8 @@ public function InExpression() } else { $literals = [$this->InParameter()]; - while ($this->lexer->isNextToken(Lexer::T_COMMA)) { - $this->match(Lexer::T_COMMA); + while ($this->lexer->isNextToken(TokenType::T_COMMA)) { + $this->match(TokenType::T_COMMA); $literals[] = $this->InParameter(); } @@ -3216,7 +3216,7 @@ public function InExpression() ); } - $this->match(Lexer::T_CLOSE_PARENTHESIS); + $this->match(TokenType::T_CLOSE_PARENTHESIS); return $inExpression; } @@ -3231,15 +3231,15 @@ public function InstanceOfExpression() $identificationVariable = $this->IdentificationVariable(); $not = false; - if ($this->lexer->isNextToken(Lexer::T_NOT)) { - $this->match(Lexer::T_NOT); + if ($this->lexer->isNextToken(TokenType::T_NOT)) { + $this->match(TokenType::T_NOT); $not = true; } - $this->match(Lexer::T_INSTANCE); - $this->match(Lexer::T_OF); + $this->match(TokenType::T_INSTANCE); + $this->match(TokenType::T_OF); - $exprValues = $this->lexer->isNextToken(Lexer::T_OPEN_PARENTHESIS) + $exprValues = $this->lexer->isNextToken(TokenType::T_OPEN_PARENTHESIS) ? $this->InstanceOfParameterList() : [$this->InstanceOfParameter()]; @@ -3253,17 +3253,17 @@ public function InstanceOfExpression() /** @return non-empty-list */ public function InstanceOfParameterList(): array { - $this->match(Lexer::T_OPEN_PARENTHESIS); + $this->match(TokenType::T_OPEN_PARENTHESIS); $exprValues = [$this->InstanceOfParameter()]; - while ($this->lexer->isNextToken(Lexer::T_COMMA)) { - $this->match(Lexer::T_COMMA); + while ($this->lexer->isNextToken(TokenType::T_COMMA)) { + $this->match(TokenType::T_COMMA); $exprValues[] = $this->InstanceOfParameter(); } - $this->match(Lexer::T_CLOSE_PARENTHESIS); + $this->match(TokenType::T_CLOSE_PARENTHESIS); return $exprValues; } @@ -3275,8 +3275,8 @@ public function InstanceOfParameterList(): array */ public function InstanceOfParameter() { - if ($this->lexer->isNextToken(Lexer::T_INPUT_PARAMETER)) { - $this->match(Lexer::T_INPUT_PARAMETER); + if ($this->lexer->isNextToken(TokenType::T_INPUT_PARAMETER)) { + $this->match(TokenType::T_INPUT_PARAMETER); assert($this->lexer->token !== null); return new AST\InputParameter($this->lexer->token->value); @@ -3299,15 +3299,15 @@ public function LikeExpression() $stringExpr = $this->StringExpression(); $not = false; - if ($this->lexer->isNextToken(Lexer::T_NOT)) { - $this->match(Lexer::T_NOT); + if ($this->lexer->isNextToken(TokenType::T_NOT)) { + $this->match(TokenType::T_NOT); $not = true; } - $this->match(Lexer::T_LIKE); + $this->match(TokenType::T_LIKE); - if ($this->lexer->isNextToken(Lexer::T_INPUT_PARAMETER)) { - $this->match(Lexer::T_INPUT_PARAMETER); + if ($this->lexer->isNextToken(TokenType::T_INPUT_PARAMETER)) { + $this->match(TokenType::T_INPUT_PARAMETER); assert($this->lexer->token !== null); $stringPattern = new AST\InputParameter($this->lexer->token->value); } else { @@ -3316,9 +3316,9 @@ public function LikeExpression() $escapeChar = null; - if ($this->lexer->lookahead !== null && $this->lexer->lookahead->type === Lexer::T_ESCAPE) { - $this->match(Lexer::T_ESCAPE); - $this->match(Lexer::T_STRING); + if ($this->lexer->lookahead !== null && $this->lexer->lookahead->type === TokenType::T_ESCAPE) { + $this->match(TokenType::T_ESCAPE); + $this->match(TokenType::T_STRING); assert($this->lexer->token !== null); $escapeChar = new AST\Literal(AST\Literal::STRING, $this->lexer->token->value); @@ -3335,18 +3335,18 @@ public function LikeExpression() public function NullComparisonExpression() { switch (true) { - case $this->lexer->isNextToken(Lexer::T_INPUT_PARAMETER): - $this->match(Lexer::T_INPUT_PARAMETER); + case $this->lexer->isNextToken(TokenType::T_INPUT_PARAMETER): + $this->match(TokenType::T_INPUT_PARAMETER); assert($this->lexer->token !== null); $expr = new AST\InputParameter($this->lexer->token->value); break; - case $this->lexer->isNextToken(Lexer::T_NULLIF): + case $this->lexer->isNextToken(TokenType::T_NULLIF): $expr = $this->NullIfExpression(); break; - case $this->lexer->isNextToken(Lexer::T_COALESCE): + case $this->lexer->isNextToken(TokenType::T_COALESCE): $expr = $this->CoalesceExpression(); break; @@ -3359,7 +3359,7 @@ public function NullComparisonExpression() $glimpse = $this->lexer->glimpse(); assert($glimpse !== null); - if ($glimpse->type === Lexer::T_DOT) { + if ($glimpse->type === TokenType::T_DOT) { $expr = $this->SingleValuedPathExpression(); // Leave switch statement @@ -3389,16 +3389,16 @@ public function NullComparisonExpression() break; } - $this->match(Lexer::T_IS); + $this->match(TokenType::T_IS); $not = false; - if ($this->lexer->isNextToken(Lexer::T_NOT)) { - $this->match(Lexer::T_NOT); + if ($this->lexer->isNextToken(TokenType::T_NOT)) { + $this->match(TokenType::T_NOT); $not = true; } - $this->match(Lexer::T_NULL); + $this->match(TokenType::T_NULL); return new AST\NullComparisonExpression($expr, $not); } @@ -3412,17 +3412,17 @@ public function ExistsExpression() { $not = false; - if ($this->lexer->isNextToken(Lexer::T_NOT)) { - $this->match(Lexer::T_NOT); + if ($this->lexer->isNextToken(TokenType::T_NOT)) { + $this->match(TokenType::T_NOT); $not = true; } - $this->match(Lexer::T_EXISTS); - $this->match(Lexer::T_OPEN_PARENTHESIS); + $this->match(TokenType::T_EXISTS); + $this->match(TokenType::T_OPEN_PARENTHESIS); $subselect = $this->Subselect(); - $this->match(Lexer::T_CLOSE_PARENTHESIS); + $this->match(TokenType::T_CLOSE_PARENTHESIS); return new AST\ExistsExpression($subselect, $not); } @@ -3437,38 +3437,38 @@ public function ComparisonOperator() assert($this->lexer->lookahead !== null); switch ($this->lexer->lookahead->value) { case '=': - $this->match(Lexer::T_EQUALS); + $this->match(TokenType::T_EQUALS); return '='; case '<': - $this->match(Lexer::T_LOWER_THAN); + $this->match(TokenType::T_LOWER_THAN); $operator = '<'; - if ($this->lexer->isNextToken(Lexer::T_EQUALS)) { - $this->match(Lexer::T_EQUALS); + if ($this->lexer->isNextToken(TokenType::T_EQUALS)) { + $this->match(TokenType::T_EQUALS); $operator .= '='; - } elseif ($this->lexer->isNextToken(Lexer::T_GREATER_THAN)) { - $this->match(Lexer::T_GREATER_THAN); + } elseif ($this->lexer->isNextToken(TokenType::T_GREATER_THAN)) { + $this->match(TokenType::T_GREATER_THAN); $operator .= '>'; } return $operator; case '>': - $this->match(Lexer::T_GREATER_THAN); + $this->match(TokenType::T_GREATER_THAN); $operator = '>'; - if ($this->lexer->isNextToken(Lexer::T_EQUALS)) { - $this->match(Lexer::T_EQUALS); + if ($this->lexer->isNextToken(TokenType::T_EQUALS)) { + $this->match(TokenType::T_EQUALS); $operator .= '='; } return $operator; case '!': - $this->match(Lexer::T_NEGATE); - $this->match(Lexer::T_EQUALS); + $this->match(TokenType::T_NEGATE); + $this->match(TokenType::T_EQUALS); return '<>'; diff --git a/src/Query/TokenType.php b/src/Query/TokenType.php new file mode 100644 index 00000000000..417c7506d25 --- /dev/null +++ b/src/Query/TokenType.php @@ -0,0 +1,99 @@ += 100 + /** @deprecated No Replacement planned. */ + public const T_ALIASED_NAME = 100; + public const T_FULLY_QUALIFIED_NAME = 101; + public const T_IDENTIFIER = 102; + + // All keyword tokens should be >= 200 + public const T_ALL = 200; + public const T_AND = 201; + public const T_ANY = 202; + public const T_AS = 203; + public const T_ASC = 204; + public const T_AVG = 205; + public const T_BETWEEN = 206; + public const T_BOTH = 207; + public const T_BY = 208; + public const T_CASE = 209; + public const T_COALESCE = 210; + public const T_COUNT = 211; + public const T_DELETE = 212; + public const T_DESC = 213; + public const T_DISTINCT = 214; + public const T_ELSE = 215; + public const T_EMPTY = 216; + public const T_END = 217; + public const T_ESCAPE = 218; + public const T_EXISTS = 219; + public const T_FALSE = 220; + public const T_FROM = 221; + public const T_GROUP = 222; + public const T_HAVING = 223; + public const T_HIDDEN = 224; + public const T_IN = 225; + public const T_INDEX = 226; + public const T_INNER = 227; + public const T_INSTANCE = 228; + public const T_IS = 229; + public const T_JOIN = 230; + public const T_LEADING = 231; + public const T_LEFT = 232; + public const T_LIKE = 233; + public const T_MAX = 234; + public const T_MEMBER = 235; + public const T_MIN = 236; + public const T_NEW = 237; + public const T_NOT = 238; + public const T_NULL = 239; + public const T_NULLIF = 240; + public const T_OF = 241; + public const T_OR = 242; + public const T_ORDER = 243; + public const T_OUTER = 244; + public const T_PARTIAL = 245; + public const T_SELECT = 246; + public const T_SET = 247; + public const T_SOME = 248; + public const T_SUM = 249; + public const T_THEN = 250; + public const T_TRAILING = 251; + public const T_TRUE = 252; + public const T_UPDATE = 253; + public const T_WHEN = 254; + public const T_WHERE = 255; + public const T_WITH = 256; + + /** @internal */ + private function __construct() + { + } +} diff --git a/tests/Tests/ORM/Functional/CustomFunctionsTest.php b/tests/Tests/ORM/Functional/CustomFunctionsTest.php index f4027d7dc83..284aee8c68a 100644 --- a/tests/Tests/ORM/Functional/CustomFunctionsTest.php +++ b/tests/Tests/ORM/Functional/CustomFunctionsTest.php @@ -7,9 +7,9 @@ use Doctrine\ORM\Query; use Doctrine\ORM\Query\AST\Functions\FunctionNode; use Doctrine\ORM\Query\AST\PathExpression; -use Doctrine\ORM\Query\Lexer; use Doctrine\ORM\Query\Parser; use Doctrine\ORM\Query\SqlWalker; +use Doctrine\ORM\Query\TokenType; use Doctrine\Tests\Models\CMS\CmsUser; use Doctrine\Tests\OrmFunctionalTestCase; @@ -75,10 +75,10 @@ class NoOp extends FunctionNode 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->field = $parser->ArithmeticPrimary(); - $parser->match(Lexer::T_CLOSE_PARENTHESIS); + $parser->match(TokenType::T_CLOSE_PARENTHESIS); } public function getSql(SqlWalker $sqlWalker): string diff --git a/tests/Tests/ORM/Functional/Ticket/GH7286Test.php b/tests/Tests/ORM/Functional/Ticket/GH7286Test.php index 0fd6d8aa37f..e46c963277b 100644 --- a/tests/Tests/ORM/Functional/Ticket/GH7286Test.php +++ b/tests/Tests/ORM/Functional/Ticket/GH7286Test.php @@ -10,9 +10,9 @@ use Doctrine\ORM\Mapping\Id; use Doctrine\ORM\Query\AST\Functions\FunctionNode; use Doctrine\ORM\Query\AST\Node; -use Doctrine\ORM\Query\Lexer; use Doctrine\ORM\Query\Parser; use Doctrine\ORM\Query\SqlWalker; +use Doctrine\ORM\Query\TokenType; use Doctrine\Tests\OrmFunctionalTestCase; final class GH7286Test extends OrmFunctionalTestCase @@ -114,14 +114,14 @@ class GH7286CustomConcat extends FunctionNode 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->first = $parser->StringPrimary(); - $parser->match(Lexer::T_COMMA); + $parser->match(TokenType::T_COMMA); $this->second = $parser->StringPrimary(); - $parser->match(Lexer::T_CLOSE_PARENTHESIS); + $parser->match(TokenType::T_CLOSE_PARENTHESIS); } public function getSql(SqlWalker $walker): string diff --git a/tests/Tests/ORM/Query/LexerTest.php b/tests/Tests/ORM/Query/LexerTest.php index 99b13063636..9aa818d1dd2 100644 --- a/tests/Tests/ORM/Query/LexerTest.php +++ b/tests/Tests/ORM/Query/LexerTest.php @@ -6,6 +6,7 @@ use Doctrine\Common\Lexer\Token; use Doctrine\ORM\Query\Lexer; +use Doctrine\ORM\Query\TokenType; use Doctrine\Tests\OrmTestCase; class LexerTest extends OrmTestCase @@ -35,7 +36,7 @@ public function testScannerRecognizesTerminalString(): void $lexer->moveNext(); $token = $lexer->lookahead; - self::assertEquals(Lexer::T_ALL, $token->type); + self::assertEquals(TokenType::T_ALL, $token->type); } public function testScannerRecognizesDecimalInteger(): void @@ -43,7 +44,7 @@ public function testScannerRecognizesDecimalInteger(): void $lexer = new Lexer('1234'); $lexer->moveNext(); $token = $lexer->lookahead; - self::assertEquals(Lexer::T_INTEGER, $token->type); + self::assertEquals(TokenType::T_INTEGER, $token->type); self::assertEquals(1234, $token->value); } @@ -52,7 +53,7 @@ public function testScannerRecognizesFloat(): void $lexer = new Lexer('1.234'); $lexer->moveNext(); $token = $lexer->lookahead; - self::assertEquals(Lexer::T_FLOAT, $token->type); + self::assertEquals(TokenType::T_FLOAT, $token->type); self::assertEquals(1.234, $token->value); } @@ -61,7 +62,7 @@ public function testScannerRecognizesFloatWithExponent(): void $lexer = new Lexer('1.2e3'); $lexer->moveNext(); $token = $lexer->lookahead; - self::assertEquals(Lexer::T_FLOAT, $token->type); + self::assertEquals(TokenType::T_FLOAT, $token->type); self::assertEquals(1.2e3, $token->value); } @@ -70,7 +71,7 @@ public function testScannerRecognizesFloatWithExponent2(): void $lexer = new Lexer('0.2e3'); $lexer->moveNext(); $token = $lexer->lookahead; - self::assertEquals(Lexer::T_FLOAT, $token->type); + self::assertEquals(TokenType::T_FLOAT, $token->type); self::assertEquals(.2e3, $token->value); } @@ -79,7 +80,7 @@ public function testScannerRecognizesFloatWithNegativeExponent(): void $lexer = new Lexer('7E-10'); $lexer->moveNext(); $token = $lexer->lookahead; - self::assertEquals(Lexer::T_FLOAT, $token->type); + self::assertEquals(TokenType::T_FLOAT, $token->type); self::assertEquals(7E-10, $token->value); } @@ -88,7 +89,7 @@ public function testScannerRecognizesFloatBig(): void $lexer = new Lexer('123456789.01'); $lexer->moveNext(); $token = $lexer->lookahead; - self::assertEquals(Lexer::T_FLOAT, $token->type); + self::assertEquals(TokenType::T_FLOAT, $token->type); self::assertEquals(1.2345678901e8, $token->value); } @@ -97,12 +98,12 @@ public function testScannerRecognizesFloatContainingWhitespace(): void $lexer = new Lexer('- 1.234e2'); $lexer->moveNext(); $token = $lexer->lookahead; - self::assertEquals(Lexer::T_MINUS, $token->type); + self::assertEquals(TokenType::T_MINUS, $token->type); self::assertEquals('-', $token->value); $lexer->moveNext(); $token = $lexer->lookahead; - self::assertEquals(Lexer::T_FLOAT, $token->type); + self::assertEquals(TokenType::T_FLOAT, $token->type); self::assertNotEquals(-1.234e2, $token->value); self::assertEquals(1.234e2, $token->value); } @@ -112,7 +113,7 @@ public function testScannerRecognizesStringContainingWhitespace(): void $lexer = new Lexer("'This is a string.'"); $lexer->moveNext(); $token = $lexer->lookahead; - self::assertEquals(Lexer::T_STRING, $token->type); + self::assertEquals(TokenType::T_STRING, $token->type); self::assertEquals('This is a string.', $token->value); } @@ -121,7 +122,7 @@ public function testScannerRecognizesStringContainingSingleQuotes(): void $lexer = new Lexer("'abc''defg'''"); $lexer->moveNext(); $token = $lexer->lookahead; - self::assertEquals(Lexer::T_STRING, $token->type); + self::assertEquals(TokenType::T_STRING, $token->type); self::assertEquals("abc'defg'", $token->value); } @@ -130,7 +131,7 @@ public function testScannerRecognizesInputParameter(): void $lexer = new Lexer('?1'); $lexer->moveNext(); $token = $lexer->lookahead; - self::assertEquals(Lexer::T_INPUT_PARAMETER, $token->type); + self::assertEquals(TokenType::T_INPUT_PARAMETER, $token->type); self::assertEquals('?1', $token->value); } @@ -139,7 +140,7 @@ public function testScannerRecognizesNamedInputParameter(): void $lexer = new Lexer(':name'); $lexer->moveNext(); $token = $lexer->lookahead; - self::assertEquals(Lexer::T_INPUT_PARAMETER, $token->type); + self::assertEquals(TokenType::T_INPUT_PARAMETER, $token->type); self::assertEquals(':name', $token->value); } @@ -148,7 +149,7 @@ public function testScannerRecognizesNamedInputParameterStartingWithUnderscore() $lexer = new Lexer(':_name'); $lexer->moveNext(); $token = $lexer->lookahead; - self::assertEquals(Lexer::T_INPUT_PARAMETER, $token->type); + self::assertEquals(TokenType::T_INPUT_PARAMETER, $token->type); self::assertEquals(':_name', $token->value); } @@ -158,17 +159,17 @@ public function testScannerTokenizesASimpleQueryCorrectly(): void $lexer = new Lexer($dql); $tokens = [ - new Token('SELECT', Lexer::T_SELECT, 0), - new Token('u', Lexer::T_IDENTIFIER, 7), - new Token('FROM', Lexer::T_FROM, 9), - new Token('My\Namespace\User', Lexer::T_FULLY_QUALIFIED_NAME, 14), - new Token('u', Lexer::T_IDENTIFIER, 32), - new Token('WHERE', Lexer::T_WHERE, 34), - new Token('u', Lexer::T_IDENTIFIER, 40), - new Token('.', Lexer::T_DOT, 41), - new Token('name', Lexer::T_IDENTIFIER, 42), - new Token('=', Lexer::T_EQUALS, 47), - new Token("Jack O'Neil", Lexer::T_STRING, 49), + new Token('SELECT', TokenType::T_SELECT, 0), + new Token('u', TokenType::T_IDENTIFIER, 7), + new Token('FROM', TokenType::T_FROM, 9), + new Token('My\Namespace\User', TokenType::T_FULLY_QUALIFIED_NAME, 14), + new Token('u', TokenType::T_IDENTIFIER, 32), + new Token('WHERE', TokenType::T_WHERE, 34), + new Token('u', TokenType::T_IDENTIFIER, 40), + new Token('.', TokenType::T_DOT, 41), + new Token('name', TokenType::T_IDENTIFIER, 42), + new Token('=', TokenType::T_EQUALS, 47), + new Token("Jack O'Neil", TokenType::T_STRING, 49), ]; foreach ($tokens as $expected) { @@ -186,15 +187,15 @@ public function testScannerTokenizesASimpleQueryCorrectly(): void public static function provideTokens(): array { return [ - [Lexer::T_IDENTIFIER, 'u'], // one char - [Lexer::T_IDENTIFIER, 'someIdentifier'], - [Lexer::T_IDENTIFIER, 's0m31d3nt1f13r'], // including digits - [Lexer::T_IDENTIFIER, 'some_identifier'], // including underscore - [Lexer::T_IDENTIFIER, '_some_identifier'], // starts with underscore - [Lexer::T_IDENTIFIER, 'comma'], // name of a token class with value < 100 (whitebox test) - [Lexer::T_FULLY_QUALIFIED_NAME, 'Some\Class'], // DQL class reference - [Lexer::T_ALIASED_NAME, 'Some:Name'], - [Lexer::T_ALIASED_NAME, 'Some:Subclassed\Name'], + [TokenType::T_IDENTIFIER, 'u'], // one char + [TokenType::T_IDENTIFIER, 'someIdentifier'], + [TokenType::T_IDENTIFIER, 's0m31d3nt1f13r'], // including digits + [TokenType::T_IDENTIFIER, 'some_identifier'], // including underscore + [TokenType::T_IDENTIFIER, '_some_identifier'], // starts with underscore + [TokenType::T_IDENTIFIER, 'comma'], // name of a token class with value < 100 (whitebox test) + [TokenType::T_FULLY_QUALIFIED_NAME, 'Some\Class'], // DQL class reference + [TokenType::T_ALIASED_NAME, 'Some:Name'], + [TokenType::T_ALIASED_NAME, 'Some:Subclassed\Name'], ]; } } diff --git a/tests/Tests/ORM/Query/ParserTest.php b/tests/Tests/ORM/Query/ParserTest.php index 9ad751d76b3..2bc42a58b8f 100644 --- a/tests/Tests/ORM/Query/ParserTest.php +++ b/tests/Tests/ORM/Query/ParserTest.php @@ -6,9 +6,9 @@ use Doctrine\Common\Persistence\PersistentObject; use Doctrine\ORM\Query; -use Doctrine\ORM\Query\Lexer; use Doctrine\ORM\Query\Parser; use Doctrine\ORM\Query\QueryException; +use Doctrine\ORM\Query\TokenType; use Doctrine\Tests\Models\CMS\CmsUser; use Doctrine\Tests\OrmTestCase; use stdClass; @@ -124,11 +124,11 @@ public static function validMatches(): array * but in LexerTest. */ return [ - [Lexer::T_WHERE, 'where'], // keyword - [Lexer::T_DOT, '.'], // token that cannot be an identifier - [Lexer::T_IDENTIFIER, 'someIdentifier'], - [Lexer::T_IDENTIFIER, 'from'], // also a terminal string (the "FROM" keyword) as in DDC-505 - [Lexer::T_IDENTIFIER, 'comma'], + [TokenType::T_WHERE, 'where'], // keyword + [TokenType::T_DOT, '.'], // token that cannot be an identifier + [TokenType::T_IDENTIFIER, 'someIdentifier'], + [TokenType::T_IDENTIFIER, 'from'], // also a terminal string (the "FROM" keyword) as in DDC-505 + [TokenType::T_IDENTIFIER, 'comma'], // not even a terminal string, but the name of a constant in the Lexer (whitebox test) ]; } @@ -137,15 +137,15 @@ public static function validMatches(): array public static function invalidMatches(): array { return [ - [Lexer::T_DOT, 'ALL'], // ALL is a terminal string (reserved keyword) and also possibly an identifier - [Lexer::T_DOT, ','], // "," is a token on its own, but cannot be used as identifier - [Lexer::T_WHERE, 'WITH'], // as in DDC-3697 - [Lexer::T_WHERE, '.'], + [TokenType::T_DOT, 'ALL'], // ALL is a terminal string (reserved keyword) and also possibly an identifier + [TokenType::T_DOT, ','], // "," is a token on its own, but cannot be used as identifier + [TokenType::T_WHERE, 'WITH'], // as in DDC-3697 + [TokenType::T_WHERE, '.'], // The following are qualified or aliased names and must not be accepted where only an Identifier is expected - [Lexer::T_IDENTIFIER, '\\Some\\Class'], - [Lexer::T_IDENTIFIER, 'Some\\Class'], - [Lexer::T_IDENTIFIER, 'Some:Name'], + [TokenType::T_IDENTIFIER, '\\Some\\Class'], + [TokenType::T_IDENTIFIER, 'Some\\Class'], + [TokenType::T_IDENTIFIER, 'Some:Name'], ]; } @@ -164,7 +164,7 @@ public function testNullLookahead(): void $parser = new Parser($query); $this->expectException(QueryException::class); - $parser->match(Lexer::T_SELECT); + $parser->match(TokenType::T_SELECT); } private function createParser(string $dql): Parser diff --git a/tests/Tests/ORM/Query/SelectSqlGenerationTest.php b/tests/Tests/ORM/Query/SelectSqlGenerationTest.php index 540d870828f..5effffe36d0 100644 --- a/tests/Tests/ORM/Query/SelectSqlGenerationTest.php +++ b/tests/Tests/ORM/Query/SelectSqlGenerationTest.php @@ -18,10 +18,10 @@ use Doctrine\ORM\Query as ORMQuery; use Doctrine\ORM\Query\AST\Functions\FunctionNode; use Doctrine\ORM\Query\AST\SimpleArithmeticExpression; -use Doctrine\ORM\Query\Lexer; use Doctrine\ORM\Query\Parser; use Doctrine\ORM\Query\QueryException; use Doctrine\ORM\Query\SqlWalker; +use Doctrine\ORM\Query\TokenType; use Doctrine\Tests\DbalTypes\NegativeToPositiveType; use Doctrine\Tests\Models\CMS\CmsGroup; use Doctrine\Tests\Models\CMS\CmsPhonenumber; @@ -2186,12 +2186,12 @@ public function parse(Parser $parser): void { $lexer = $parser->getLexer(); - $parser->match(Lexer::T_IDENTIFIER); - $parser->match(Lexer::T_OPEN_PARENTHESIS); + $parser->match(TokenType::T_IDENTIFIER); + $parser->match(TokenType::T_OPEN_PARENTHESIS); $this->simpleArithmeticExpression = $parser->SimpleArithmeticExpression(); - $parser->match(Lexer::T_CLOSE_PARENTHESIS); + $parser->match(TokenType::T_CLOSE_PARENTHESIS); } } /** @Entity */ diff --git a/tests/Tests/ORM/Query/TreeWalkerAdapterTest.php b/tests/Tests/ORM/Query/TreeWalkerAdapterTest.php index d0915bde9b6..4613de998af 100644 --- a/tests/Tests/ORM/Query/TreeWalkerAdapterTest.php +++ b/tests/Tests/ORM/Query/TreeWalkerAdapterTest.php @@ -7,8 +7,8 @@ use Doctrine\Deprecations\PHPUnit\VerifyDeprecations; use Doctrine\ORM\AbstractQuery; use Doctrine\ORM\Mapping\ClassMetadata; -use Doctrine\ORM\Query\Lexer; use Doctrine\ORM\Query\ParserResult; +use Doctrine\ORM\Query\TokenType; use Doctrine\ORM\Query\TreeWalkerAdapter; use PHPUnit\Framework\TestCase; use stdClass; @@ -33,7 +33,7 @@ public function testDeprecatedSetQueryComponent(): void 'relation' => null, 'map' => null, 'nestingLevel' => 0, - 'token' => ['value' => '', 'type' => Lexer::T_NONE, 'position' => 0], + 'token' => ['value' => '', 'type' => TokenType::T_NONE, 'position' => 0], ]); } @@ -52,7 +52,7 @@ public function doSetQueryComponent(): void 'relation' => null, 'map' => null, 'nestingLevel' => 0, - 'token' => ['value' => '', 'type' => Lexer::T_NONE, 'position' => 0], + 'token' => ['value' => '', 'type' => TokenType::T_NONE, 'position' => 0], ]); } };