make the BNFs more readable

and add one for grouped item
This commit is contained in:
Gavin King 2022-01-04 13:39:23 +01:00
parent 008455bc0c
commit ef53b2a2de
13 changed files with 58 additions and 23 deletions

View File

@ -1882,6 +1882,16 @@ The `group by` clause looks quite similar to the `select` clause—it has a
- if there's just one item, then the query will have a single result for each unique value of that item, or
- if there are multiple items, the query will have a result for each unique _combination_ or their values.
The BNF for a grouped item is just:
[[hql-group-by-item-bnf]]
====
[source, antlrv4, indent=0]
----
include::{extrasdir}/group_by_item_bnf.txt[]
----
====
Consider the following queries:
[[hql-group-by-example]]

View File

@ -0,0 +1 @@
identifier | INTEGER_LITERAL | expression

View File

@ -1,11 +1,11 @@
limitClause
: LIMIT parameterOrIntegerLiteral
: "LIMIT" parameterOrIntegerLiteral
offsetClause
: OFFSET parameterOrIntegerLiteral (ROW | ROWS)?
: "OFFSET" parameterOrIntegerLiteral ("ROW" | "ROWS")?
fetchClause
: FETCH (FIRST | NEXT)
(parameterOrIntegerLiteral | parameterOrNumberLiteral PERCENT)
(ROW | ROWS)
(ONLY | WITH TIES)
: "FETCH" ("FIRST" | "NEXT")
(parameterOrIntegerLiteral | parameterOrNumberLiteral "%")
("ROW" | "ROWS")
("ONLY" | "WITH" "TIES")

View File

@ -1,10 +1,10 @@
sortExpression orderingSpecification? nullsPrecedence?
sortExpression sortDirection? nullsPrecedence?
sortExpression
: identifier | INTEGER_LITERAL | expression
orderingSpecification
: ASC | DESC
sortDirection
: "ASC" | "DESC"
nullsPrecedence
: NULLS (FIRST | LAST)
: "NULLS" ("FIRST" | "LAST")

View File

@ -1,7 +1,7 @@
expression NOT? IN inList
expression "NOT"? "IN" inList
inList
: (ELEMENTS|INDICES) LEFT_PAREN dotIdentifierSequence RIGHT_PAREN
| LEFT_PAREN (expression (COMMA expression)*)? RIGHT_PAREN
| LEFT_PAREN subquery RIGHT_PAREN
: ("ELEMENTS"|"INDICES") "(" simplePath ")"
| "(" (expression ("," expression)*)? ")"
| "(" subquery ")"
| parameter

View File

@ -1 +1 @@
expression NOT? (LIKE | ILIKE) expression (ESCAPE character)?
expression "NOT"? ("LIKE" | "ILIKE") expression ("ESCAPE" character)?

View File

@ -1 +1 @@
CASE (WHEN predicate THEN expression)+ (ELSE expression)? END
"CASE" ("WHEN" predicate "THEN" expression)+ ("ELSE" expression)? "END"

View File

@ -1,7 +1,7 @@
(expression | instantiation) alias?
instantiation
: NEW instantiationTarget LEFT_PAREN instantiationArgs RIGHT_PAREN
: "NEW" instantiationTarget "(" instantiationArguments ")"
alias
: AS? IDENTIFIER
: "AS"? IDENTIFIER

View File

@ -1 +1 @@
CASE expression (WHEN expression THEN expression)+ (ELSE expression)? END
"CASE" expression ("WHEN" expression "THEN" expression)+ ("ELSE" expression)? END

View File

@ -1 +1,2 @@
deleteStatement : DELETE FROM? targetEntity whereClause?
deleteStatement
: "DELETE" "FROM"? targetEntity whereClause?

View File

@ -1 +1,14 @@
insertStatement : INSERT INTO? targetEntity targetFields (queryExpression | valuesList)
insertStatement
: "INSERT" "INTO"? targetEntity targetFields (queryExpression | valuesList)
targetEntity
: entityName variable?
targetFields
: "(" simplePath ("," simplePath)* ")"
valuesList
: "VALUES" values ("," values)*
values
: "(" expression ("," expression)* ")"

View File

@ -5,7 +5,7 @@ queryExpression
: orderedQuery (setOperator orderedQuery)*
orderedQuery
: (query | LEFT_PAREN queryExpression RIGHT_PAREN) queryOrder?
: (query | "(" queryExpression ")") queryOrder?
query
: selectClause fromClause? whereClause? (groupByClause havingClause?)?

View File

@ -1 +1,11 @@
updateStatement : UPDATE VERSIONED? targetEntity setClause whereClause?
updateStatement
: "UPDATE" "VERSIONED"? targetEntity setClause whereClause?
targetEntity
: entityName variable?
setClause
: "SET" assignment ("," assignment)*
assignment
: simplePath "=" expression