Skip to content

Commit 55caa12

Browse files
committed
Add section on Function Handlers, defining the term
1 parent 6e93724 commit 55caa12

File tree

3 files changed

+55
-92
lines changed

3 files changed

+55
-92
lines changed

spec/errors.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,10 +283,10 @@ with a _resolved value_ which does not support selection.
283283
## Message Function Errors
284284
285285
A **_<dfn>Message Function Error</dfn>_** is any error that occurs
286-
when calling a message function implementation
286+
when calling a _function handler_
287287
or which depends on validation associated with a specific function.
288288
289-
Implementations SHOULD provide a way for _functions_ to emit
289+
Implementations SHOULD provide a way for _function handlers_ to emit
290290
(or cause to be emitted) any of the types of error defined in this section.
291291
Implementations MAY also provide implementation-defined _Message Function Error_ types.
292292
@@ -300,7 +300,7 @@ Implementations MAY also provide implementation-defined _Message Function Error_
300300
> 3. Uses a `:get` message function which requires its argument to be an object and
301301
> an option `field` to be provided with a string value.
302302
>
303-
> The exact type of _Message Function Error_ is determined by the message function implementation.
303+
> The exact type of _Message Function Error_ is determined by the _function handler_.
304304
>
305305
> ```
306306
> Hello, {horse :get field=name}!

spec/formatting.md

Lines changed: 49 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ as long as the final _formatting_ result is made available to users
4040
and the observable behavior of the _formatting_ matches that described here.
4141

4242
_Attributes_ MUST NOT have any effect on the formatted output of a _message_,
43-
nor be made available to function implementations.
43+
nor be made available to _function handlers_.
4444

4545
> [!IMPORTANT]
4646
>
@@ -77,7 +77,7 @@ At a minimum, it includes:
7777
This is often determined by a user-provided argument of a formatting function call.
7878

7979
- The _function registry_,
80-
providing the implementations of the functions referred to by message _functions_.
80+
providing the _function handlers_ of the functions referred to by message _functions_.
8181

8282
- Optionally, a fallback string to use for the message if it is not _valid_.
8383

@@ -99,6 +99,16 @@ which is available for use by later _expressions_.
9999
Since a _variable_ can be referenced in different ways later,
100100
implementations SHOULD NOT immediately fully format the value for output.
101101

102+
> For example, in
103+
> ```
104+
> .input {$a :number minimumIntegerDigits=3}
105+
> .local $b = {$a :number maximumFractionDigits=3}
106+
> ```
107+
> the value bound to `$a` is the
108+
> _resolved value_ used as the _operand_
109+
> of the `:number` _function_
110+
> when resolving the value of the _variable_ `$b`.
111+
102112
In an _input-declaration_, the _variable_ operand of the _variable-expression_
103113
identifies not only the name of the external input value,
104114
but also the _variable_ to which the _resolved value_ of the _variable-expression_ is bound.
@@ -109,7 +119,7 @@ The form that _resolved values_ take is implementation-dependent,
109119
and different implementations MAY choose to perform different levels of resolution.
110120
111121
> While this specification does not require it,
112-
> a _resolved value_ could be implemented by requiring each function implementation to
122+
> a _resolved value_ could be implemented by requiring each _function handler_ to
113123
> return a value matching the following interface:
114124
>
115125
> ```ts
@@ -243,8 +253,8 @@ the following steps are taken:
243253
1. If the _expression_ includes an _operand_, resolve its value.
244254
If this fails, use a _fallback value_ for the _expression_.
245255
2. Resolve the _identifier_ of the _function_ and, based on the starting sigil,
246-
find the appropriate function implementation to call.
247-
If the implementation cannot find the function,
256+
find the appropriate _function handler_ to call.
257+
If the implementation cannot find the _function handler_,
248258
or if the _identifier_ includes a _namespace_ that the implementation does not support,
249259
emit an _Unknown Function_ error
250260
and use a _fallback value_ for the _expression_.
@@ -254,109 +264,64 @@ the following steps are taken:
254264
255265
3. Perform _option resolution_.
256266
257-
4. Call the function implementation with the following arguments:
267+
4. Call the _function handler_ with the following arguments:
258268
259269
- The current _locale_.
260270
- The resolved mapping of _options_.
261271
- If the _expression_ includes an _operand_, its _resolved value_.
262272
263273
The form that resolved _operand_ and _option_ values take is implementation-defined.
264274
265-
A _declaration_ binds the _resolved value_ of an _expression_
266-
to a _variable_.
267-
Thus, the result of one _function_ is potentially the _operand_
268-
of another _function_,
269-
or the value of one of the _options_ for another function.
270-
For example, in
271-
```
272-
.input {$n :number minimumIntegerDigits=3}
273-
.local $n1 = {$n :number maximumFractionDigits=3}
274-
```
275-
the value bound to `$n` is the
276-
_resolved value_ used as the _operand_
277-
of the `:number` _function_
278-
when resolving the value of the _variable_ `$n1`.
279-
280-
Implementations that provide a means for defining custom functions
281-
SHOULD provide a means for function implementations
282-
to return values that contain enough information
283-
(e.g. a representation of
284-
the resolved _operand_ and _option_ values
285-
that the function was called with)
286-
to be used as arguments to subsequent calls
287-
to the function implementations.
288-
For example, an implementation might define an interface that allows custom function implementation.
289-
Such an interface SHOULD define an implementation-specific
290-
argument type `T` and return type `U`
291-
for implementations of functions
292-
such that `U` can be coerced to `T`.
293-
Implementations of a _function_ SHOULD emit a
294-
_Bad Operand_ error for _operands_ whose _resolved value_
295-
or type is not supported.
296-
297-
> [!NOTE]
298-
> The behavior of the previous example is
299-
> currently implementation-dependent. Supposing that
300-
> the external input variable `n` is bound to the string `"1"`,
301-
> and that the implementation formats to a string,
302-
> the formatted result of the following message:
303-
>
304-
> ```
305-
> .input {$n :number minimumIntegerDigits=3}
306-
> .local $n1 = {$n :number maximumFractionDigits=3}
307-
> {{What is the value of: {$n1}}}
308-
> ```
309-
>
310-
> is currently implementation-dependent.
311-
> Depending on whether the options are preserved
312-
> between the resolution of the first `:number` _function_
313-
> and the resolution of the second `:number` _function_,
314-
> a conformant implementation
315-
> could produce either "001.000" or "1.000"
316-
>
317-
> Each function **specification** MAY have
318-
> its own rules to preserve some options in the returned structure
319-
> and discard others.
320-
> In instances where a function specification does not determine whether an option is preserved or discarded,
321-
> each function **implementation** of that specification MAY have
322-
> its own rules to preserve some options in the returned structure
323-
> and discard others.
324-
>
325-
326-
> [!NOTE]
327-
> During the Technical Preview,
328-
> feedback on how the registry describes
329-
> the flow of _resolved values_ and _options_
330-
> from one _function_ to another,
331-
> and on what requirements this specification should impose,
332-
> is highly desired.
333-
334275
An implementation MAY pass additional arguments to the function,
335276
as long as reasonable precautions are taken to keep the function interface
336277
simple and minimal, and avoid introducing potential security vulnerabilities.
337278
338-
An implementation MAY define its own functions.
339-
An implementation MAY allow custom functions to be defined by users.
340-
341-
Function access to the _formatting context_ MUST be minimal and read-only,
342-
and execution time SHOULD be limited.
343-
344-
Implementation-defined _functions_ SHOULD use an implementation-defined _namespace_.
345-
346279
5. If the call succeeds,
347280
resolve the value of the _expression_ as the result of that function call.
348281
349282
If the call fails or does not return a valid value,
350283
emit the appropriate _Message Function Error_ for the failure.
351284
352-
Implementations MAY provide a mechanism for the _function_ to provide
285+
Implementations MAY provide a mechanism for the _function handler_ to provide
353286
additional detail about internal failures.
354287
Specifically, if the cause of the failure was that the datatype, value, or format of the
355288
_operand_ did not match that expected by the _function_,
356289
the _function_ might cause a _Bad Operand_ error to be emitted.
357290
358291
In all failure cases, use the _fallback value_ for the _expression_ as its _resolved value_.
359292
293+
#### Function Handler
294+
295+
To resolve a _function_,
296+
a **_<dfn>function handler</dfn>_** is required.
297+
This is an implementation-defined process such as a function or method
298+
which accepts a set of arguments and returns a _resolved value_.
299+
300+
An implementation MAY define its own functions and their handlers.
301+
An implementation MAY allow custom functions to be defined by users.
302+
303+
Implementations that provide a means for defining custom functions
304+
MUST provide a means for _function handlers_
305+
to return _resolved values_ that contain enough information
306+
to be used as _operands_ or _option_ values in subsequent _expressions_.
307+
308+
The _resolved value_ returned by a _function handler_
309+
MAY be different from the value of the _operand_ of the _function_.
310+
It MAY be an implementation specified type.
311+
It is not required to be the same type as the _operand_.
312+
313+
A _function handler_ MAY include resolved options in its _resolved value_.
314+
The resolved options MAY be different from the _options_ of the function.
315+
316+
A _function handler_ SHOULD emit a
317+
_Bad Operand_ error for _operands_ whose _resolved value_
318+
or type is not supported.
319+
320+
_Function handler_ access to the _formatting context_ MUST be minimal and read-only,
321+
and execution time SHOULD be limited.
322+
323+
Implementation-defined _functions_ SHOULD use an implementation-defined _namespace_.
324+
360325
#### Option Resolution
361326
362327
The result of resolving _option_ values is an unordered mapping of string identifiers to values.

