Commit 44b7e5f0 authored by guilhermeblanco's avatar guilhermeblanco

Some BNF changes and fixes...

parent 42180823
...@@ -14,10 +14,36 @@ ...@@ -14,10 +14,36 @@
* Initially Select and Sub-select DQL will not support LIMIT and OFFSET (due to limit-subquery algorithm) * Initially Select and Sub-select DQL will not support LIMIT and OFFSET (due to limit-subquery algorithm)
*/ */
/* /*
* IDENTIFIERS * TERMINALS
*
* identifier (name, email, ...)
* string ('foo', 'bar''s house', '%ninja%', ...)
* char ('/', '\\', ' ', ...)
* integer (-1, 0, 1, 34, ...)
* float (-0.23, 0.007, 1.245342E+8, ...)
* boolean (false, true)
*/
/*
* QUERY LANGUAGE (START)
*/ */
QueryLanguage ::= SelectStatement | UpdateStatement | DeleteStatement
/*
* STATEMENTS
*/
SelectStatement ::= SelectClause FromClause [WhereClause] [GroupByClause] [HavingClause] [OrderByClause]
UpdateStatement ::= UpdateClause [WhereClause]
DeleteStatement ::= DeleteClause [WhereClause]
/*
* IDENTIFIERS
*/
IdentificationVariable ::= identifier IdentificationVariable ::= identifier
/* identifier that must be a class name */ /* identifier that must be a class name */
...@@ -49,38 +75,27 @@ AssociationPathExpression ::= CollectionValuedPathExpression | SingleVa ...@@ -49,38 +75,27 @@ AssociationPathExpression ::= CollectionValuedPathExpression | SingleVa
SingleValuedPathExpression ::= StateFieldPathExpression | SingleValuedAssociationPathExpression SingleValuedPathExpression ::= StateFieldPathExpression | SingleValuedAssociationPathExpression
StateFieldPathExpression ::= {IdentificationVariable | SingleValuedAssociationPathExpression} "." StateField StateFieldPathExpression ::= {IdentificationVariable | SingleValuedAssociationPathExpression} "." StateField
SingleValuedAssociationPathExpression ::= IdentificationVariable "." {SingleValuedAssociationField "."}* SingleValuedAssociationField SingleValuedAssociationPathExpression ::= IdentificationVariable "." {SingleValuedAssociationField "."}* SingleValuedAssociationField
CollectionValuedPathExpression ::= IdentificationVariable "." {SingleValuedAssociationField "."}*CollectionValuedAssociationField CollectionValuedPathExpression ::= IdentificationVariable "." {SingleValuedAssociationField "."}* CollectionValuedAssociationField
StateField ::= {EmbeddedClassStateField "."}*SimpleStateField StateField ::= {EmbeddedClassStateField "."}* SimpleStateField
/*
* QUERY LANGUAGE (START)
*/
QueryLanguage ::= SelectStatement | UpdateStatement | DeleteStatement
/*
* STATEMENTS
*/
SelectStatement ::= SelectClause FromClause [WhereClause] [GroupByClause] [HavingClause] [OrderByClause]
UpdateStatement ::= UpdateClause [WhereClause]
DeleteStatement ::= DeleteClause [WhereClause]
/* /*
* CLAUSES * CLAUSES
*/ */
SelectClause ::= "SELECT" ["ALL" | "DISTINCT"] SelectExpression {"," SelectExpression}* SelectClause ::= "SELECT" ["ALL" | "DISTINCT"] SelectExpression {"," SelectExpression}*
SimpleSelectClause ::= "SELECT" ["ALL" | "DISTINCT"] SelectExpression SimpleSelectClause ::= "SELECT" ["ALL" | "DISTINCT"] SimpleSelectExpression
DeleteClause ::= "DELETE" ["FROM"] AbstractSchemaName [["AS"] IdentificationVariable] DeleteClause ::= "DELETE" ["FROM"] AbstractSchemaName [["AS"] IdentificationVariable]
WhereClause ::= "WHERE" ConditionalExpression WhereClause ::= "WHERE" ConditionalExpression
FromClause ::= "FROM" IdentificationVariableDeclaration {"," IdentificationVariableDeclaration}* FromClause ::= "FROM" IdentificationVariableDeclaration {"," IdentificationVariableDeclaration}*
SubselectFromClause ::= "FROM" SubselectIdentificationVariableDeclaration {"," SubselectIdentificationVariableDeclaration}*
HavingClause ::= "HAVING" ConditionalExpression HavingClause ::= "HAVING" ConditionalExpression
GroupByClause ::= "GROUP" "BY" GroupByItem {"," GroupByItem}* GroupByClause ::= "GROUP" "BY" GroupByItem {"," GroupByItem}*
OrderByClause ::= "ORDER" "BY" OrderByItem {"," OrderByItem}* OrderByClause ::= "ORDER" "BY" OrderByItem {"," OrderByItem}*
LimitClause ::= "LIMIT" integer LimitClause ::= "LIMIT" integer
OffsetClause ::= "OFFSET" integer OffsetClause ::= "OFFSET" integer
UpdateClause ::= "UPDATE" AbstractSchemaName [["AS"] IdentificationVariable] "SET" UpdateItem {"," UpdateItem}* UpdateClause ::= "UPDATE" AbstractSchemaName [["AS"] IdentificationVariable] "SET" UpdateItem {"," UpdateItem}*
/* TODO: subselect needs to be changed maybe. See JPQL spec. */ Subselect ::= SimpleSelectClause SubselectFromClause [WhereClause] [GroupByClause] [HavingClause] [OrderByClause]
Subselect ::= SimpleSelectClause FromClause [WhereClause] [GroupByClause] [HavingClause] [OrderByClause]
/* /*
* ITEMS * ITEMS
...@@ -91,21 +106,28 @@ UpdateItem ::= [IdentificationVariable"."]{StateField | SingleValuedAssociationF ...@@ -91,21 +106,28 @@ UpdateItem ::= [IdentificationVariable"."]{StateField | SingleValuedAssociationF
NewValue ::= SimpleArithmeticExpression | StringPrimary | DatetimePrimary | BooleanPrimary | NewValue ::= SimpleArithmeticExpression | StringPrimary | DatetimePrimary | BooleanPrimary |
EnumPrimary | SimpleEntityExpression | "NULL" EnumPrimary | SimpleEntityExpression | "NULL"
/* /*
* FROM/JOIN/INDEX BY * FROM/JOIN/INDEX BY
*/ */
IdentificationVariableDeclaration ::= RangeVariableDeclaration [IndexBy] {JoinVariableDeclaration}* IdentificationVariableDeclaration ::= RangeVariableDeclaration [IndexBy] {JoinVariableDeclaration}*
SubselectIdentificationVariableDeclaration ::= IdentificationVariableDeclaration | AssociationPathExpression
["AS"] IdentificationVariable
JoinVariableDeclaration ::= Join [IndexBy] JoinVariableDeclaration ::= Join [IndexBy]
RangeVariableDeclaration ::= AbstractSchemaName [AS] IdentificationVariable RangeVariableDeclaration ::= AbstractSchemaName ["AS"] IdentificationVariable
Join ::= ["LEFT" ["OUTER"] | "INNER"] "JOIN" JoinAssociationPathExpression [AS] IdentificationVariable [("ON" | "WITH") ConditionalExpression] Join ::= ["LEFT" ["OUTER"] | "INNER"] "JOIN" JoinAssociationPathExpression
["AS"] IdentificationVariable [("ON" | "WITH") ConditionalExpression]
IndexBy ::= "INDEX" "BY" StateFieldPathExpression IndexBy ::= "INDEX" "BY" StateFieldPathExpression
/* /*
* SELECT EXPRESSION * SELECT EXPRESSION
*/ */
SelectExpression ::= IdentificationVariable ["." "*"] | SelectExpression ::= IdentificationVariable ["." "*"] |
(StateFieldPathExpression | AggregateExpression | (StateFieldPathExpression | AggregateExpression |
"(" Subselect ")" ) [["AS"] FieldIdentificationVariable] "(" Subselect ")" ) [["AS"] FieldIdentificationVariable]
SimpleSelectExpression ::= SingleValuedPathExpression | IdentificationVariable | AggregateExpression
/* /*
* CONDITIONAL EXPRESSIONS * CONDITIONAL EXPRESSIONS
...@@ -114,10 +136,11 @@ ConditionalExpression ::= ConditionalTerm | ConditionalExpression "OR" Condition ...@@ -114,10 +136,11 @@ ConditionalExpression ::= ConditionalTerm | ConditionalExpression "OR" Condition
ConditionalTerm ::= ConditionalFactor | ConditionalTerm "AND" ConditionalFactor ConditionalTerm ::= ConditionalFactor | ConditionalTerm "AND" ConditionalFactor
ConditionalFactor ::= ["NOT"] ConditionalPrimary ConditionalFactor ::= ["NOT"] ConditionalPrimary
ConditionalPrimary ::= SimpleConditionalExpression | "(" ConditionalExpression ")" ConditionalPrimary ::= SimpleConditionalExpression | "(" ConditionalExpression ")"
/* EmptyCollectionComparisonExpression and CollectionMemberExpression are for the future */
SimpleConditionalExpression ::= ComparisonExpression | BetweenExpression | LikeExpression | SimpleConditionalExpression ::= ComparisonExpression | BetweenExpression | LikeExpression |
InExpression | NullComparisonExpression | ExistsExpression | InExpression | NullComparisonExpression | ExistsExpression |
EmptyCollectionComparisonExpression | CollectionMemberExpression EmptyCollectionComparisonExpression | CollectionMemberExpression
/* EmptyCollectionComparisonExpression and CollectionMemberExpression are for the future */
/* /*
* COLLECTION EXPRESSIONS (FOR THE FUTURE) * COLLECTION EXPRESSIONS (FOR THE FUTURE)
...@@ -125,7 +148,20 @@ SimpleConditionalExpression ::= ComparisonExpression | BetweenExpression | LikeE ...@@ -125,7 +148,20 @@ SimpleConditionalExpression ::= ComparisonExpression | BetweenExpression | LikeE
EmptyCollectionComparisonExpression ::= CollectionValuedPathExpression "IS" ["NOT"] "EMPTY" EmptyCollectionComparisonExpression ::= CollectionValuedPathExpression "IS" ["NOT"] "EMPTY"
CollectionMemberExpression ::= EntityExpression ["NOT"] "MEMBER" ["OF"] CollectionValuedPathExpression CollectionMemberExpression ::= EntityExpression ["NOT"] "MEMBER" ["OF"] CollectionValuedPathExpression
Atom ::= string | integer | float | boolean | input_parameter
/*
* LITERAL VALUES
*/
Literal ::= string | char | integer | float | boolean | InputParameter
/*
* INPUT PARAMETER
*/
InputParameter ::= PositionalParameter | NamedParameter
PositionalParameter ::= "?" integer
NamedParameter ::= ":" string
/* /*
* ARITHMETIC EXPRESSIONS * ARITHMETIC EXPRESSIONS
...@@ -134,28 +170,30 @@ ArithmeticExpression ::= SimpleArithmeticExpression | "(" Subselect ")" ...@@ -134,28 +170,30 @@ ArithmeticExpression ::= SimpleArithmeticExpression | "(" Subselect ")"
SimpleArithmeticExpression ::= ArithmeticTerm | SimpleArithmeticExpression ("+"|"-") ArithmeticTerm SimpleArithmeticExpression ::= ArithmeticTerm | SimpleArithmeticExpression ("+"|"-") ArithmeticTerm
ArithmeticTerm ::= ArithmeticFactor | ArithmeticTerm ("*" |"/") ArithmeticFactor ArithmeticTerm ::= ArithmeticFactor | ArithmeticTerm ("*" |"/") ArithmeticFactor
ArithmeticFactor ::= [("+" | "-")] ArithmeticPrimary ArithmeticFactor ::= [("+" | "-")] ArithmeticPrimary
ArithmeticPrimary ::= StateFieldPathExpression | Atom | "(" SimpleArithmeticExpression ")" | Function | AggregateExpression ArithmeticPrimary ::= StateFieldPathExpression | Literal | "(" SimpleArithmeticExpression ")" | Function | AggregateExpression
/* /*
* STRING/BOOLEAN/DATE/ENTITY/ENUM EXPRESSIONS * STRING/BOOLEAN/DATE/ENTITY/ENUM EXPRESSIONS
*/ */
StringExpression ::= StringPrimary | "(" Subselect ")" StringExpression ::= StringPrimary | "(" Subselect ")"
StringPrimary ::= StateFieldPathExpression | string_literal | input_parameter | FunctionsReturningStrings | AggregateExpression StringPrimary ::= StateFieldPathExpression | string | InputParameter | FunctionsReturningStrings | AggregateExpression
BooleanExpression ::= BooleanPrimary | "(" Subselect ")" BooleanExpression ::= BooleanPrimary | "(" Subselect ")"
BooleanPrimary ::= StateFieldPathExpression | boolean_literal | input_parameter BooleanPrimary ::= StateFieldPathExpression | boolean | InputParameter
EnumExpression ::= EnumPrimary | "(" Subselect ")" EnumExpression ::= EnumPrimary | "(" Subselect ")"
EnumPrimary ::= StateFieldPathExpression | enum_literal | input_parameter EnumPrimary ::= StateFieldPathExpression | string | InputParameter
EntityExpression ::= SingleValuedAssociationPathExpression | SimpleEntityExpression EntityExpression ::= SingleValuedAssociationPathExpression | SimpleEntityExpression
SimpleEntityExpression ::= IdentificationVariable | input_parameter SimpleEntityExpression ::= IdentificationVariable | InputParameter
DatetimeExpression ::= DatetimePrimary | "(" Subselect ")" DatetimeExpression ::= DatetimePrimary | "(" Subselect ")"
DatetimePrimary ::= StateFieldPathExpression | input_parameter | FunctionsReturningDatetime | AggregateExpression DatetimePrimary ::= StateFieldPathExpression | InputParameter | FunctionsReturningDatetime | AggregateExpression
/* /*
* AGGREGATE EXPRESSION * AGGREGATE EXPRESSION
*/ */
AggregateExpression ::= ("AVG" | "MAX" | "MIN" | "SUM") "(" ["DISTINCT"] StateFieldPathExpression ")" | AggregateExpression ::= ("AVG" | "MAX" | "MIN" | "SUM") "(" ["DISTINCT"] StateFieldPathExpression ")" |
"COUNT" "(" ["DISTINCT"] IdentificationVariable | SingleValuedAssociationPathExpression | StateFieldPathExpression ")" "COUNT" "(" ["DISTINCT"] (IdentificationVariable | SingleValuedAssociationPathExpression | StateFieldPathExpression) ")"
/* /*
* QUANTIFIED/BETWEEN/COMPARISON/LIKE/NULL/EXISTS EXPRESSIONS * QUANTIFIED/BETWEEN/COMPARISON/LIKE/NULL/EXISTS EXPRESSIONS
...@@ -168,12 +206,13 @@ ComparisonExpression ::= ArithmeticExpression ComparisonOperator ( Quantifie ...@@ -168,12 +206,13 @@ ComparisonExpression ::= ArithmeticExpression ComparisonOperator ( Quantifie
EnumExpression ("=" | "<>") (EnumExpression | QuantifiedExpression) | EnumExpression ("=" | "<>") (EnumExpression | QuantifiedExpression) |
DatetimeExpression ComparisonOperator (DatetimeExpression | QuantifiedExpression) | DatetimeExpression ComparisonOperator (DatetimeExpression | QuantifiedExpression) |
EntityExpression ("=" | "<>") (EntityExpression | QuantifiedExpression) EntityExpression ("=" | "<>") (EntityExpression | QuantifiedExpression)
InExpression ::= StateFieldPathExpression ["NOT"] "IN" "(" (Atom {"," Atom}* | Subselect) ")" InExpression ::= StateFieldPathExpression ["NOT"] "IN" "(" (Literal {"," Literal}* | Subselect) ")"
LikeExpression ::= ["NOT"] "LIKE" pattern_value ["ESCAPE" escape_character] LikeExpression ::= ["NOT"] "LIKE" string ["ESCAPE" char]
NullComparisonExpression ::= (SingleValuedPathExpression | input_parameter) "IS" ["NOT"] "NULL" NullComparisonExpression ::= (SingleValuedPathExpression | InputParameter) "IS" ["NOT"] "NULL"
ExistsExpression ::= ["NOT"] "EXISTS" "(" Subselect ")" ExistsExpression ::= ["NOT"] "EXISTS" "(" Subselect ")"
ComparisonOperator ::= "=" | "<" | "<=" | "<>" | ">" | ">=" | "!=" ComparisonOperator ::= "=" | "<" | "<=" | "<>" | ">" | ">=" | "!="
/* /*
* FUNCTIONS * FUNCTIONS
*/ */
...@@ -181,6 +220,7 @@ FunctionsReturningStrings ::= PortableFunctionsReturningStrings | OtherFunctions ...@@ -181,6 +220,7 @@ FunctionsReturningStrings ::= PortableFunctionsReturningStrings | OtherFunctions
FunctionsReturningNumerics ::= PortableFunctionsReturningNumerics | OtherFunctionsReturningNumerics FunctionsReturningNumerics ::= PortableFunctionsReturningNumerics | OtherFunctionsReturningNumerics
FunctionsReturningDateTime ::= PortableFunctionsReturningDateTime | OtherFunctionsReturningDateTime FunctionsReturningDateTime ::= PortableFunctionsReturningDateTime | OtherFunctionsReturningDateTime
/* /*
* OTHER FUNCTIONS: List of all allowed (but not portable) functions here. * OTHER FUNCTIONS: List of all allowed (but not portable) functions here.
*/ */
...@@ -188,6 +228,7 @@ OtherFunctionsReturningStrings ::= ... ...@@ -188,6 +228,7 @@ OtherFunctionsReturningStrings ::= ...
OtherFunctionsReturningNumerics ::= ... OtherFunctionsReturningNumerics ::= ...
OtherFunctionsReturningDateTime ::= ... OtherFunctionsReturningDateTime ::= ...
/* /*
* PORTABLE FUNCTIONS: List all portable functions here * PORTABLE FUNCTIONS: List all portable functions here
* @TODO add all supported portable functions here * @TODO add all supported portable functions here
...@@ -204,6 +245,6 @@ PortableFunctionsReturningDateTime ::= "CURRENT_DATE" | "CURRENT_TIME" | "CURREN ...@@ -204,6 +245,6 @@ PortableFunctionsReturningDateTime ::= "CURRENT_DATE" | "CURRENT_TIME" | "CURREN
PortableFunctionsReturningStrings ::= PortableFunctionsReturningStrings ::=
"CONCAT" "(" StringPrimary "," StringPrimary ")" | "CONCAT" "(" StringPrimary "," StringPrimary ")" |
"SUBSTRING" "(" StringPrimary "," SimpleArithmeticExpression "," SimpleArithmeticExpression ")" | "SUBSTRING" "(" StringPrimary "," SimpleArithmeticExpression "," SimpleArithmeticExpression ")" |
"TRIM" "(" [["LEADING" | "TRAILING" | "BOTH"] [trim_character] "FROM"] StringPrimary ")" | "TRIM" "(" [["LEADING" | "TRAILING" | "BOTH"] [char] "FROM"] StringPrimary ")" |
"LOWER" "(" StringPrimary ")" | "LOWER" "(" StringPrimary ")" |
"UPPER" "(" StringPrimary ")" "UPPER" "(" StringPrimary ")"
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment