Skip to content

Implement declare decimal-format for XQuery 3.1#6217

Closed
joewiz wants to merge 4 commits into
eXist-db:developfrom
joewiz:v2/declare-decimal-format
Closed

Implement declare decimal-format for XQuery 3.1#6217
joewiz wants to merge 4 commits into
eXist-db:developfrom
joewiz:v2/declare-decimal-format

Conversation

@joewiz
Copy link
Copy Markdown
Member

@joewiz joewiz commented Apr 6, 2026

Summary

Implements declare decimal-format and declare default decimal-format prolog declarations per XQuery 3.1. Addresses review comments from @line-o on PR #6077.

Note: This branch is based on the merged grammar (requires v2/w3c-xquery-update-3.0 + v2/xqft-phase2 + v2/xquery-4.0-parser to be merged first).

Spec References

Tests

  • NumberTests: 161 run, 0 failures
  • Codacy: 0 issues

Supersedes

Test plan

  • exist-core unit tests pass (NumberTests 161 run, 0 failures)
  • All format-number tests with decimal-format declarations pass
  • Error codes: XQST0097 (duplicate), FODF1310 (invalid zero-digit)

🤖 Generated with Claude Code

joewiz and others added 2 commits April 13, 2026 09:25
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>
@joewiz joewiz force-pushed the v2/declare-decimal-format branch from c4344b7 to 8febcfd Compare April 13, 2026 13:26
@line-o
Copy link
Copy Markdown
Member

line-o commented Apr 14, 2026

@joewiz what is needed for this PR to be ready?

@line-o line-o added enhancement new features, suggestions, etc. xquery issue is related to xquery implementation labels Apr 14, 2026
@joewiz joewiz marked this pull request as ready for review April 14, 2026 13:43
@joewiz joewiz requested a review from a team as a code owner April 14, 2026 13:43
@joewiz
Copy link
Copy Markdown
Member Author

joewiz commented Apr 14, 2026

[This response was co-authored with Claude Code. -Joe]

CI state: 5/9 checks pass. Of the 4 failures:

  • 3 are pre-existing integration test hangs (ubuntu, windows, macOS)
  • 1 ("Test and Publish Container Images") was a transient HTTP 502 from exist-db.org's public XAR repo — not a code issue

Dependencies: Wave 3. Must merge after v2/w3c-xquery-update-3.0 (#6214), v2/xqft-phase2 (#6215), and v2/xquery-4.0-parser (#6216) — this PR's grammar base depends on all three. It is the last of the four grammar PRs.

For full context on all 7.0 PRs and the merge order, see the Reviewer Guide.

@duncdrum duncdrum added the blocked blocked by a 3rd party label Apr 14, 2026
@duncdrum duncdrum added this to v7.0.0 Apr 14, 2026
@duncdrum duncdrum added this to the eXist-7.0.0 milestone Apr 14, 2026
@line-o
Copy link
Copy Markdown
Member

line-o commented May 4, 2026

Does this PR close #56 ?

…-format

# Conflicts:
#	exist-core/src/main/java/org/exist/xquery/ErrorCodes.java
@joewiz
Copy link
Copy Markdown
Member Author

joewiz commented May 4, 2026

@line-o Yes, I believe it does.

Comment thread exist-core/src/main/antlr/org/exist/xquery/parser/XQueryTree.g
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>
@joewiz
Copy link
Copy Markdown
Member Author

joewiz commented May 10, 2026

[This response was co-authored with Claude Code. -Joe]

Per the 2026-05-10 v2/* extraction audit, the four commits in this branch are entirely XQ 3.1-mandatory (W3C XPath/XQuery 3.1 §4.16) with no dependency on Saxon 12, the new parser, or XQ 4.0 grammar extensions. Extracted to a new PR against develop for the eXist 7.0 conformance push: #6339.

The extraction was done as a clean cherry-pick of the three substantive commits (skipping the develop merge commit). One additive conflict in ErrorCodes.java was resolved to keep develop's modern text-block form. Verified locally with full mvn test -pl exist-core (6708/0/0) and XQTS XQ 3.1 (prod-DecimalFormatDecl 2/30 → 23/29, +21 passing — matches the audit's +19-25 prediction).

Recommend closing this PR as superseded once #6339 merges.

line-o pushed a commit that referenced this pull request May 11, 2026
Address @reinhapa's review comment on PR #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>
@line-o
Copy link
Copy Markdown
Member

line-o commented May 12, 2026

@duncdrum is this PR still blocked? I would rather add it to Wave 2
@joewiz would you rebase this, please.

@line-o
Copy link
Copy Markdown
Member

line-o commented May 12, 2026

superseded by #6339

@line-o line-o closed this May 12, 2026
@github-project-automation github-project-automation Bot moved this to Done in v7.0.0 May 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

blocked blocked by a 3rd party enhancement new features, suggestions, etc. xquery issue is related to xquery implementation

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants