Skip to content

Commit

Permalink
(registry.dtd) Rename pattern to validationRule
Browse files Browse the repository at this point in the history
We already use `pattern` to describe a sequence of text and placeholders in the message body. Let's not overload it with another, validation-related meaning. I had picked `pattern` in `registry.dtd` because of "regex patterns", but I think we can do better than that.

This PR also changes some `NMTOKEN` attributes to `IDREF`, as noticed by @eemeli in unicode-org#407 (comment).

This PR doesn't address the main question of unicode-org#407, however. It's only concerned with renaming `pattern` to prevent confusion.
  • Loading branch information
stasm committed Aug 14, 2023
1 parent 2528e8d commit b864a99
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 40 deletions.
14 changes: 7 additions & 7 deletions spec/registry.dtd
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<!ELEMENT registry (function,pattern)*>
<!ELEMENT registry (function|validationRule)*>

<!ELEMENT function (description,(formatSignature|matchSignature)+)>
<!ATTLIST function name NMTOKEN #REQUIRED>

<!ELEMENT description (#PCDATA)>

<!ELEMENT pattern EMPTY>
<!ATTLIST pattern id ID #REQUIRED>
<!ATTLIST pattern regex CDATA #REQUIRED>
<!ELEMENT validationRule EMPTY>
<!ATTLIST validationRule id ID #REQUIRED>
<!ATTLIST validationRule regex CDATA #REQUIRED>

<!ELEMENT formatSignature (input?,option*)>
<!ATTLIST formatSignature position (open|close|standalone) "standalone">
Expand All @@ -18,17 +18,17 @@

<!ELEMENT input EMPTY>
<!ATTLIST input values NMTOKENS #IMPLIED>
<!ATTLIST input pattern NMTOKEN #IMPLIED>
<!ATTLIST input validationRule IDREF #IMPLIED>
<!ATTLIST input readonly (true|false) "false">

<!ELEMENT option EMPTY>
<!ATTLIST option name NMTOKEN #REQUIRED>
<!ATTLIST option values NMTOKENS #IMPLIED>
<!ATTLIST option default NMTOKEN #IMPLIED>
<!ATTLIST option pattern IDREF #IMPLIED>
<!ATTLIST option validationRule IDREF #IMPLIED>
<!ATTLIST option required (true|false) "false">
<!ATTLIST option readonly (true|false) "false">

<!ELEMENT match EMPTY>
<!ATTLIST match values NMTOKENS #IMPLIED>
<!ATTLIST match pattern NMTOKEN #IMPLIED>
<!ATTLIST match validationRule IDREF #IMPLIED>
40 changes: 20 additions & 20 deletions spec/registry.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ The main building block of the registry is the `<function>` element.
It represents an implementation of a custom function available to translation at runtime.
A function defines a human-readable _description_ of its behavior
and one or more machine-readable _signatures_ of how to call it.
Named `<pattern>` elements can optionally define regex validation rules for
Named `<validationRule>` elements can optionally define regex validation rules for
literals, option values, and variant keys.

MessageFormat 2 functions can be invoked in two contexts:
Expand All @@ -59,7 +59,7 @@ A signature may also define one or more `<option>` elements representing _named
An option can be omitted in a call to the function,
unless the `required` attribute is present.
They accept either a finite enumeration of values (the `values` attribute)
or validate their input with a regular expression (the `pattern` attribute).
or validate their input with a regular expression (the `validationRule` attribute).
Read-only options (the `readonly` attribute) can be displayed to translators in CAT tools, but may not be edited.

Matching-function signatures additionally include one or more `<match>` elements
Expand All @@ -83,9 +83,9 @@ For the sake of brevity, only `locales="en"` is considered.
</matchSignature>
</function>

<pattern id="anyNumber" regex="-?[0-9]+(\.[0-9]+)"/>
<pattern id="positiveInteger" regex="[0-9]+"/>
<pattern id="currencyCode" regex="[A-Z]{3}"/>
<validationRule id="anyNumber" regex="-?[0-9]+(\.[0-9]+)"/>
<validationRule id="positiveInteger" regex="[0-9]+"/>
<validationRule id="currencyCode" regex="[A-Z]{3}"/>

<function name="number">
<description>
Expand All @@ -94,27 +94,27 @@ For the sake of brevity, only `locales="en"` is considered.
</description>

<matchSignature locales="en">
<input pattern="anyNumber"/>
<input validationRule="anyNumber"/>
<option name="type" values="cardinal ordinal"/>
<option name="minimumIntegerDigits" pattern="positiveInteger"/>
<option name="minimumFractionDigits" pattern="positiveInteger"/>
<option name="maximumFractionDigits" pattern="positiveInteger"/>
<option name="minimumSignificantDigits" pattern="positiveInteger"/>
<option name="maximumSignificantDigits" pattern="positiveInteger"/>
<option name="minimumIntegerDigits" validationRule="positiveInteger"/>
<option name="minimumFractionDigits" validationRule="positiveInteger"/>
<option name="maximumFractionDigits" validationRule="positiveInteger"/>
<option name="minimumSignificantDigits" validationRule="positiveInteger"/>
<option name="maximumSignificantDigits" validationRule="positiveInteger"/>
<!-- Since this applies to both cardinal and ordinal, all plural options are valid. -->
<match values="zero one two few many"/>
<match pattern="anyNumber"/>
<match validationRule="anyNumber"/>
</matchSignature>

<formatSignature locales="en">
<input pattern="anyNumber"/>
<option name="minimumIntegerDigits" pattern="positiveInteger"/>
<option name="minimumFractionDigits" pattern="positiveInteger"/>
<option name="maximumFractionDigits" pattern="positiveInteger"/>
<option name="minimumSignificantDigits" pattern="positiveInteger"/>
<option name="maximumSignificantDigits" pattern="positiveInteger"/>
<input validationRule="anyNumber"/>
<option name="minimumIntegerDigits" validationRule="positiveInteger"/>
<option name="minimumFractionDigits" validationRule="positiveInteger"/>
<option name="maximumFractionDigits" validationRule="positiveInteger"/>
<option name="minimumSignificantDigits" validationRule="positiveInteger"/>
<option name="maximumSignificantDigits" validationRule="positiveInteger"/>
<option name="style" readonly="true" values="decimal currency percent unit" default="decimal"/>
<option name="currency" readonly="true" pattern="currencyCode"/>
<option name="currency" readonly="true" validationRule="currencyCode"/>
</formatSignature>
</function>
</registry>
Expand All @@ -134,7 +134,7 @@ which allow to validate the variant keys.
If at least one `<match>` validation rules passes,
a variant key is considered valid.

- `<match pattern="anyNumber"/>` can be used to valide the `when 1` variant
- `<match validationRule="anyNumber"/>` can be used to valide the `when 1` variant
by testing the `1` key against the `anyNumber` regular expression defined in the registry file.
- `<match values="one other"/>` can be used to valide the `when other` variant
by verifying that the `other` key is present in the list of enumarated values: `one other`.
Expand Down
26 changes: 13 additions & 13 deletions spec/registry.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
<?xml-model href="registry.dtd" type="application/xml-dtd"?>
<registry>
<!-- All regex here are to be seen as provisory. See issue #422. -->
<pattern id="anyNumber" regex="-?(0|([1-9]\d*))(\.\d*)?([eE][-+]?\d+)?"/>
<pattern id="positiveInteger" regex="0|([1-9]\d*)"/>
<pattern id="currencyCode" regex="[A-Z]{3}"/>
<pattern id="timeZoneId" regex="[a-zA-Z/]+"/>
<pattern id="anythingNotEmpty" regex=".+"/>
<pattern id="iso8601" regex="\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}"/>
<validationRule id="anyNumber" regex="-?(0|([1-9]\d*))(\.\d*)?([eE][-+]?\d+)?"/>
<validationRule id="positiveInteger" regex="0|([1-9]\d*)"/>
<validationRule id="currencyCode" regex="[A-Z]{3}"/>
<validationRule id="timeZoneId" regex="[a-zA-Z/]+"/>
<validationRule id="anythingNotEmpty" regex=".+"/>
<validationRule id="iso8601" regex="\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}"/>

<function name="datetime">
<!-- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat -->
<description>Locale-sensitive date and time formatting</description>

<formatSignature>
<input pattern="iso8601"/>
<input validationRule="iso8601"/>
<!-- The predefined date formatting style to use. -->
<option name="dateStyle" values="full long medium short"/>
<!-- The predefined time formatting style to use. -->
Expand All @@ -29,15 +29,15 @@
time zone database, such as "Asia/Shanghai", "Asia/Kolkata",
"America/New_York".
-->
<option name="timeZone" pattern="timeZoneId"/>
<option name="timeZone" validationRule="timeZoneId"/>
</formatSignature>

<!-- TODO: clarify if this is OK or if it is an abuse.
The intention is to show that dateStyle / timeStyle and the other
options are conflicting, you can use either / or, but not both.
-->
<formatSignature>
<input pattern="iso8601"/>
<input validationRule="iso8601"/>
<!-- Calendar to use. -->
<option name="calendar" values="buddhist chinese coptic dangi ethioaa ethiopic gregory hebrew indian islamic islamic-umalqura islamic-tbla islamic-civil islamic-rgsa iso8601 japanese persian roc"/>
<!-- The formatting style used for day periods like "in the morning", "am", "noon", "n" etc. -->
Expand All @@ -49,7 +49,7 @@
Implementations may also recognize the time zone names of the IANA time zone
database, such as "Asia/Shanghai", "Asia/Kolkata", "America/New_York".
-->
<option name="timeZone" pattern="timeZoneId"/>
<option name="timeZone" validationRule="timeZoneId"/>
<!-- The hour cycle to use. -->
<option name="hourCycle" values="h11 h12 h23 h24"/>
<!-- The representation of the weekday. -->
Expand Down Expand Up @@ -82,7 +82,7 @@
<description>Locale-sensitive number formatting</description>

<formatSignature>
<input pattern="anyNumber"/>
<input validationRule="anyNumber"/>
<!-- Only used when notation is "compact". -->
<option name="compactDisplay" values="short long" default="short"/>
<!-- The currency to use in currency formatting.
Expand All @@ -92,7 +92,7 @@
(https://www.six-group.com/en/products-services/financial-information/data-standards.html#scrollTo=currency-codes).
There is no default value; if the style is "currency", the currency property must be provided.
-->
<option name="currency" pattern="currencyCode"/>
<option name="currency" validationRule="currencyCode"/>
<!-- How to display the currency in currency formatting. -->
<option name="currencyDisplay" values="symbol narrowSymbol code name" default="symbol"/>
<!-- In many locales, accounting format means to wrap the number with parentheses
Expand All @@ -115,7 +115,7 @@
Pairs of simple units can be concatenated with "-per-" to make a compound unit.
There is no default value; if the style is "unit", the unit property must be provided.
-->
<option name="unit" pattern="anythingNotEmpty"/>
<option name="unit" validationRule="anythingNotEmpty"/>
<!-- The unit formatting style to use in unit formatting. -->
<option name="unitDisplay" values="long short narrow" default="short"/>
<!-- The minimum number of integer digits to use.
Expand Down

0 comments on commit b864a99

Please sign in to comment.