Implement declare decimal-format (XQuery 3.1)#6077
Implement declare decimal-format (XQuery 3.1)#6077joewiz wants to merge 2 commits intoeXist-db:developfrom
Conversation
4963be3 to
15c8748
Compare
line-o
left a comment
There was a problem hiding this comment.
Thank you @joewiz for this welcome and valuable addition to exist-db.
From what I can see and understand the changes make sense.
A few questions I asked myself going through the changes:
- Why is the default
UNNAMED? - The newly added function
requireSingleCharsounds like a general purpose one but it is very closely tied to decimal formats looking at the exception that is thrown - Same is true for validateZeroDigit
- validateDistinctPictureChars is less ambiguous but I think all new functions would benefit from a clear prefix like
dfor so
|
(CI note: Codacy keeps stalling on this PR, despite repeated restarts of the job. If only there were a way to restart one stalled job without restarting them all.) |
|
[Co-authored with Claude Code.] Thanks for the review, @line-o! I've pushed a commit (bb4a1a1) addressing your points:
Why |
34ec782 to
bb4a1a1
Compare
|
(CI observation: Looks like the XQTS failure needs us to implement one of the workarounds/fixes we discussed yesterday.) |
|
@joewiz Please rebase this onto current develop. I am curious about the XQTS results |
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>
bb4a1a1 to
549fffd
Compare
|
This PR lets us pass 36 additional test cases of XQTS. The two new failures are
|
|
just for reference basex has the same result as we would after this PR is applied |
Full implementation of XQuery 3.1 decimal-format declarations: - declare decimal-format name property = value ... ; - declare default decimal-format property = value ... ; All 12 properties supported: decimal-separator, grouping-separator, infinity, minus-sign, NaN, percent, per-mille, zero-digit, digit, pattern-separator, exponent-separator. Validation: - XQST0097: duplicate named or default decimal-format declarations - XQST0098: non-distinct picture-string character values - Zero-digit must be a Unicode digit with numeric value 0 - Single-character property validation Complementary to PR eXist-db#6077, which adds the same support to the ANTLR 2 grammar for the develop branch. The ANTLR 2 grammar changes are already on this branch via the parser branch lineage; this commit adds the equivalent rd parser implementation. NumberTests: 160/161 (was 153/161, +7). All format-number tests pass. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
[This comment was co-authored with Claude Code. -Joe] Closing — superseded by #6217 (v2/declare-decimal-format). This work has been consolidated into a clean v2/ branch as part of the eXist-db 7.0 PR reorganization. The new PR includes all commits from this PR plus additional related work, with reviewer feedback incorporated where applicable. See the reviewer guide for the full context. |
Full implementation of XQuery 3.1 decimal-format declarations: - declare decimal-format name property = value ... ; - declare default decimal-format property = value ... ; All 12 properties supported: decimal-separator, grouping-separator, infinity, minus-sign, NaN, percent, per-mille, zero-digit, digit, pattern-separator, exponent-separator. Validation: - XQST0097: duplicate named or default decimal-format declarations - XQST0098: non-distinct picture-string character values - Zero-digit must be a Unicode digit with numeric value 0 - Single-character property validation Complementary to PR eXist-db#6077, which adds the same support to the ANTLR 2 grammar for the develop branch. The ANTLR 2 grammar changes are already on this branch via the parser branch lineage; this commit adds the equivalent rd parser implementation. NumberTests: 160/161 (was 153/161, +7). All format-number tests pass. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary
declare decimal-formatanddeclare default decimal-formatprolog declarations (spec section 4.10)DecimalFormat,XQueryContextstorage,FnFormatNumbers3-arg support) — this adds the missing parser recognition and tree walker processingfn:format-numberChanges
XQuery.greservedKeywordsXQueryTree.gErrorCodes.javaXQST0097(duplicate declarations) andXQST0098(invalid/conflicting property values)XQueryContext.javasetDefaultStaticDecimalFormat()convenience methodformat-numbers.xqlCloses #56
See also: eXist-db/exist-xqts-runner#44 (fix copy-paste typo in XQTS runner for exponent-separator attribute)
Test plan
format-numbers.xqltests pass (0 failures, 0 errors)🤖 Generated with Claude Code