Skip to content

Commit ac7cdc5

Browse files
committed
Fix references to fallback values
1 parent df21df3 commit ac7cdc5

File tree

1 file changed

+41
-34
lines changed

1 file changed

+41
-34
lines changed

spec/formatting.md

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,7 @@ whether its value was originally a _quoted literal_ or an _unquoted literal_.
213213
> For example,
214214
> the _option_ `foo=42` and the _option_ `foo=|42|` are treated as identical.
215215
216-
217-
> For example, in a JavaScript formatter
216+
> In a JavaScript formatter,
218217
> the _resolved value_ of a _text_ or a _literal_ could have the following implementation:
219218
>
220219
> ```ts
@@ -239,23 +238,23 @@ Otherwise, the _variable_ is an implicit reference to an input value,
239238
and its value is looked up from the _formatting context_ _input mapping_.
240239
241240
The resolution of a _variable_ fails if no value is identified for its _name_.
242-
If this happens, an _Unresolved Variable_ error is emitted.
243-
If a _variable_ would resolve to a _fallback value_,
244-
this MUST also be considered a failure.
241+
If this happens, an _Unresolved Variable_ error is emitted
242+
and a _fallback value_ is used as _resolved value_ of the _variable_.
245243
246244
### Function Resolution
247245
248246
To resolve an _expression_ with a _function_,
249247
the following steps are taken:
250248
251249
1. If the _expression_ includes an _operand_, resolve its value.
252-
If this fails, use a _fallback value_ for the _expression_.
250+
If this is a _fallback value_,
251+
use it as the _resolved value_ of the _expression_.
253252
2. Resolve the _identifier_ of the _function_ and, based on the starting sigil,
254253
find the appropriate _function handler_ to call.
255254
If the implementation cannot find the _function handler_,
256255
or if the _identifier_ includes a _namespace_ that the implementation does not support,
257256
emit an _Unknown Function_ error
258-
and use a _fallback value_ for the _expression_.
257+
and use a _fallback value_ as the _resolved value_ of the _expression_.
259258
260259
Implementations are not required to implement _namespaces_ or installable
261260
_function registries_.
@@ -286,7 +285,7 @@ the following steps are taken:
286285
_operand_ did not match that expected by the _function_,
287286
the _function_ SHOULD cause a _Bad Operand_ error to be emitted.
288287
289-
In all failure cases, use the _fallback value_ for the _expression_ as its _resolved value_.
288+
In all failure cases, use a _fallback value_ as the _resolved value_ of the _expression_.
290289
291290
#### Function Handler
292291
@@ -322,16 +321,20 @@ Implementation-defined _functions_ SHOULD use an implementation-defined _namespa
322321
323322
#### Option Resolution
324323
325-
The result of resolving _option_ values is an unordered mapping of string identifiers to values.
324+
The result of resolving _option_ values is an unordered mapping of string identifiers to values,
325+
determined as follows:
326326
327-
For each _option_:
327+
1. Let `res` be a new empty mapping.
328+
1. For each _option_:
329+
1. Let `id` be the string value of the _identifier_ of the _option_.
330+
1. Let `rv` be the _resolved value_ of the _option_ value.
331+
1. If `rv` is a _fallback value_:
332+
1. Set the value bound to `id` in `res` to an unresolved value.
333+
1. Else:
334+
1. Set the value bound to `id` in `res` to `rv`.
335+
1. Return `res`.
328336
329-
- Resolve the _identifier_ of the _option_.
330-
- If the _option_'s right-hand side successfully resolves to a value,
331-
bind the _identifier_ of the _option_ to the _resolved value_ in the mapping.
332-
- Otherwise, bind the _identifier_ of the _option_ to an unresolved value in the mapping.
333-
Implementations MAY later remove this value before calling the _function_.
334-
(Note that an _Unresolved Variable_ error will have been emitted.)
337+
Implementations MAY remove entries from `res` with unresolved values.
335338
336339
Errors MAY be emitted during _option resolution_,
337340
but it always resolves to some mapping of string identifiers to values.
@@ -351,15 +354,23 @@ The resolution of _markup_ MUST always succeed.
351354
352355
### Fallback Resolution
353356
354-
A **_<dfn>fallback value</dfn>_** is the _resolved value_ for an _expression_ that fails to resolve.
357+
A **_<dfn>fallback value</dfn>_** is the _resolved value_ for
358+
an _expression_ or _variable_ that fails to resolve.
359+
It has a string representation that is used for its formatting.
360+
361+
The _resolved value_ of _text_, _literal_, and _markup_ MUST NOT be a _fallback value_.
362+
363+
A _variable_ fails to resolve when no value is identified for its _name_.
364+
The string representation of its _fallback value_ is
365+
U+0024 DOLLAR SIGN `$` followed by the _name_ of the _variable_.
355366
356367
An _expression_ fails to resolve when:
357368
358-
- A _variable_ used as an _operand_ (with or without a _function_) fails to resolve.
359-
* Note that this does not include a _variable_ used as an _option_ value.
369+
- A _variable_ used as its _operand_ resolves to a _fallback value_.
370+
Note that this does not include a _variable_ used as an _option_ value.
360371
- A _function_ fails to resolve.
361372
362-
The _fallback value_ depends on the contents of the _expression_:
373+
The string representation of the _fallback value_ of an _expression_ depends on its contents:
363374
364375
- _expression_ with a _literal_ _operand_ (either quoted or unquoted)
365376
U+007C VERTICAL LINE `|`
@@ -372,33 +383,29 @@ The _fallback value_ depends on the contents of the _expression_:
372383
> `{42 :func}` resolves to the _fallback value_ `|42|` and
373384
> `{|C:\\| :func}` resolves to the _fallback value_ `|C:\\|`.
374385
375-
- _expression_ with _variable_ _operand_ referring to a local _declaration_ (with or without a _function_):
376-
the _value_ to which it resolves (which may already be a _fallback value_)
386+
- _expression_ with a _variable_ _operand_ referring to a _declaration_:
387+
the string representation of the _fallback value_ of the _expression_ of that _declaration_.
377388
378389
> Examples:
379390
> In a context where `:func` fails to resolve,
380-
> the _pattern_'s _expression_ in `.local $var={|val|} {{{$var :func}}}`
391+
> the _placeholder_ in `.local $var = {|val| :func} {{{$var}}}`
381392
> resolves to the _fallback value_ `|val|` and the message formats to `{|val|}`.
382-
> In a context where `:now` fails to resolve but `:datetime` does not,
383-
> the _pattern_'s _expression_ in
393+
>
394+
> In a context where `:pretty` fails to resolve but `:now` does not,
395+
> the _placeholder_ in
384396
> ```
385397
> .local $t = {:now format=iso8601}
386-
> .local $pretty_t = {$t :datetime}
387-
> {{{$pretty_t}}}
398+
> {{{$t :pretty}}}
388399
> ```
389-
> (transitively) resolves to the _fallback value_ `:now` and
390-
> the message formats to `{:now}`.
400+
> resolves to the _fallback value_ `:now` and the message formats to `{:now}`.
391401
392-
- _expression_ with _variable_ _operand_ not referring to a local _declaration_ (with or without a _function_):
402+
- _expression_ with _variable_ _operand_ not referring to a _declaration_:
403+
the _fallback value_ representation of that _variable_,
393404
U+0024 DOLLAR SIGN `$` followed by the _name_ of the _variable_
394405
395406
> Examples:
396407
> In a context where `$var` fails to resolve, `{$var}` and `{$var :number}`
397408
> both resolve to the _fallback value_ `$var`.
398-
> In a context where `:func` fails to resolve,
399-
> the _pattern_'s _expression_ in `.input $arg {{{$arg :func}}}`
400-
> resolves to the _fallback value_ `$arg` and
401-
> the message formats to `{$arg}`.
402409
403410
- _function_ _expression_ with no _operand_:
404411
U+003A COLON `:` followed by the _function_ _identifier_

0 commit comments

Comments
 (0)