@@ -40,7 +40,7 @@ as long as the final _formatting_ result is made available to users
4040and 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_.
9999Since a _ variable_ can be referenced in different ways later,
100100implementations 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+
102112In an _input-declaration_, the _variable_ operand of the _variable-expression_
103113identifies not only the name of the external input value,
104114but 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,
109119and 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:
2432531. If the _expression_ includes an _operand_, resolve its value.
244254 If this fails, use a _fallback value_ for the _expression_.
2452552. 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
2552653. 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-
3462795. 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
362327The result of resolving _option_ values is an unordered mapping of string identifiers to values.
0 commit comments