Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions exist-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,7 @@
<include>src/test/resources/standalone-webapp/WEB-INF/web.xml</include>
<include>src/test/xquery/tail-recursion.xml</include>
<include>src/test/xquery/maps/maps.xqm</include>
<include>src/test/xquery/numbers/format-numbers.xql</include>
<include>src/test/xquery/util/util.xml</include>
<include>src/test/xquery/xquery3/parse-xml.xqm</include>
<include>src/test/xquery/xquery3/serialize.xql</include>
Expand Down Expand Up @@ -1102,6 +1103,7 @@
<include>src/test/java/org/exist/xquery/CleanupTest.java</include>
<include>src/test/java/org/exist/xquery/ConstructedNodesRecoveryTest.java</include>
<include>src/main/java/org/exist/xquery/Context.java</include>
<include>src/main/java/org/exist/xquery/DecimalFormat.java</include>
<include>src/main/java/org/exist/xquery/DeferredFunctionCall.java</include>
<include>src/main/java/org/exist/xquery/DynamicCardinalityCheck.java</include>
<include>src/main/java/org/exist/xquery/DynamicTypeCheck.java</include>
Expand Down Expand Up @@ -1284,6 +1286,7 @@
<include>src/main/java/org/exist/xquery/functions/xmldb/XMLDBStore.java</include>
<include>src/main/java/org/exist/xquery/functions/xmldb/XMLDBXUpdate.java</include>
<include>src/test/java/org/exist/xquery/functions/xquery3/TryCatchTest.java</include>
<include>src/main/antlr/org/exist/xquery/parser/XQuery.g</include>
<include>src/main/antlr/org/exist/xquery/parser/XQueryTree.g</include>
<include>src/test/java/org/exist/xquery/update/AbstractUpdateTest.java</include>
<include>src/test/java/org/exist/xquery/update/IndexIntegrationTest.java</include>
Expand Down Expand Up @@ -1374,6 +1377,7 @@
<exclude>src/test/xquery/tail-recursion.xml</exclude>
<exclude>src/test/xquery/type-promotion.xqm</exclude>
<exclude>src/test/xquery/maps/maps.xqm</exclude>
<exclude>src/test/xquery/numbers/format-numbers.xql</exclude>
<exclude>src/test/xquery/securitymanager/acl.xqm</exclude>
<exclude>src/test/xquery/util/util.xml</exclude>
<exclude>src/test/xquery/xqsuite/xqsuite-assertions-dynamic.xqm</exclude>
Expand Down Expand Up @@ -1781,6 +1785,7 @@
<exclude>src/test/java/org/exist/xquery/CleanupTest.java</exclude>
<exclude>src/test/java/org/exist/xquery/ConstructedNodesRecoveryTest.java</exclude>
<exclude>src/main/java/org/exist/xquery/Context.java</exclude>
<exclude>src/main/java/org/exist/xquery/DecimalFormat.java</exclude>
<exclude>src/main/java/org/exist/xquery/DeferredFunctionCall.java</exclude>
<exclude>src/main/java/org/exist/xquery/DynamicCardinalityCheck.java</exclude>
<exclude>src/main/java/org/exist/xquery/DynamicTypeCheck.java</exclude>
Expand Down Expand Up @@ -1989,6 +1994,7 @@
<exclude>src/main/java/org/exist/xquery/functions/xmldb/XMLDBXUpdate.java</exclude>
<exclude>src/test/java/org/exist/xquery/functions/xquery3/SerializeTest.java</exclude>
<exclude>src/test/java/org/exist/xquery/functions/xquery3/TryCatchTest.java</exclude>
<exclude>src/main/antlr/org/exist/xquery/parser/XQuery.g</exclude>
<exclude>src/main/antlr/org/exist/xquery/parser/XQueryTree.g</exclude>
<exclude>src/main/java/org/exist/xquery/pragmas/TimePragma.java</exclude>
<exclude>src/test/java/org/exist/xquery/update/AbstractUpdateTest.java</exclude>
Expand Down
66 changes: 64 additions & 2 deletions exist-core/src/main/antlr/org/exist/xquery/parser/XQuery.g
Original file line number Diff line number Diff line change
@@ -1,4 +1,28 @@
/*
* Elemental
* Copyright (C) 2024, Evolved Binary Ltd
*
* [email protected]
* https://www.evolvedbinary.com | https://www.elemental.xyz
*
* 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; version 2.1.
*
* 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
*
* NOTE: Parts of this file contain code from 'The eXist-db Authors'.
* The original license header is included below.
*
* =====================================================================
*
* eXist-db Open Source Native XML Database
* Copyright (C) 2001 The eXist-db Authors
*
Expand Down Expand Up @@ -150,6 +174,8 @@ imaginaryTokenDefinitions
NAMESPACE_DECL
DEF_NAMESPACE_DECL
DEF_COLLATION_DECL
DECIMAL_FORMAT_DECL
DEFAULT_DECIMAL_FORMAT
DEF_FUNCTION_NS_DECL
CONTEXT_ITEM_DECL
ANNOT_DECL
Expand Down Expand Up @@ -256,7 +282,7 @@ prolog throws XPathException
(
importDecl
|
( "declare" ( "default" | "boundary-space" | "ordering" | "construction" | "base-uri" | "copy-namespaces" | "namespace" ) ) =>
( "declare" ( "default" | "boundary-space" | "ordering" | "construction" | "base-uri" | "copy-namespaces" | "namespace" | "decimal-format" ) ) =>
s:setter
{
if(!inSetters)
Expand Down Expand Up @@ -295,10 +321,44 @@ versionDecl throws XPathException
{ #versionDecl = #(#[VERSION_DECL, v.getText()], enc); }
;

dfPropertyName
:
"decimal-separator"
| "grouping-separator"
| "infinity"
| "minus-sign"
| "NaN"
| "percent"
| "per-mille"
| "zero-digit"
| "digit"
| "pattern-separator"
| "exponent-separator"
;

decimalFormatDecl
{ String dfName = null; }
:
"declare"!
(
"default" "decimal-format"
( dfPropertyName EQ! STRING_LITERAL )*
{
## = #( #[DECIMAL_FORMAT_DECL, "DECIMAL_FORMAT_DECL"], #[DEFAULT_DECIMAL_FORMAT, "DEFAULT_DECIMAL_FORMAT"], ## );
}
|
"decimal-format" eqName
( dfPropertyName EQ! STRING_LITERAL )*
{
## = #( #[DECIMAL_FORMAT_DECL, "DECIMAL_FORMAT_DECL"], ## );
}
)
;

setter
:
(
( "declare" "default" ) =>
( "declare" "default" ( "collation" | "element" | "function" | "order" ) ) =>
"declare"! "default"!
(
"collation"! defc:STRING_LITERAL
Expand Down Expand Up @@ -330,6 +390,8 @@ setter
|
( "declare" "namespace" ) =>
namespaceDecl
| ( "declare" ( "default" )? "decimal-format" ) =>
decimalFormatDecl
)
;

Expand Down
71 changes: 71 additions & 0 deletions exist-core/src/main/antlr/org/exist/xquery/parser/XQueryTree.g
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ options {
protected Set<String> importedModules = new HashSet<>();
protected Set<String> importedModuleFunctions = null;
protected Set<QName> importedModuleVariables = null;
private boolean hasDefaultDecimalFormat = false;

public XQueryTreeParser(XQueryContext context) {
this(context, null);
Expand Down Expand Up @@ -511,6 +512,76 @@ throws PermissionDeniedException, EXistException, XPathException
}
)
|
#(
DECIMAL_FORMAT_DECL
{
final XQueryAST root = (XQueryAST) _t; // points to DECIMAL_FORMAT_DECL
// first sibling is either DEFAULT_DECIMAL_FORMAT (default) or EQNAME (named)
final XQueryAST dfName = (XQueryAST) root.getNextSibling();

final QName qnDfName;
if ("default".equals(dfName.getText())) {
qnDfName = XQueryContext.UNNAMED_DECIMAL_FORMAT;
if (hasDefaultDecimalFormat) {
throw new XPathException(dfName.getLine(), dfName.getColumn(), ErrorCodes.W3CErrorCode.XQST0111.getErrorCode(), "Query prolog cannot contain two default decimal format declarations.");
} else {
hasDefaultDecimalFormat = true;
}
} else {
try {
qnDfName = QName.parse(staticContext, dfName.getText(), null);
} catch (final IllegalQNameException iqe) {
throw new XPathException(dfName.getLine(), dfName.getColumn(), ErrorCodes.XPST0081, "No namespace defined for prefix " + dfName.getText());
}

if (staticContext.getStaticDecimalFormat(qnDfName) != null) {
throw new XPathException(dfName.getLine(), dfName.getColumn(), ErrorCodes.W3CErrorCode.XQST0111.getErrorCode(), "Query prolog cannot contain two decimal format declarations with the same name: " + dfName.getText());
}
}

// position current at the first property name for the decimal format
XQueryAST current = (XQueryAST) dfName.getNextSibling();
if ("default".equals(dfName.getText())) {
current = (XQueryAST) current.getNextSibling();
}

final Map<String, String> dfProperties = new HashMap<>();

while (current != null) {
final XQueryAST pname = current;
final XQueryAST pval = (XQueryAST) current.getNextSibling();

if (pval == null) {
break;
}

final String pn = pname.getText();
String pv = pval.getText();
if (pv.length() >= 2 && (pv.startsWith("\"") || pv.startsWith("'"))) {
pv = pv.substring(1, pv.length() - 1);
}
if (dfProperties.put(pn, pv) != null) {
throw new XPathException(dfName.getLine(), dfName.getColumn(), ErrorCodes.W3CErrorCode.XQST0114.getErrorCode(), "Decimal format: " + dfName.getText() + " defines the property: " + pn + " more than once.");
}

current = (XQueryAST) pval.getNextSibling();
}

final DecimalFormat df;
try {
df = DecimalFormat.fromProperties(dfProperties);
} catch (final IllegalArgumentException ex) {
throw new XPathException(dfName.getLine(), dfName.getColumn(), ErrorCodes.W3CErrorCode.XQST0097.getErrorCode(), ex.getMessage() + " within the picture string of the decimal format: " + dfName.getText() + ".");
}
if (!df.checkDistinctCharacters()) {
throw new XPathException(dfName.getLine(), dfName.getColumn(), ErrorCodes.W3CErrorCode.XQST0098.getErrorCode(), "Characters within the picture string of the decimal format: " + dfName.getText() + " are not distinct.");
}

staticContext.setStaticDecimalFormat(qnDfName, df);
context.setStaticDecimalFormat(qnDfName, df);
}
)
|
#(
qname:GLOBAL_VAR
{
Expand Down
14 changes: 7 additions & 7 deletions exist-core/src/main/java/org/exist/util/CodePointString.java
Original file line number Diff line number Diff line change
Expand Up @@ -353,14 +353,14 @@ public CodePointString insert(final int[] indexes, final int codePoint) {
* @return this
*/
public CodePointString removeFirst(final int codePoint) {
int idx = -1;
for (int i = 0; i < codePoints.length; i++) {
if (codePoints[i] == codePoint) {
idx = i;
break;
}
}
final int idx = indexOf(codePoint);
return removeChar(idx);
}

/**
* Removes the codepoint at the specified index.
*/
public CodePointString removeChar(final int idx) {
if (idx > -1) {
final int[] newCodePoints = new int[codePoints.length - 1];

Expand Down
Loading
Loading