Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
f6b3623
[refactor] Move existing non W3C specification compliant XQuery Updat…
adamretter Jun 10, 2023
3b5b54f
[feature] Add support for XQUF 3.0 updating and simple annotations
gabriele-tomassetti Jul 7, 2022
c02bb02
[refactor] Add detection of error XUST0032
gabriele-tomassetti Jul 7, 2022
5814ad6
[feature] Add annotation support for testing of an XQUF updating func…
gabriele-tomassetti Jul 7, 2022
669f90e
[refactor] Change SequenceType to support annotations
gabriele-tomassetti Jul 7, 2022
6fb663a
[test] Add test for annotation in testing of an updating function
gabriele-tomassetti Jul 7, 2022
98fa9f6
[feature] Add Revalidation Mode to XQueryContext
gabriele-tomassetti Jul 8, 2022
bab26ef
[feature] Add support for revalidation declaration
gabriele-tomassetti Jul 8, 2022
fd36ddc
[refactor] Add detection of error XUST0003
gabriele-tomassetti Jul 8, 2022
2d55fff
[feature] Add test for revalidation declaration
gabriele-tomassetti Jul 8, 2022
c61a4be
[feature] Add parsing support for Transform With expression
gabriele-tomassetti Jul 11, 2022
1f944c8
[feature] Add parsing support for Copy Modify expression
gabriele-tomassetti Jul 11, 2022
9b5b14c
[feature] Add CopyModifyExpression class to implement Transform With …
gabriele-tomassetti Jul 11, 2022
872ec1d
[feature] Add intermediate AST handling for Copy Modify and Transform…
gabriele-tomassetti Jul 11, 2022
9adcfb9
[test] Add tests for Copy Modify and Transform With expressions
gabriele-tomassetti Jul 11, 2022
47fc3e7
[refactor] Add Category enum to Expression in order to distinguish be…
gabriele-tomassetti Jul 11, 2022
dd9631b
[feature] Add parsing support for Dynamic updating function call
gabriele-tomassetti Jul 11, 2022
4848644
[feature] Add intermediate AST handling for dynamic updating function…
gabriele-tomassetti Jul 11, 2022
d53f922
[test] Add test for dynamic updating function call
gabriele-tomassetti Jul 11, 2022
5031dcc
[feature] Add parsing support for insert expression
gabriele-tomassetti Jul 12, 2022
d37154c
[feature] Add intermediate AST support for insert expression
gabriele-tomassetti Jul 12, 2022
e2895fa
[feature] Add InsertExpr class to support XQUF insert expression
gabriele-tomassetti Jul 12, 2022
b1d14de
[test] Add test for insert expression
gabriele-tomassetti Jul 12, 2022
ba1e1c7
[feature] Add base class ModifyingExpression to support insert, delet…
gabriele-tomassetti Jul 13, 2022
7e9057a
[refactor] Update class InsertExpr
gabriele-tomassetti Jul 13, 2022
ec9b38b
[feature] Add parsing support for delete expression
gabriele-tomassetti Jul 13, 2022
b7ee82c
[feature] Add intermediate AST support for delete expression
gabriele-tomassetti Jul 13, 2022
e7f3495
[feature] Add DeleteExpr class to support XQUF delete expression
gabriele-tomassetti Jul 13, 2022
e94b0d9
[test] Add test for delete expression
gabriele-tomassetti Jul 13, 2022
a2b8153
[feature] Add parsing support for replace expression
gabriele-tomassetti Jul 13, 2022
71d0e09
[feature] Add handling of intermediate AST for replace expression
gabriele-tomassetti Jul 13, 2022
3514f7f
[feature] Add ReplaceExpr class to implement replace expression
gabriele-tomassetti Jul 13, 2022
1d80f17
[test] Add tests for replace expression
gabriele-tomassetti Jul 13, 2022
7481ee1
[feature] Add parsing support for rename expression
gabriele-tomassetti Jul 13, 2022
391afe9
[feature] Add handling of intermediate AST for rename expression
gabriele-tomassetti Jul 13, 2022
d426c2c
[feature] Add class RenameExpr to support rename expression
gabriele-tomassetti Jul 13, 2022
ac7e942
[test] Add test for rename expression
gabriele-tomassetti Jul 13, 2022
a0ec78a
[test] Add new tests found in reference
gabriele-tomassetti Jul 20, 2022
4d774ba
[bugfix] Add missing reserved keyword 'copy'
adamretter Jun 10, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 125 additions & 9 deletions exist-core/src/main/antlr/org/exist/xquery/parser/XQuery.g
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ imaginaryTokenDefinitions
PRAGMA
GTEQ
SEQUENCE
INSERT_TARGET
;

