Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task 4. Implement XQuery 3.0 Update Facility #4

Open
wants to merge 38 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
04a6d12
Add support for updating and simple annotations
gabriele-tomassetti Jul 7, 2022
081e857
Add tests for new annotations
gabriele-tomassetti Jul 7, 2022
d6520cc
Add detection of error XUST0032
gabriele-tomassetti Jul 7, 2022
b8d3c37
Add annotation support for testing of an updating function
gabriele-tomassetti Jul 7, 2022
e7f7cea
Change SequenceType to support annotations
gabriele-tomassetti Jul 7, 2022
1829fff
Add test for annotation in testing of an updating function
gabriele-tomassetti Jul 7, 2022
f9570ac
Add Revalidation Mode to XQueryContext
gabriele-tomassetti Jul 8, 2022
f09dbee
Add support revalidation declaration
gabriele-tomassetti Jul 8, 2022
128ae68
Add detection of error XUST0003
gabriele-tomassetti Jul 8, 2022
134d2b0
Add test for revalidation declaration
gabriele-tomassetti Jul 8, 2022
54cc5b6
Add parsin support for Transform With expression
gabriele-tomassetti Jul 11, 2022
842a8ad
Add parsing support for Copy Modify expression
gabriele-tomassetti Jul 11, 2022
309043b
Add CopyModifyExpression class to implement Transform With and Copy M…
gabriele-tomassetti Jul 11, 2022
ad16093
Add intermediate AST handling for Copy Modify and Transform With expr…
gabriele-tomassetti Jul 11, 2022
018018a
Add tests for Copy Modify and Transform With expressions
gabriele-tomassetti Jul 11, 2022
3740ff9
Add Category enum to Expression in order to distinguish between updat…
gabriele-tomassetti Jul 11, 2022
c93d36e
Add parsing support for Dynamic updating function call
gabriele-tomassetti Jul 11, 2022
ac632e6
Add intermediate AST handling for dynamic updating function call
gabriele-tomassetti Jul 11, 2022
58ebc44
Add test for dynamic updating function call
gabriele-tomassetti Jul 11, 2022
21313a8
Add parsing support for insert expression
gabriele-tomassetti Jul 12, 2022
e814d1c
Add intermediate AST support for insert expression
gabriele-tomassetti Jul 12, 2022
dc3138b
Add InsertExpr class to support XQUF insert expression
gabriele-tomassetti Jul 12, 2022
b18b13e
Add test for insert expression
gabriele-tomassetti Jul 12, 2022
36d2ba3
Add base class ModifyingExpression to support insert, delete, replace…
gabriele-tomassetti Jul 13, 2022
6fa890e
Update class InsertExpr
gabriele-tomassetti Jul 13, 2022
c1a66e9
Add parsing support for delete expression
gabriele-tomassetti Jul 13, 2022
447269b
Add intermediate AST support for delete expression
gabriele-tomassetti Jul 13, 2022
f730cb9
Add DeleteExpr class to support XQUF delete expression
gabriele-tomassetti Jul 13, 2022
57b4cf1
Add test for delete expression
gabriele-tomassetti Jul 13, 2022
0f69177
Add parsing support for replace expression
gabriele-tomassetti Jul 13, 2022
df1f086
Add handling of intermediate AST for replace expression
gabriele-tomassetti Jul 13, 2022
db081c4
Add ReplaceExpr class to implement replace expression
gabriele-tomassetti Jul 13, 2022
977777a
Add tests for replace expression
gabriele-tomassetti Jul 13, 2022
9246ea8
Add parsing support for rename expression
gabriele-tomassetti Jul 13, 2022
61cf0e3
Add handling of intermediate AST for rename expression
gabriele-tomassetti Jul 13, 2022
cf3dd0c
Add class RenameExpr to support rename expression
gabriele-tomassetti Jul 13, 2022
98d754b
Add test for rename expression
gabriele-tomassetti Jul 13, 2022
ac450e1
Add new tests found in reference
gabriele-tomassetti Jul 20, 2022
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
132 changes: 123 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 @@ -456,6 +466,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 @@ -576,7 +597,7 @@ itemType throws XPathException
:
( "item" LPAREN ) => "item"^ LPAREN! RPAREN!
|
( "function" LPAREN ) => functionTest
( ("function" LPAREN) | ( MOD ) ) => functionTest
|
( "map" LPAREN ) => mapType
|
Expand Down Expand Up @@ -611,20 +632,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 @@ -699,6 +723,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 @@ -742,6 +772,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 @@ -1007,7 +1081,7 @@ castableExpr throws XPathException

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

comparisonExpr throws XPathException
Expand Down Expand Up @@ -1276,11 +1350,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 @@ -2224,6 +2314,30 @@ reservedKeywords returns [String name]
"map" { name = "map"; }
|
"array" { name = "array"; }
|
"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"; }
;

/**
Expand Down
Loading