spec/registry.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# MessageFormat 2.0 Default Function Registry
22

3-
This section describes the functions which each implementation MUST provide
4-
to be conformant with this specification.
3+
This section describes the functions for which each implementation MUST provide
4+
a _function handler_ to be conformant with this specification.
55

66
Implementations MAY implement additional _functions_ or additional _options_.
77
In particular, implementations are encouraged to provide feedback on proposed
@@ -374,7 +374,7 @@ All other values produce a _Bad Operand_ error.
374374
### Digit Size Options
375375
376376
Some _options_ of number _functions_ are defined to take a "digit size option".
377-
Implementations of number _functions_ use these _options_ to control aspects of numeric display
377+
_Function handlers_ of number _functions_ use these _options_ to control aspects of numeric display
378378
such as the number of fraction, integer, or significant digits.
379379
380380
A "digit size option" is an _option_ value that the _function_ interprets
@@ -579,8 +579,6 @@ The function `:datetime` has these _style options_.
579579
580580
_Field options_ describe which fields to include in the formatted output
581581
and what format to use for that field.
582-
The implementation may use this _function_ to configure which fields
583-
appear in the formatted output.
584582
585583
> [!NOTE]
586584
> _Field options_ do not have default values because they are only to be used

0 commit comments

Comments
 (0)