[feature] Implement declare decimal-format for XQuery 3.1#6339
Merged
Conversation
Add parser support for the XQuery 3.1 `declare decimal-format` and `declare default decimal-format` prolog declarations (spec section 4.10), enabling users to customize number formatting via fn:format-number. The runtime infrastructure (DecimalFormat class, XQueryContext storage, FnFormatNumbers 3-arg support) was already in place — this adds the missing parser recognition and tree walker processing. Changes: - XQuery.g: Add DECIMAL_FORMAT_DECL/DEF_DECIMAL_FORMAT_DECL tokens, grammar rules for named and default forms, property keywords - XQueryTree.g: Walk AST, validate properties (single-char, zero-digit, distinctness), register formats in XQueryContext - ErrorCodes.java: Add XQST0097 (duplicate) and XQST0098 (invalid) - XQueryContext.java: Add setDefaultStaticDecimalFormat() convenience - format-numbers.xql: Add tests for named/default formats, custom NaN/infinity, and error cases Closes eXist-db#56 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…dd Javadoc Rename the three decimal-format validation helper methods in XQueryTree.g with a `df` prefix to clarify their scope: - requireSingleChar → dfRequireSingleChar - validateZeroDigit → dfValidateZeroDigit - validateDistinctPictureChars → dfValidateDistinctPictureChars Add Javadoc comments on DecimalFormat.UNNAMED and UNNAMED_DECIMAL_FORMAT explaining the XPath 3.1 spec origin of the "unnamed" terminology. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Address @reinhapa's review comment on PR eXist-db#6217: convert the property-name dispatch in the decimal-format AST handler from a traditional switch/break statement into arrow-syntax cases. No behavioural change; NumberTests still pass (161 run, 0 failures). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
3 tasks
reinhapa
approved these changes
May 11, 2026
4 tasks
duncdrum
pushed a commit
that referenced
this pull request
May 11, 2026
The MathContext.DECIMAL64 cap on the final BigDecimal coercion truncated high-precision xs:decimal/xs:integer inputs to 16 significant digits. Removing the multiply-by-ONE noise op preserves full precision; the subsequent .round() still handles the maximum fractional part size. xs:double inputs are unaffected: DoubleValue.toDecimalValue() already uses BigDecimal.valueOf(value), which produces the canonical short form rather than the exact bit-pattern decimal expansion. XQTS 3.1 fn-format-number delta: - before: 74 / 77 passing (3 failures: numberformat63, numberformat64, numberformat901err -- the last unrelated, fixed by #6339) - after: 78 / 78 passing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds the XQuery 3.1
declare decimal-formatprolog declaration. Per W3C XPath/XQuery 3.1 §4.16 (https://www.w3.org/TR/xquery-31/#prod-xquery31-DecimalFormatDecl), this prolog form lets an XQuery module declare named (or default) decimal-format properties that subsequentfn:format-number()calls reference.This PR is an extraction from PR #6217 (
v2/declare-decimal-format) per the 2026-05-10 v2/* extraction audit. The whole branch is XQ 3.1-mandatory by spec — extracting it directly todevelopremoves a 3.1 conformance gap from the 7.0 release path without waiting for the broader v2/xq4-* feature set.What changed
Three commits cherry-picked from
joewiz:v2/declare-decimal-format:[feature] Implement declare decimal-format for XQuery 3.1[refactor] Address review: add df prefix to decimal-format helpers, add Javadoc[refactor] Use switch expression for decimal-format property dispatchTouched files:
exist-core/src/main/antlr/org/exist/xquery/parser/XQuery.g— addsDecimalFormatDeclproductionexist-core/src/main/antlr/org/exist/xquery/parser/XQueryTree.g— tree-walker integrationexist-core/src/main/java/org/exist/xquery/DecimalFormat.java— prolog handler with property semanticsexist-core/src/main/java/org/exist/xquery/ErrorCodes.java— addsXQST0097,XQST0098exist-core/src/main/java/org/exist/xquery/XQueryContext.java— wiringexist-core/src/test/xquery/numbers/format-numbers.xql— test additionsOne conflict resolved during cherry-pick:
ErrorCodes.javahad additive divergence between v2's older base (string-concatXQDY0101, noXQST0118/XQST0125) and currentdevelop(text-blockXQDY0101,XQST0118/XQST0125present). Resolution keptdevelop's modern forms and appended the two new decimal-format codes (XQST0097,XQST0098) using the same text-block style.Spec references
XQTS deltas (XQ 3.1, 2026-05-10)
prod-DecimalFormatDeclfn-format-numberLift matches the audit's +19-25 prediction. The remaining 6
prod-DecimalFormatDeclfailures are spec-edge cases (picture-string property validation paths) tracked separately on the v2 branch and out of scope for this minimal extraction.Test plan
mvn install -pl exist-core -am -DskipTestsgreenmvn test -pl exist-core -Dtest='xquery.numbers.NumberTests'— 161 tests, 0 failures (coversformat-numbers.xql)mvn test -pl exist-core(lock-coordinated) — 6708 tests, 0 failures, 0 errors, 97 skipped, BUILD SUCCESS in 18:49prod-DecimalFormatDeclSource
Cherry-picked from
joewiz:v2/declare-decimal-format(PR #6217). After this PR merges, PR #6217 should be closed as superseded.🤖 Generated with Claude Code