// === XPointer ===
Expand Down Expand Up @@ -238,7 +239,7 @@ moduleDecl throws XPathException
// === Prolog ===

prolog throws XPathException
{ boolean inSetters = true; }
{ boolean inSetters = true; boolean redeclaration = false; }
:
(
(
Expand All @@ -263,8 +264,17 @@ prolog throws XPathException
( "declare" "context" "item" )
=> contextItemDeclUp { inSetters = false; }
|
( "declare" MOD )
// bare keyword updating is valid because of rule CompatibilityAnnotation in the XQUF standard
( "declare" (MOD | "updating") )
=> annotateDecl { inSetters = false; }
|
( "declare" "revalidation" )
=> revalidationDecl {
inSetters = false;
if(redeclaration)
throw new XPathException((XQueryAST) returnAST, ErrorCodes.XUST0003, "It is a static error if a Prolog contains more than one revalidation declaration.");
redeclaration = true;
}
)
SEMICOLON!
)*
Expand Down Expand Up @@ -454,6 +464,17 @@ annotation
:
MOD! name=eqName! (LPAREN! literal (COMMA! literal)* RPAREN!)?
{ #annotation= #(#[ANNOT_DECL, name], #annotation); }

| "updating"!
{
name = "updating";
#annotation= #(#[ANNOT_DECL, name], #annotation);
}
;

revalidationDecl throws XPathException
:
"declare"! "revalidation"^ ("strict" | "lax" | "skip")
;

eqName returns [String name]
Expand Down Expand Up @@ -574,7 +595,7 @@ itemType throws XPathException
:
( "item" LPAREN ) => "item"^ LPAREN! RPAREN!
|
( "function" LPAREN ) => functionTest
( ("function" LPAREN) | ( MOD ) ) => functionTest
|
( "map" LPAREN ) => mapType
|
Expand Down Expand Up @@ -609,20 +630,23 @@ atomicType throws XPathException

functionTest throws XPathException
:
( "function" LPAREN STAR RPAREN) => anyFunctionTest
|
typedFunctionTest
annotations
(
( "function" LPAREN STAR RPAREN ) => anyFunctionTest
|
typedFunctionTest
)
;

anyFunctionTest throws XPathException
:
"function"! LPAREN! s:STAR RPAREN!
annotations "function"! LPAREN! s:STAR RPAREN!
{ #anyFunctionTest = #(#[FUNCTION_TEST, "anyFunction"], #s); }
;

typedFunctionTest throws XPathException
:
"function"! LPAREN! (sequenceType (COMMA! sequenceType)*)? RPAREN! "as" sequenceType
annotations "function"! LPAREN! (sequenceType (COMMA! sequenceType)*)? RPAREN! "as" sequenceType
{ #typedFunctionTest = #(#[FUNCTION_TEST, "anyFunction"], #typedFunctionTest); }
;

Expand Down Expand Up @@ -697,6 +721,12 @@ exprSingle throws XPathException
| ( "switch" LPAREN ) => switchExpr
| ( "typeswitch" LPAREN ) => typeswitchExpr
| ( "update" ( "replace" | "value" | "insert" | "delete" | "rename" )) => updateExpr
| ( "insert" ( "node" | "nodes" ) ) => xqufInsertExpr
| ( "delete" ( "node" | "nodes" ) ) => xqufDeleteExpr
| ( "replace" ( "value" | "node" ) ) => xqufReplaceExpr
| ( "rename" "node" ) => xqufRenameExpr
| ( "copy" DOLLAR ) => copyModifyExpr
| ( "invoke" "updating" ) => dynamicUpdFunCall
| orExpr
;

Expand Down Expand Up @@ -740,6 +770,50 @@ renameExpr throws XPathException
"rename" exprSingle "as"! exprSingle
;

xqufInsertExpr throws XPathException
:
"insert"^ ( "node"! | "nodes"! ) exprSingle
insertExprTargetChoice exprSingle
;

insertExprTargetChoice throws XPathException
{ String target = null; }
:
(
( ( "as"! ( "first"! { target = "first"; } | "last"! { target = "last"; } ) )? "into"! {
if (target == null)
target = "into";
} )
| "after"! { target = "after"; }
| "before"! { target = "before"; }
)
{ #insertExprTargetChoice= #(#[INSERT_TARGET, target]); }

;

xqufDeleteExpr throws XPathException
:
"delete"^ ( "node"! | "nodes"! ) exprSingle
;

xqufReplaceExpr throws XPathException
:
"replace"^ ("value" "of"!)? "node"! exprSingle "with"! exprSingle
;

xqufRenameExpr throws XPathException
:
"rename"^ "node"! exprSingle "as"! exprSingle
;

copyModifyExpr throws XPathException
:
"copy"^ letVarBinding ( COMMA! letVarBinding )*
"modify"! exprSingle
"return"! exprSingle
;


// === try/catch ===
tryCatchExpr throws XPathException
:
Expand Down Expand Up @@ -1005,7 +1079,7 @@ castableExpr throws XPathException

castExpr throws XPathException
:
arrowExpr ( "cast"^ "as"! singleType )?
transformWithExpr ( "cast"^ "as"! singleType )?
;

comparisonExpr throws XPathException
Expand Down Expand Up @@ -1274,11 +1348,27 @@ postfixExpr throws XPathException
)*
;

dynamicUpdFunCall throws XPathException
:
"invoke"! "updating"^ primaryExpr ( argumentList )*
;

arrowExpr throws XPathException
:
unaryExpr ( ARROW_OP^ arrowFunctionSpecifier argumentList )*
;


// This is not perfectly adherent to the standard grammar
// at https://www.w3.org/TR/xquery-31/#prod-xquery31-ArrowExpr
// but the standard XQuery 3.1 grammar conflicts with the XQuery Update Facility 3.0 grammar
// https://www.w3.org/TR/xquery-update-30/#prod-xquery30-TransformWithExpr
// However, the end behavior should be identical
transformWithExpr throws XPathException
:
arrowExpr ( "transform"^ "with"! LCURLY! ( expr )? RCURLY! )?
;

arrowFunctionSpecifier throws XPathException
{ String name= null; }
:
Expand Down Expand Up @@ -2228,6 +2318,32 @@ reservedKeywords returns [String name]
"empty-sequence" { name = "empty-sequence"; }
|
"schema-element" { name = "schema-element"; }
|
"updating" { name = "updating"; }
|
"revalidation" { name = "revalidation"; }
|
"strict" { name = "strict"; }
|
"lax" { name = "lax"; }
|
"skip" { name = "skip"; }
|
"transform" { name = "transform"; }
|
"invoke" { name = "invoke"; }
|
"nodes" { name = "nodes"; }
|
"first" { name = "first"; }
|
"last" { name = "last"; }
|
"after" { name = "after"; }
|
"before" { name = "before"; }
|
"copy" { name = "copy"; }
;

/**
Expand Down
Loading