2008-01-13 01:32:45 +03:00
|
|
|
/* Context-free grammar for Doctrine Query Language
|
|
|
|
*
|
|
|
|
* Document syntax:
|
|
|
|
* - non-terminals begin with an upper case character
|
|
|
|
* - terminals begin with a lower case character
|
|
|
|
* - parentheses (...) are used for grouping
|
|
|
|
* - square brackets [...] are used for defining an optional part, eg. zero or
|
|
|
|
* one time time
|
|
|
|
* - curly brackets {...} are used for repetion, eg. zero or more times
|
|
|
|
* - double quotation marks "..." define a terminal string
|
|
|
|
* - a vertical bar represents an alternative
|
|
|
|
*/
|
|
|
|
|
2007-12-10 23:02:41 +03:00
|
|
|
QueryLanguage = SelectStatement | UpdateStatement | DeleteStatement
|
|
|
|
|
|
|
|
SelectStatement = [SelectClause] FromClause [WhereClause] [GroupByClause] [HavingClause] [OrderByClause] [LimitClause]
|
|
|
|
UpdateStatement = UpdateClause [WhereClause] [OrderByClause] [LimitClause]
|
|
|
|
DeleteStatement = DeleteClause [WhereClause] [OrderByClause] [LimitClause]
|
|
|
|
|
|
|
|
Subselect = SimpleSelectClause FromClause [WhereClause] [GroupByClause] [HavingClause] [OrderByClause] [LimitClause] [OffsetClause]
|
|
|
|
SelectClause = "SELECT" ["ALL" | "DISTINCT"] SelectExpression {"," SelectExpression}
|
|
|
|
SimpleSelectClause = "SELECT" ["ALL" | "DISTINCT"] SelectExpression
|
|
|
|
DeleteClause = "DELETE" "FROM" RangeVariableDeclaration
|
|
|
|
WhereClause = "WHERE" ConditionalExpression
|
|
|
|
FromClause = "FROM" IdentificationVariableDeclaration {"," IdentificationVariableDeclaration}
|
|
|
|
HavingClause = "HAVING" ConditionalExpression
|
|
|
|
GroupByClause = "GROUP" "BY" GroupByItem {"," GroupByItem}
|
|
|
|
OrderByClause = "ORDER" "BY" OrderByItem {"," OrderByItem}
|
|
|
|
LimitClause = "LIMIT" Expression ["OFFSET" Expression]
|
|
|
|
UpdateClause = "UPDATE" RangeVariableDeclaration "SET" UpdateItem {"," UpdateItem}
|
|
|
|
|
2008-01-18 22:27:59 +03:00
|
|
|
OrderByItem = Expression ["ASC" | "DESC"]
|
2007-12-10 23:02:41 +03:00
|
|
|
GroupByItem = PathExpression
|
|
|
|
UpdateItem = PathExpression "=" (Expression | "NULL")
|
|
|
|
|
2008-01-13 01:32:45 +03:00
|
|
|
IdentificationVariableDeclaration = RangeVariableDeclaration {Join}
|
2008-01-18 22:27:59 +03:00
|
|
|
RangeVariableDeclaration = PathExpression [["AS"] IdentificationVariable]
|
2007-12-10 23:02:41 +03:00
|
|
|
|
2008-01-18 01:01:40 +03:00
|
|
|
Join = ["LEFT" | "INNER"] "JOIN" RangeVariableDeclaration [("ON" | "WITH") ConditionalExpression] [IndexBy]
|
|
|
|
IndexBy = "INDEX" "BY" PathExpression
|
2007-12-10 23:02:41 +03:00
|
|
|
|
|
|
|
ConditionalExpression = ConditionalTerm {"OR" ConditionalTerm}
|
|
|
|
ConditionalTerm = ConditionalFactor {"AND" ConditionalFactor}
|
|
|
|
ConditionalFactor = ["NOT"] ConditionalPrimary
|
|
|
|
ConditionalPrimary = SimpleConditionalExpression | "(" ConditionalExpression ")"
|
|
|
|
SimpleConditionalExpression
|
|
|
|
= Expression (ComparisonExpression | BetweenExpression | LikeExpression
|
|
|
|
| InExpression | NullComparisonExpression) | ExistsExpression
|
|
|
|
|
2008-01-13 01:32:45 +03:00
|
|
|
Atom = string_literal | numeric_constant | input_parameter
|
2007-12-10 23:02:41 +03:00
|
|
|
|
2008-01-13 01:32:45 +03:00
|
|
|
Expression = Term {("+" | "-") Term}
|
|
|
|
Term = Factor {("*" | "/") Factor}
|
|
|
|
Factor = [("+" | "-")] Primary
|
|
|
|
Primary = PathExpression | Atom | "(" Expression ")" | Function | AggregateExpression
|
2007-12-10 23:02:41 +03:00
|
|
|
|
2008-01-13 01:32:45 +03:00
|
|
|
SelectExpression = (PathExpressionEndingWithAsterisk | Expression | "(" Subselect ")" ) [["AS"] IdentificationVariable]
|
2007-12-10 23:02:41 +03:00
|
|
|
PathExpression = identifier {"." identifier}
|
2008-01-13 01:32:45 +03:00
|
|
|
PathExpressionEndingWithAsterisk = {identifier "."} "*"
|
2007-12-10 23:02:41 +03:00
|
|
|
|
|
|
|
AggregateExpression = ("AVG" | "MAX" | "MIN" | "SUM") "(" ["DISTINCT"] Expression ")"
|
|
|
|
| "COUNT" "(" ["DISTINCT"] (Expression | "*") ")"
|
|
|
|
|
|
|
|
QuantifiedExpression = ("ALL" | "ANY" | "SOME") "(" Subselect ")"
|
|
|
|
BetweenExpression = ["NOT"] "BETWEEN" Expression "AND" Expression
|
|
|
|
ComparisonExpression = ComparisonOperator ( QuantifiedExpression | Expression | "(" Subselect ")" )
|
|
|
|
InExpression = ["NOT"] "IN" "(" (Atom {"," Atom} | Subselect) ")"
|
2008-01-13 01:32:45 +03:00
|
|
|
LikeExpression = ["NOT"] "LIKE" Expression ["ESCAPE" string_literal]
|
2007-12-10 23:02:41 +03:00
|
|
|
NullComparisonExpression = "IS" ["NOT"] "NULL"
|
|
|
|
ExistsExpression = ["NOT"] "EXISTS" "(" Subselect ")"
|
|
|
|
|
2008-01-13 01:32:45 +03:00
|
|
|
Function = identifier "(" [Expression {"," Expression}] ")"
|