Doctrine\ORM\Query\Parser
An LL(*) recursive-descent parser for the context-free grammar of the Doctrine Query Language.
Parses a DQL query, reports any errors in it, and generates an AST.
- Author: Guilherme Blanco <guilhermeblanco@hotmail.com>
Synopsis
class Parser
{
- // members
- private array $_STRING_FUNCTIONS;
- private array $_NUMERIC_FUNCTIONS;
- private array $_DATETIME_FUNCTIONS;
- private array $_deferredIdentificationVariables;
- private array $_deferredPartialObjectExpressions;
- private array $_deferredPathExpressions;
- private array $_deferredResultVariables;
- private Lexer $_lexer;
- private ParserResult $_parserResult;
- private EnityManager $_em;
- private Query $_query;
- private array $_queryComponents;
- private integer $_nestingLevel;
- private array $_customTreeWalkers;
- private TreeWalker $_customOutputWalker;
- private array $_identVariableExpressions;
- // methods
- public static bool isInternalFunction()
- public void __construct()
- public void setCustomOutputTreeWalker()
- public void addCustomTreeWalker()
- public Lexer getLexer()
- public ParserResult getParserResult()
- public EntityManager getEntityManager()
- public SelectStatement getAST()
- public void match()
- public void free()
- public ParserResult parse()
- private void fixIdentificationVariableOrder()
- public void syntaxError()
- public void semanticalError()
- private array _peekBeyondClosingParenthesis()
- private boolean _isMathOperator()
- private boolean _isFunction()
- private boolean _isAggregateFunction()
- private boolean _isNextAllAnySome()
- private void _processDeferredIdentificationVariables()
- private void _processDeferredPartialObjectExpressions()
- private void _processDeferredResultVariables()
- private void _processDeferredPathExpressions()
- private void _processRootEntityAliasSelected()
- public SelectStatement QueryLanguage()
- public SelectStatement SelectStatement()
- public UpdateStatement UpdateStatement()
- public DeleteStatement DeleteStatement()
- public string IdentificationVariable()
- public string AliasIdentificationVariable()
- public string AbstractSchemaName()
- public string AliasResultVariable()
- public string ResultVariable()
- public JoinAssociationPathExpression JoinAssociationPathExpression()
- public PathExpression PathExpression()
- public PathExpression AssociationPathExpression()
- public PathExpression SingleValuedPathExpression()
- public PathExpression StateFieldPathExpression()
- public PathExpression SingleValuedAssociationPathExpression()
- public PathExpression CollectionValuedPathExpression()
- public SelectClause SelectClause()
- public SimpleSelectClause SimpleSelectClause()
- public UpdateClause UpdateClause()
- public DeleteClause DeleteClause()
- public FromClause FromClause()
- public SubselectFromClause SubselectFromClause()
- public WhereClause WhereClause()
- public HavingClause HavingClause()
- public GroupByClause GroupByClause()
- public OrderByClause OrderByClause()
- public Subselect Subselect()
- public UpdateItem UpdateItem()
- public string GroupByItem()
- public OrderByItem OrderByItem()
- public void NewValue()
- public IdentificationVariableDeclaration IdentificationVariableDeclaration()
- public SubselectIdentificationVariableDeclaration SubselectIdentificationVariableDeclaration()
- public Join Join()
- public RangeVariableDeclaration RangeVariableDeclaration()
- public JoinAssociationPathExpression JoinAssociationDeclaration()
- public array PartialObjectExpression()
- public IndexBy IndexBy()
- public mixed ScalarExpression()
- public mixed CaseExpression()
- public CoalesceExpression CoalesceExpression()
- public NullIfExpression NullIfExpression()
- public GeneralExpression GeneralCaseExpression()
- public void SimpleCaseExpression()
- public WhenExpression WhenClause()
- public SimpleWhenExpression SimpleWhenClause()
- public SelectExpression SelectExpression()
- public SimpleSelectExpression SimpleSelectExpression()
- public ConditionalExpression ConditionalExpression()
- public ConditionalTerm ConditionalTerm()
- public ConditionalFactor ConditionalFactor()
- public ConditionalPrimary ConditionalPrimary()
- public void SimpleConditionalExpression()
- public EmptyCollectionComparisonExpression EmptyCollectionComparisonExpression()
- public CollectionMemberExpression CollectionMemberExpression()
- public string Literal()
- public string InParameter()
- public InputParameter InputParameter()
- public ArithmeticExpression ArithmeticExpression()
- public SimpleArithmeticExpression SimpleArithmeticExpression()
- public ArithmeticTerm ArithmeticTerm()
- public ArithmeticFactor ArithmeticFactor()
- public void ArithmeticPrimary()
- public StringPrimary StringExpression()
- public void StringPrimary()
- public SingleValuedAssociationPathExpression EntityExpression()
- public string SimpleEntityExpression()
- public AggregateExpression AggregateExpression()
- public QuantifiedExpression QuantifiedExpression()
- public BetweenExpression BetweenExpression()
- public ComparisonExpression ComparisonExpression()
- public InExpression InExpression()
- public InstanceOfExpression InstanceOfExpression()
- public mixed InstanceOfParameter()
- public LikeExpression LikeExpression()
- public NullComparisonExpression NullComparisonExpression()
- public ExistsExpression ExistsExpression()
- public string ComparisonOperator()
- public void FunctionDeclaration()
- private void CustomFunctionDeclaration()
- public void FunctionsReturningNumerics()
- public void CustomFunctionsReturningNumerics()
- public void FunctionsReturningDatetime()
- public void CustomFunctionsReturningDatetime()
- public void FunctionsReturningStrings()
- public void CustomFunctionsReturningStrings()
Tasks
Line | Task |
---|---|
249 | Is there a way to remove this? It may impact the mixed hydration resultset a lot! |
Members
private
-
$_DATETIME_FUNCTIONS
READ-ONLY: Maps BUILT-IN datetime function names to AST class names. -
$_NUMERIC_FUNCTIONS
READ-ONLY: Maps BUILT-IN numeric function names to AST class names. -
$_STRING_FUNCTIONS
READ-ONLY: Maps BUILT-IN string function names to AST class names. - $_customOutputWalker
—
Doctrine\ORM\Query\TreeWalker
The custom last tree walker, if any, that is responsible for producing the output. - $_customTreeWalkers
—
array
Any additional custom tree walkers that modify the AST. -
$_deferredIdentificationVariables
Expressions that were encountered during parsing of identifiers and expressions and still need to be validated. - $_deferredPartialObjectExpressions
- $_deferredPathExpressions
- $_deferredResultVariables
- $_em
—
Doctrine\ORM\Query\EnityManager
The EntityManager. - $_identVariableExpressions — array
- $_lexer
—
\Doctrine\ORM\Query\Lexer
The lexer. - $_nestingLevel
—
integer
Keeps the nesting level of defined ResultVariables - $_parserResult
—
\Doctrine\ORM\Query\ParserResult
The parser result. - $_query
—
Doctrine\ORM\Query
The Query to parse. - $_queryComponents
—
array
Map of declared query components in the parsed query.
Methods
private
- CustomFunctionDeclaration() — Helper function for FunctionDeclaration grammar rule
- _isAggregateFunction() — Checks whether the given token type indicates an aggregate function.
- _isFunction() — Checks if the next-next (after lookahead) token starts a function.
- _isMathOperator() — Checks if the given token indicates a mathematical operator.
- _isNextAllAnySome() — Checks whether the current lookahead token of the lexer has the type T_ALL, T_ANY or T_SOME.
- _peekBeyondClosingParenthesis() — Peek beyond the matched closing parenthesis and return the first token after that one.
- _processDeferredIdentificationVariables() — Validates that the given <tt>IdentificationVariable</tt> is semantically correct.
- _processDeferredPartialObjectExpressions() — Validates that the given <tt>PartialObjectExpression</tt> is semantically correct.
- _processDeferredPathExpressions() — Validates that the given <tt>PathExpression</tt> is semantically correct for grammar rules:
- _processDeferredResultVariables() — Validates that the given <tt>ResultVariable</tt> is semantically correct.
- _processRootEntityAliasSelected()
- fixIdentificationVariableOrder() — Fix order of identification variables.
public
- __construct() — Creates a new query parser object.
- AbstractSchemaName() — AbstractSchemaName ::= identifier
- AggregateExpression() — AggregateExpression ::= ("AVG" | "MAX" | "MIN" | "SUM") "(" ["DISTINCT"] StateFieldPathExpression ")" | "COUNT" "(" ["DISTINCT"] (IdentificationVariable | SingleValuedPathExpression) ")"
- AliasIdentificationVariable() — AliasIdentificationVariable = identifier
- AliasResultVariable() — AliasResultVariable ::= identifier
- ArithmeticExpression() — ArithmeticExpression ::= SimpleArithmeticExpression | "(" Subselect ")"
- ArithmeticFactor() — ArithmeticFactor ::= [("+" | "-")] ArithmeticPrimary
- ArithmeticPrimary() — ArithmeticPrimary ::= SingleValuedPathExpression | Literal | "(" SimpleArithmeticExpression ")" | FunctionsReturningNumerics | AggregateExpression | FunctionsReturningStrings | FunctionsReturningDatetime | IdentificationVariable | ResultVariable | InputParameter | CaseExpression
- ArithmeticTerm() — ArithmeticTerm ::= ArithmeticFactor {("*" | "/") ArithmeticFactor}
- AssociationPathExpression() — AssociationPathExpression ::= CollectionValuedPathExpression | SingleValuedAssociationPathExpression
- BetweenExpression() — BetweenExpression ::= ArithmeticExpression ["NOT"] "BETWEEN" ArithmeticExpression "AND" ArithmeticExpression
- CaseExpression() — CaseExpression ::= GeneralCaseExpression | SimpleCaseExpression | CoalesceExpression | NullifExpression GeneralCaseExpression ::= "CASE" WhenClause {WhenClause}* "ELSE" ScalarExpression "END" WhenClause ::= "WHEN" ConditionalExpression "THEN" ScalarExpression SimpleCaseExpression ::= "CASE" CaseOperand SimpleWhenClause {SimpleWhenClause}* "ELSE" ScalarExpression "END" CaseOperand ::= StateFieldPathExpression | TypeDiscriminator SimpleWhenClause ::= "WHEN" ScalarExpression "THEN" ScalarExpression CoalesceExpression ::= "COALESCE" "(" ScalarExpression {"," ScalarExpression}* ")" NullifExpression ::= "NULLIF" "(" ScalarExpression "," ScalarExpression ")"
- CoalesceExpression() — CoalesceExpression ::= "COALESCE" "(" ScalarExpression {"," ScalarExpression}* ")"
- CollectionMemberExpression() — CollectionMemberExpression ::= EntityExpression ["NOT"] "MEMBER" ["OF"] CollectionValuedPathExpression
- CollectionValuedPathExpression() — CollectionValuedPathExpression ::= IdentificationVariable "." CollectionValuedAssociationField
- ComparisonExpression() — ComparisonExpression ::= ArithmeticExpression ComparisonOperator ( QuantifiedExpression | ArithmeticExpression )
- ComparisonOperator() — ComparisonOperator ::= "=" | "<" | "<=" | "<>" | ">" | ">=" | "!="
- ConditionalExpression() — ConditionalExpression ::= ConditionalTerm {"OR" ConditionalTerm}
- ConditionalFactor() — ConditionalFactor ::= ["NOT"] ConditionalPrimary
- ConditionalPrimary() — ConditionalPrimary ::= SimpleConditionalExpression | "(" ConditionalExpression ")"
- ConditionalTerm() — ConditionalTerm ::= ConditionalFactor {"AND" ConditionalFactor}
- CustomFunctionsReturningDatetime()
- CustomFunctionsReturningNumerics()
- CustomFunctionsReturningStrings()
- DeleteClause() — DeleteClause ::= "DELETE" ["FROM"] AbstractSchemaName ["AS"] AliasIdentificationVariable
- DeleteStatement() — DeleteStatement ::= DeleteClause [WhereClause]
- EmptyCollectionComparisonExpression() — EmptyCollectionComparisonExpression ::= CollectionValuedPathExpression "IS" ["NOT"] "EMPTY"
- EntityExpression() — EntityExpression ::= SingleValuedAssociationPathExpression | SimpleEntityExpression
- ExistsExpression() — ExistsExpression ::= ["NOT"] "EXISTS" "(" Subselect ")"
- FromClause() — FromClause ::= "FROM" IdentificationVariableDeclaration {"," IdentificationVariableDeclaration}
- FunctionDeclaration() — FunctionDeclaration ::= FunctionsReturningStrings | FunctionsReturningNumerics | FunctionsReturningDatetime
- FunctionsReturningDatetime() — FunctionsReturningDateTime ::= "CURRENT_DATE" | "CURRENT_TIME" | "CURRENT_TIMESTAMP"
- FunctionsReturningNumerics() — FunctionsReturningNumerics ::= "LENGTH" "(" StringPrimary ")" | "LOCATE" "(" StringPrimary "," StringPrimary ["," SimpleArithmeticExpression]")" | "ABS" "(" SimpleArithmeticExpression ")" | "SQRT" "(" SimpleArithmeticExpression ")" | "MOD" "(" SimpleArithmeticExpression "," SimpleArithmeticExpression ")" | "SIZE" "(" CollectionValuedPathExpression ")"
- FunctionsReturningStrings() — FunctionsReturningStrings ::= "CONCAT" "(" StringPrimary "," StringPrimary ")" | "SUBSTRING" "(" StringPrimary "," SimpleArithmeticExpression "," SimpleArithmeticExpression ")" | "TRIM" "(" [["LEADING" | "TRAILING" | "BOTH"] [char] "FROM"] StringPrimary ")" | "LOWER" "(" StringPrimary ")" | "UPPER" "(" StringPrimary ")"
- GeneralCaseExpression() — GeneralCaseExpression ::= "CASE" WhenClause {WhenClause}* "ELSE" ScalarExpression "END"
- GroupByClause() — GroupByClause ::= "GROUP" "BY" GroupByItem {"," GroupByItem}
- GroupByItem() — GroupByItem ::= IdentificationVariable | ResultVariable | SingleValuedPathExpression
- HavingClause() — HavingClause ::= "HAVING" ConditionalExpression
- IdentificationVariable() — IdentificationVariable ::= identifier
- IdentificationVariableDeclaration() — IdentificationVariableDeclaration ::= RangeVariableDeclaration [IndexBy] {Join}
- InExpression() — InExpression ::= SingleValuedPathExpression ["NOT"] "IN" "(" (InParameter {"," InParameter}* | Subselect) ")"
- InParameter() — InParameter ::= Literal | InputParameter
- IndexBy() — IndexBy ::= "INDEX" "BY" StateFieldPathExpression
- InputParameter() — InputParameter ::= PositionalParameter | NamedParameter
- InstanceOfExpression() — InstanceOfExpression ::= IdentificationVariable ["NOT"] "INSTANCE" ["OF"] (InstanceOfParameter | "(" InstanceOfParameter {"," InstanceOfParameter}* ")")
- InstanceOfParameter() — InstanceOfParameter ::= AbstractSchemaName | InputParameter
- Join() — Join ::= ["LEFT" ["OUTER"] | "INNER"] "JOIN" (JoinAssociationDeclaration | RangeVariableDeclaration) ["WITH" ConditionalExpression]
- JoinAssociationDeclaration() — JoinAssociationDeclaration ::= JoinAssociationPathExpression ["AS"] AliasIdentificationVariable [IndexBy]
- JoinAssociationPathExpression() — JoinAssociationPathExpression ::= IdentificationVariable "." (CollectionValuedAssociationField | SingleValuedAssociationField)
- LikeExpression() — LikeExpression ::= StringExpression ["NOT"] "LIKE" StringPrimary ["ESCAPE" char]
- Literal() — Literal ::= string | char | integer | float | boolean
- NewValue() — NewValue ::= SimpleArithmeticExpression | StringPrimary | DatetimePrimary | BooleanPrimary | EnumPrimary | SimpleEntityExpression | "NULL"
- NullComparisonExpression() — NullComparisonExpression ::= (SingleValuedPathExpression | InputParameter) "IS" ["NOT"] "NULL"
- NullIfExpression() — NullIfExpression ::= "NULLIF" "(" ScalarExpression "," ScalarExpression ")"
- OrderByClause() — OrderByClause ::= "ORDER" "BY" OrderByItem {"," OrderByItem}
- OrderByItem() — OrderByItem ::= ( SimpleArithmeticExpression | SingleValuedPathExpression | ScalarExpression | ResultVariable ) ["ASC" | "DESC"]
- PartialObjectExpression() — PartialObjectExpression ::= "PARTIAL" IdentificationVariable "." PartialFieldSet PartialFieldSet ::= "{" SimpleStateField {"," SimpleStateField}* "}"
- PathExpression() — Parses an arbitrary path expression and defers semantical validation based on expected types.
- QuantifiedExpression() — QuantifiedExpression ::= ("ALL" | "ANY" | "SOME") "(" Subselect ")"
- QueryLanguage() — QueryLanguage ::= SelectStatement | UpdateStatement | DeleteStatement
- RangeVariableDeclaration() — RangeVariableDeclaration ::= AbstractSchemaName ["AS"] AliasIdentificationVariable
- ResultVariable() — ResultVariable ::= identifier
- ScalarExpression() — ScalarExpression ::= SimpleArithmeticExpression | StringPrimary | DateTimePrimary | StateFieldPathExpression | BooleanPrimary | CaseExpression | InstanceOfExpression
- SelectClause() — SelectClause ::= "SELECT" ["DISTINCT"] SelectExpression {"," SelectExpression}
- SelectExpression() — SelectExpression ::= ( IdentificationVariable | ScalarExpression | AggregateExpression | FunctionDeclaration | PartialObjectExpression | "(" Subselect ")" | CaseExpression ) [["AS"] ["HIDDEN"] AliasResultVariable]
- SelectStatement() — SelectStatement ::= SelectClause FromClause [WhereClause] [GroupByClause] [HavingClause] [OrderByClause]
- SimpleArithmeticExpression() — SimpleArithmeticExpression ::= ArithmeticTerm {("+" | "-") ArithmeticTerm}
- SimpleCaseExpression() — SimpleCaseExpression ::= "CASE" CaseOperand SimpleWhenClause {SimpleWhenClause}* "ELSE" ScalarExpression "END" CaseOperand ::= StateFieldPathExpression | TypeDiscriminator
- SimpleConditionalExpression() — SimpleConditionalExpression ::= ComparisonExpression | BetweenExpression | LikeExpression | InExpression | NullComparisonExpression | ExistsExpression | EmptyCollectionComparisonExpression | CollectionMemberExpression | InstanceOfExpression
- SimpleEntityExpression() — SimpleEntityExpression ::= IdentificationVariable | InputParameter
- SimpleSelectClause() — SimpleSelectClause ::= "SELECT" ["DISTINCT"] SimpleSelectExpression
- SimpleSelectExpression() — SimpleSelectExpression ::= ( StateFieldPathExpression | IdentificationVariable | FunctionDeclaration | AggregateExpression | "(" Subselect ")" | ScalarExpression ) [["AS"] AliasResultVariable]
- SimpleWhenClause() — SimpleWhenClause ::= "WHEN" ScalarExpression "THEN" ScalarExpression
- SingleValuedAssociationPathExpression() — SingleValuedAssociationPathExpression ::= IdentificationVariable "." SingleValuedAssociationField
- SingleValuedPathExpression() — SingleValuedPathExpression ::= StateFieldPathExpression | SingleValuedAssociationPathExpression
- StateFieldPathExpression() — StateFieldPathExpression ::= IdentificationVariable "." StateField
- StringExpression() — StringExpression ::= StringPrimary | "(" Subselect ")"
- StringPrimary() — StringPrimary ::= StateFieldPathExpression | string | InputParameter | FunctionsReturningStrings | AggregateExpression | CaseExpression
- Subselect() — Subselect ::= SimpleSelectClause SubselectFromClause [WhereClause] [GroupByClause] [HavingClause] [OrderByClause]
- SubselectFromClause() — SubselectFromClause ::= "FROM" SubselectIdentificationVariableDeclaration {"," SubselectIdentificationVariableDeclaration}
- SubselectIdentificationVariableDeclaration() — SubselectIdentificationVariableDeclaration ::= IdentificationVariableDeclaration | (AssociationPathExpression ["AS"] AliasIdentificationVariable)
- UpdateClause() — UpdateClause ::= "UPDATE" AbstractSchemaName ["AS"] AliasIdentificationVariable "SET" UpdateItem {"," UpdateItem}
- UpdateItem() — UpdateItem ::= SingleValuedPathExpression "=" NewValue
- UpdateStatement() — UpdateStatement ::= UpdateClause [WhereClause]
- WhenClause() — WhenClause ::= "WHEN" ConditionalExpression "THEN" ScalarExpression
- WhereClause() — WhereClause ::= "WHERE" ConditionalExpression
- addCustomTreeWalker() — Adds a custom tree walker for modifying the AST.
- free() — Free this parser enabling it to be reused
- getAST() — Parse and build AST for the given Query.
- getEntityManager() — Gets the EntityManager used by the parser.
- getLexer() — Gets the lexer used by the parser.
- getParserResult() — Gets the ParserResult that is being filled with information during parsing.
- isInternalFunction() — Check if a function is internally defined. Used to prevent overwriting of built-in functions through user-defined functions.
- match() — Attempts to match the given token with the current lookahead token.
- parse() — Parses a query string.
- semanticalError() — Generates a new semantical error.
- setCustomOutputTreeWalker() — Sets a custom tree walker that produces output.
- syntaxError() — Generates a new syntax error.