Skip to content

Add support for XQuery Update Facility 3.0 #4956

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

Draft
wants to merge 39 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
[feature] Add support for XQUF 3.0 updating and simple annotations
  • Loading branch information
gabriele-tomassetti authored and adamretter committed Oct 14, 2023
commit 3b5b54fd7b000e1eb5eff69ee8c5828276f8623a
11 changes: 10 additions & 1 deletion exist-core/src/main/antlr/org/exist/xquery/parser/XQuery.g
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@ 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; }
)
SEMICOLON!
Expand Down Expand Up @@ -454,6 +455,12 @@ annotation
:
MOD! name=eqName! (LPAREN! literal (COMMA! literal)* RPAREN!)?
{ #annotation= #(#[ANNOT_DECL, name], #annotation); }

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

eqName returns [String name]
Expand Down Expand Up @@ -2228,6 +2235,8 @@ reservedKeywords returns [String name]
"empty-sequence" { name = "empty-sequence"; }
|
"schema-element" { name = "schema-element"; }
|
"updating" { name = "updating"; }
;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ options {
String ns = qname.getNamespaceURI();
if (ns.equals(Namespaces.XPATH_FUNCTIONS_NS)) {
String ln = qname.getLocalPart();
return ("private".equals(ln) || "public".equals(ln));
return ("private".equals(ln) || "public".equals(ln) || "updating".equals(ln) || "simple".equals(ln));
} else {
return !(ns.equals(Namespaces.XML_NS)
|| ns.equals(Namespaces.SCHEMA_NS)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/*
* eXist-db Open Source Native XML Database
* Copyright (C) 2001 The eXist-db Authors
*
* [email protected]
* http://www.exist-db.org
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package org.exist.xquery.update;

import antlr.RecognitionException;
import antlr.TokenStreamException;
import org.exist.EXistException;
import org.exist.security.PermissionDeniedException;
import org.exist.storage.BrokerPool;
import org.exist.storage.DBBroker;
import org.exist.test.ExistEmbeddedServer;
import org.exist.xquery.PathExpr;
import org.exist.xquery.XPathException;
import org.exist.xquery.XQueryContext;
import org.exist.xquery.parser.XQueryAST;
import org.exist.xquery.parser.XQueryLexer;
import org.exist.xquery.parser.XQueryParser;
import org.exist.xquery.parser.XQueryTreeParser;
import org.junit.ClassRule;
import org.junit.Test;

import java.io.StringReader;

import static org.junit.Assert.*;

/**
* @author <a href="[email protected]">Adam Retter</a>
* @author <a href="[email protected]">Gabriele Tomassetti</a>
*/
public class XQueryUpdate3Test {

@ClassRule
public static final ExistEmbeddedServer existEmbeddedServer = new ExistEmbeddedServer(true, true);

@Test
public void updatingCompatibilityAnnotation() throws EXistException, RecognitionException, XPathException, TokenStreamException, PermissionDeniedException {
final String query =
"xquery version \"3.0\"\n;" +
"module namespace t=\"http://exist-db.org/xquery/test/examples\";\n" +
"declare updating function" +
" t:upsert($e as element(), \n" +
" $an as xs:QName, \n" +
" $av as xs:anyAtomicType) \n" +
" {\n" +
" let $ea := $e/attribute()[fn:node-name(.) = $an]\n" +
" return\n" +
" $ea\n" +
" };";

final BrokerPool pool = BrokerPool.getInstance();
try (final DBBroker broker = pool.getBroker()) {
// parse the query into the internal syntax tree
final XQueryContext context = new XQueryContext(broker.getBrokerPool());
final XQueryLexer lexer = new XQueryLexer(context, new StringReader(query));
final XQueryParser xparser = new XQueryParser(lexer);
xparser.xpath();
if (xparser.foundErrors()) {
fail(xparser.getErrorMessage());
}

final XQueryAST ast = (XQueryAST) xparser.getAST();
final XQueryTreeParser treeParser = new XQueryTreeParser(context);
final PathExpr expr = new PathExpr(context);
treeParser.xpath(ast, expr);
if (treeParser.foundErrors()) {
fail(treeParser.getErrorMessage());
}
}
}

@Test
public void simpleAnnotation() throws EXistException, RecognitionException, XPathException, TokenStreamException, PermissionDeniedException {
final String query =
"xquery version \"3.0\"\n;" +
"module namespace t=\"http://exist-db.org/xquery/test/examples\";\n" +
"declare %simple function" +
" t:upsert($e as element(), \n" +
" $an as xs:QName, \n" +
" $av as xs:anyAtomicType) \n" +
" {\n" +
" let $ea := $e/attribute()[fn:node-name(.) = $an]\n" +
" return\n" +
" $ea\n" +
" };";

final BrokerPool pool = BrokerPool.getInstance();
try (final DBBroker broker = pool.getBroker()) {
// parse the query into the internal syntax tree
final XQueryContext context = new XQueryContext(broker.getBrokerPool());
final XQueryLexer lexer = new XQueryLexer(context, new StringReader(query));
final XQueryParser xparser = new XQueryParser(lexer);
xparser.xpath();
if (xparser.foundErrors()) {
fail(xparser.getErrorMessage());
return;
}

final XQueryAST ast = (XQueryAST) xparser.getAST();
final XQueryTreeParser treeParser = new XQueryTreeParser(context);
final PathExpr expr = new PathExpr(context);
treeParser.xpath(ast, expr);
if (treeParser.foundErrors()) {
fail(treeParser.getErrorMessage());
}
}
}
}