Skip to content

Commit c0abd4f

Browse files
aphillipseemelicatamorphismgibson042
authored
Implementing namespacing (#524)
* Implementing namespacing * Update syntax.md * Update formatting.md * Fix one instance of normative language * Update spec/formatting.md * Update spec/formatting.md Co-authored-by: Eemeli Aro <[email protected]> * Update message.abnf From a suggestion by @eemeli but accounting for the use of `name-part` in `variable` * Adjust to match syntax changes * Fixing list numbering and name-handling wording * Update spec/formatting.md Co-authored-by: Tim Chevalier <[email protected]> * Update spec/formatting.md Co-authored-by: Tim Chevalier <[email protected]> * Update spec/formatting.md Co-authored-by: Tim Chevalier <[email protected]> * Update spec/formatting.md Co-authored-by: Richard Gibson <[email protected]> * Remove `:` from `name-char` This makes `name` equivalent to xml-names's NCName (just like the spec text says) * Clean up references to NCName and clarify no colons * Update formatting based on comments * Update spec/formatting.md Co-authored-by: Eemeli Aro <[email protected]> * Address comments * Address part of @eemeli's feedback Removing "resolve the name" to the syntax spec. * Update syntax.md * Update spec/message.abnf Co-authored-by: Eemeli Aro <[email protected]> * Update spec/formatting.md Co-authored-by: Eemeli Aro <[email protected]> * Update spec/formatting.md Co-authored-by: Eemeli Aro <[email protected]> * Update spec/formatting.md Co-authored-by: Eemeli Aro <[email protected]> * Update spec/syntax.md Co-authored-by: Eemeli Aro <[email protected]> * Address naming of `identifier` and `name` * Implementing `identifier` and `name` in syntax.md * Implement `identifier` vs. `name` in formatting.md * Update spec/syntax.md Co-authored-by: Eemeli Aro <[email protected]> * Changes per 2023-11-27 call * Update message.abnf * Add `:` to unquoted * Update spec/formatting.md Co-authored-by: Richard Gibson <[email protected]> * Update spec/message.abnf Co-authored-by: Richard Gibson <[email protected]> * Apply suggestions from code review Co-authored-by: Richard Gibson <[email protected]> * Clean formatting * Address double-emission of unresolved variable * Update spec/formatting.md Co-authored-by: Eemeli Aro <[email protected]> * Remove extra MUSTard Co-authored-by: Eemeli Aro <[email protected]> --------- Co-authored-by: Eemeli Aro <[email protected]> Co-authored-by: Tim Chevalier <[email protected]> Co-authored-by: Richard Gibson <[email protected]>
1 parent 2bd3e6e commit c0abd4f

File tree

3 files changed

+97
-43
lines changed

3 files changed

+97
-43
lines changed

spec/formatting.md

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -197,17 +197,28 @@ the following steps are taken:
197197
198198
1. If the _expression_ includes an _operand_, resolve its value.
199199
If this fails, use a _fallback value_ for the _expression_.
200-
2. Based on the _function_ starting sigil and _name_,
201-
find the appropriate function implementation from the _function registry_.
202-
If the registry does not define an implementation for this _name_,
200+
2. Resolve the _identifier_ of the _function_ and, based on the starting sigil,
201+
find the appropriate function implementation to call.
202+
If the implementation cannot find the function,
203+
or if the _identifier_ includes a _namespace_ that the implementation does not support,
203204
emit an Unknown Function error
204205
and use a _fallback value_ for the _expression_.
205-
3. Resolve the _option_ values to a mapping of string identifiers to values.
206+
207+
Implementations are not required to implement _namespaces_ or installable
208+
_function registries_.
209+
210+
3. Resolve the _options_ to a mapping of string identifiers to values.
211+
If _options_ is missing, the mapping will be empty.
206212
For each _option_:
207-
- If its right-hand side successfully resolves to a value,
208-
bind the _name_ of the _option_ to the resolved value in the mapping.
209-
- Otherwise, do not bind the _name_ of the _option_ to any value in the mapping.
210-
4. Call the function implementation with the following arguments:
213+
- Resolve the _identifier_ of the _option_.
214+
- If the _option_'s _identifier_ already exists in the resolved mapping of _options_,
215+
emit a Duplicate Option Name error.
216+
- If the _option_'s right-hand side successfully resolves to a value,
217+
bind the _identifier_ of the _option_ to the resolved value in the mapping.
218+
- Otherwise, bind the _identifier_ of the _option_ to an unresolved value in the mapping.
219+
(Note that an Unresolved Variable error will have been emitted.)
220+
4. Remove from the resolved mapping of _options_ any binding for which the value is an unresolved value.
221+
5. Call the function implementation with the following arguments:
211222
212223
- The current _locale_.
213224
- The resolved mapping of _options_.
@@ -219,15 +230,20 @@ the following steps are taken:
219230
as long as reasonable precautions are taken to keep the function interface
220231
simple and minimal, and avoid introducing potential security vulnerabilities.
221232
222-
As implementations MAY allow custom functions to be defined by users,
223-
their access to the _formatting context_ SHOULD be minimal and read-only,
224-
and their execution time SHOULD be limited.
233+
An implementation MAY define its own functions.
234+
An implementation MAY allow custom functions to be defined by users.
235+
236+
Function access to the _formatting context_ MUST be minimal and read-only,
237+
and execution time SHOULD be limited.
238+
239+
Implementation-defined _functions_ SHOULD use an implementation-defined _namespace_.
225240
226241
5. If the call succeeds,
227242
resolve the value of the _expression_ as the result of that function call.
228243
If the call fails or does not return a valid value,
229244
emit a Resolution error and use a _fallback value_ for the _expression_.
230245
246+
231247
### Fallback Resolution
232248
233249
A **_fallback value_** is the resolved value emitted when an _expression_ cannot be resolved.
@@ -255,13 +271,13 @@ The _fallback value_ depends on the contents of the _expression_:
255271
> Example: `$user`
256272
257273
- _expression_ with no _operand_:
258-
the _function_ starting sigil followed by its _name_
274+
the _function_ starting sigil followed by its _identifier_
259275
260276
> Examples: `:platform`, `+tag`, `-tag`
261277
262278
- Otherwise: The U+FFFD REPLACEMENT CHARACTER `�` character
263279
264-
_Option_ names and values are not included in the _fallback value_.
280+
_Option_ identifiers and values are not included in the _fallback value_.
265281
266282
When an error occurs in an _expression_ with a _variable_ _operand_
267283
and the _variable_ refers to a local _declaration_,
@@ -817,7 +833,7 @@ These are divided into the following categories:
817833
> }}
818834
> ```
819835
820-
- A **Duplicate Option Name error** occurs when the same _name_
836+
- A **Duplicate Option Name error** occurs when the same _identifier_
821837
appears on the left-hand side
822838
of more than one _option_ in the same _expression_.
823839

spec/message.abnf

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ annotation = (function *(s option)) / reserved / private-use
2323

2424
literal = quoted / unquoted
2525
variable = "$" name
26-
function = (":" / "+" / "-") name
27-
option = name [s] "=" [s] (literal / variable)
26+
function = (":" / "+" / "-") identifier
27+
option = identifier [s] "=" [s] (literal / variable)
2828

2929
; reserved keywords are always lowercase
3030
input = %s"input"
@@ -45,13 +45,10 @@ quoted-char = %x0-5B ; omit \
4545
/ %x7D-D7FF ; omit surrogates
4646
/ %xE000-10FFFF
4747

48-
; based on https://www.w3.org/TR/xml/#NT-Nmtoken,
49-
; but cannot start with U+002D HYPHEN-MINUS or U+003A COLON ":"
50-
unquoted = unquoted-start *name-char
48+
unquoted = unquoted-start *(name-char / ":")
5149
unquoted-start = name-start / DIGIT / "."
5250
/ %xB7 / %x300-36F / %x203F-2040
5351

54-
5552
; reserve sigils for private-use by implementations
5653
private-use = private-start reserved-body
5754
private-start = "^" / "&"
@@ -70,15 +67,17 @@ reserved-char = %x00-08 ; omit HTAB and LF
7067
/ %x7E-D7FF ; omit surrogates
7168
/ %xE000-10FFFF
7269

73-
; based on https://www.w3.org/TR/xml/#NT-Name,
74-
; but cannot start with U+003A COLON ":"
75-
name = name-start *name-char
70+
; identifier matches https://www.w3.org/TR/REC-xml-names/#NT-QName
71+
; name matches https://www.w3.org/TR/REC-xml-names/#NT-NCName
72+
identifier = [namespace ":"] name
73+
namespace = name
74+
name = name-start *name-char
7675
name-start = ALPHA / "_"
7776
/ %xC0-D6 / %xD8-F6 / %xF8-2FF
7877
/ %x370-37D / %x37F-1FFF / %x200C-200D
7978
/ %x2070-218F / %x2C00-2FEF / %x3001-D7FF
8079
/ %xF900-FDCF / %xFDF0-FFFD / %x10000-EFFFF
81-
name-char = name-start / DIGIT / "-" / "." / ":"
80+
name-char = name-start / DIGIT / "-" / "."
8281
/ %xB7 / %x300-36F / %x203F-2040
8382

8483
text-escape = backslash ( backslash / "{" / "}" )

spec/syntax.md

Lines changed: 58 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ external input value does not appear in a _declaration_.
169169
> [!Note]
170170
> These restrictions only apply to _declarations_.
171171
> A _placeholder_ or _selector_ can apply a different annotation to a _variable_
172-
> than one applied to the same _variable_ name in a _declaration_.
172+
> than one applied to the same _variable_ named in a _declaration_.
173173
> For example, this message is _valid_:
174174
> ```
175175
> {{
@@ -482,7 +482,7 @@ and vice versa.
482482
> {+button}Submit{-button} or {+link}cancel{-link}.
483483
> ```
484484
485-
A _function_ consists of a prefix sigil followed by a _name_.
485+
A _function_ consists of a prefix sigil followed by an _identifier_.
486486
The following sigils are used for _functions_:
487487
488488
- `:` for a _standalone_ function
@@ -497,16 +497,16 @@ _Options_ are not required.
497497
An **_<dfn>option</dfn>_** is a key-value pair
498498
containing a named argument that is passed to a _function_.
499499
500-
An _option_ has a _name_ and a _value_.
501-
The _name_ is separated from the _value_ by an U+003D EQUALS SIGN `=` along with
500+
An _option_ has an _identifier_ and a _value_.
501+
The _identifier_ is separated from the _value_ by an U+003D EQUALS SIGN `=` along with
502502
optional whitespace.
503503
The value of an _option_ can be either a _literal_ or a _variable_.
504504
505505
Multiple _options_ are permitted in an _annotation_.
506506
Each _option_ is separated by whitespace.
507507
508508
```abnf
509-
option = name [s] "=" [s] (literal / variable)
509+
option = identifier [s] "=" [s] (literal / variable)
510510
```
511511
512512
> Examples of _functions_ with _options_
@@ -672,21 +672,65 @@ unquoted-start = name-start / DIGIT / "."
672672
/ %xB7 / %x300-36F / %x203F-2040
673673
```
674674

675-
### Names
675+
### Names and Identifiers
676676

677-
A **_<dfn>name</dfn>_** is an identifier for a _variable_ (prefixed with `$`),
677+
An **_<dfn>identifier</dfn>_** is a character sequence that
678+
identifies a _function_ or _option_.
679+
Each _identifier_ consists of a _name_ optionally preceeded by
680+
a _namespace_.
681+
When present, the _namespace_ is separated from the _name_ by a
682+
U+003A COLON `:`.
683+
Built-in _functions_ and their _options_ do not have a _namespace_ identifier.
684+
685+
_Function_ _identifiers_ are prefixed with `:`, `+`, or `-`.
686+
_Option_ _identifiers_ have no prefix.
687+
688+
A **_<dfn>name</dfn>_** is a character sequence used in an _identifier_
689+
or as the name for for a _variable_.
690+
691+
_Variable_ names are prefixed with `$`.
678692
for a _function_ (prefixed with `:`, `+` or `-`),
679-
or for an _option_ (these have no prefix).
680-
The namespace for _names_ is based on XML's [Name](https://www.w3.org/TR/xml/#NT-Name),
681-
with the restriction that it MUST NOT start with `:`,
682-
as that would conflict with the _function_ start character.
683-
Otherwise, the set of characters allowed in names is large.
693+
694+
Valid content for _names_ is based on <cite>Namespaces in XML 1.0</cite>'s
695+
[NCName](https://www.w3.org/TR/xml-names/#NT-NCName).
696+
This is different from XML's [Name](https://www.w3.org/TR/xml/#NT-Name)
697+
in that it MUST NOT contain a U+003A COLON `:`.
698+
Otherwise, the set of characters allowed in a _name_ is large.
699+
700+
> [!NOTE]
701+
> _External variables_ can be passed in that are not valid _names_.
702+
> Such variables cannot be referenced in a _message_,
703+
> but are not otherwise errors.
704+
705+
Examples:
706+
> A variable:
707+
>```
708+
>This has a {$variable}
709+
>```
710+
>A function:
711+
> ```
712+
> This has a {:function}
713+
> ```
714+
> An add-on function from the `icu` namespace:
715+
> ```
716+
> This has a {:icu:function}
717+
> ```
718+
> An option and an add-on option:
719+
> ```
720+
> This has {:options option=value icu:option=add_on}
721+
> ```
722+
723+
Support for _namespaces_ and their interpretation is implementation-defined
724+
in this release.
684725
685726
```abnf
686727
variable = "$" name
687-
function = (":" / "+" / "-") name
728+
function = (":" / "+" / "-") identifier
729+
option = identifier [s] "=" [s] (literal / variable)
688730
689-
name = name-start *name-char
731+
identifier = [namespace ":"] name
732+
namespace = name
733+
name = name-start *name-char
690734
name-start = ALPHA / "_"
691735
/ %xC0-D6 / %xD8-F6 / %xF8-2FF
692736
/ %x370-37D / %x37F-1FFF / %x200C-200D
@@ -696,11 +740,6 @@ name-char = name-start / DIGIT / "-" / "." / ":"
696740
/ %xB7 / %x300-36F / %x203F-2040
697741
```
698742
699-
> [!NOTE]
700-
> _External variables_ can be passed in that are not valid _names_.
701-
> Such variables cannot be referenced in a _message_,
702-
> but are not otherwise errors.
703-
704743
### Escape Sequences
705744

706745
An **_<dfn>escape sequence</dfn>_** is a two-character sequence starting with

0 commit comments

Comments
 (0)