Skip to content

Commit c7dcfec

Browse files
gabriele-tomassettiadamretter
authored andcommitted
[feature] Add support for Count Expression
1 parent 20fbdc9 commit c7dcfec

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

exist-core/src/main/antlr/org/exist/xquery/parser/XQuery.g

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,14 +802,21 @@ initialClause throws XPathException
802802
803803
intermediateClause throws XPathException
804804
:
805-
( initialClause | whereClause | groupByClause | orderByClause )
805+
( initialClause | whereClause | groupByClause | orderByClause | countClause )
806806
;
807807
808808
whereClause throws XPathException
809809
:
810810
"where"^ exprSingle
811811
;
812812
813+
countClause throws XPathException
814+
{ String varName; }
815+
:
816+
"count"^ DOLLAR! varName=varName!
817+
{ #countClause = #(#countClause, #[VARIABLE_BINDING, varName]); }
818+
;
819+
813820
forClause throws XPathException
814821
:
815822
"for"^ inVarBinding ( COMMA! inVarBinding )*
@@ -2223,6 +2230,8 @@ reservedKeywords returns [String name]
22232230
|
22242231
"array" { name = "array"; }
22252232
|
2233+
"count" { name = "count"; }
2234+
|
22262235
"copy-namespaces" { name = "copy-namespaces"; }
22272236
|
22282237
"empty-sequence" { name = "empty-sequence"; }

exist-core/src/main/antlr/org/exist/xquery/parser/XQueryTree.g

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1752,9 +1752,22 @@ throws PermissionDeniedException, EXistException, XPathException
17521752
clauses.add(clause);
17531753
}
17541754
)
1755-
)+
1756-
step=expr [(PathExpr) action]
1757-
{
1755+
|
1756+
#(
1757+
co:"count"
1758+
countVarName:VARIABLE_BINDING
1759+
{
1760+
ForLetClause clause = new ForLetClause();
1761+
clause.ast = co;
1762+
clause.varName = countVarName.getText();
1763+
clause.type = FLWORClause.ClauseType.COUNT;
1764+
clause.inputSequence = null;
1765+
clauses.add(clause);
1766+
}
1767+
)
1768+
)+
1769+
step=expr [(PathExpr) action]
1770+
{
17581771
for (int i= clauses.size() - 1; i >= 0; i--) {
17591772
ForLetClause clause= (ForLetClause) clauses.get(i);
17601773
FLWORClause expr;

exist-core/src/main/java/org/exist/xquery/FLWORClause.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
public interface FLWORClause extends Expression {
3232

3333
enum ClauseType {
34-
FOR, LET, GROUPBY, ORDERBY, WHERE, SOME, EVERY
34+
FOR, LET, GROUPBY, ORDERBY, WHERE, SOME, EVERY, COUNT
3535
}
3636

3737
/**

0 commit comments

Comments
 (0)