Skip to content

Commit fcf1a82

Browse files
aphillipseemeligithub-actions[bot]
authored
Allow expressions without annotations to dynamically choose a function (#456)
* Allow expressions without annotations to dynamically choose a function Fixes #42 Also addresses some problems with normative terms in the same text. * Address comment about the bad normative text * Update spec/formatting.md Co-authored-by: Eemeli Aro <[email protected]> * Attempt to implement WG consensus from 2023-08-28 call - Made one fix to inappropriate normative language - Removed the formatting allowance previously inserted - Reversed the order of the expression resolution "sieve", so that the complicated optional goo goes at the end. - Allow (but not require) an implementation to use the value of a _variable_ to assign the annotation - Allow (but not require) an implementation to use the value of a _literal_ to assign the annotation if-and-only-if the literal does not appear in an declaration This is complicated and probably begging for examples. * Update spec/formatting.md Co-authored-by: Eemeli Aro <[email protected]> * Better reflect current consensus * Address comments * Formatting cleanup * Move all of the example inside the example Must drink more coffee ☕ * style: Apply Prettier * 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/formatting.md Co-authored-by: Eemeli Aro <[email protected]> * Update spec/formatting.md Co-authored-by: Eemeli Aro <[email protected]> --------- Co-authored-by: Eemeli Aro <[email protected]> Co-authored-by: Eemeli Aro <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 7b5c2a9 commit fcf1a82

File tree

1 file changed

+56
-18
lines changed

1 file changed

+56
-18
lines changed

spec/formatting.md

Lines changed: 56 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ _Expressions_ are used in _declarations_, _selectors_, and _patterns_.
7070

7171
In a _declaration_, the resolved value of the _expression_ is assigned to a _variable_,
7272
which is available for use by later _expressions_.
73-
As such a _variable_ MAY then be referenced in different ways,
73+
Since a _variable_ can be referenced in different ways later,
7474
implementations SHOULD NOT immediately fully format the value for output.
7575

7676
In _selectors_, the resolved value of an _expression_ is used for _pattern selection_.
@@ -93,17 +93,53 @@ and different implementations MAY choose to perform different levels of resoluti
9393
9494
Depending on the presence or absence of an _operand_
9595
and a _function_, _private-use_, or _reserved_ _annotation_,
96-
one of the following is used to resolve the value of the _expression_:
97-
98-
- If the _expression_ contains no _annotation_,
99-
its resolved value is determined by _literal resolution_ or _variable resolution_,
100-
depending on the shape of the _operand_.
101-
- Else, if the _expression_ has a _function_ _annotation_,
102-
its resolved value is defined by _function resolution_.
103-
- Else, if the _expression_ has a _private-use_ _annotation_,
104-
its resolved value is defined according to the implementations's specification.
105-
- Else, the _expression_ has a _reserved_ _annotation_,
106-
an Unsupported Expression error is emitted and a fallback value is used as its value.
96+
the resolved value of the _expression_ is determined as follows:
97+
98+
If the _expression_ contains a _reserved_ _annotation_,
99+
an `Unsupported Expression` error is emitted and a fallback value is used as its value.
100+
101+
Else, if the _expression_ contains a _private-use_ _annotation_,
102+
its resolved value is defined according to the implementation's specification.
103+
104+
Else, if the _expression_ contains an _annotation_,
105+
its resolved value is defined by _function resolution_.
106+
107+
Else, the _expression_ will contain only an _operand_,
108+
which consists of either a _literal_ or a _variable_.
109+
110+
If the _expression_ consists of a _variable_,
111+
its resolved value is defined by _variable resolution_.
112+
An implementation MAY perform additional processing
113+
when resolving the value of the _expression_.
114+
115+
> For example, it could apply _function resolution_ using a _function_
116+
> and a set of _options_ chosen based on the value or type of the _variable_.
117+
> So, given a _message_ like this:
118+
>
119+
> ```
120+
> {Today is {$date}}
121+
> ```
122+
>
123+
> If the value passed in the _variable_ were a date object,
124+
> such as a JavaScript `Date` or a Java `java.util.Date` or `java.time.Temporal`,
125+
> the implementation could interpret the _placeholder_ `{$date}` as if
126+
> the pattern included the function `:datetime` with some set of default options.
127+
128+
Else, if the _expression_ consists of a _literal_,
129+
its resolved value is defined by _literal resolution_.
130+
131+
> **Note**
132+
> This means that a _literal_ value with no _annotation_
133+
> is always treated as a string.
134+
> To represent values that are not strings as a _literal_,
135+
> an _annotation_ needs to be provided:
136+
>
137+
> ```
138+
> let $aNumber = {1234 :number}
139+
> let $aDate = {|2023-08-30| :datetime}
140+
> let $aFoo = {|some foo| :foo}
141+
> {You have {42 :number}}
142+
> ```
107143
108144
### Literal Resolution
109145
@@ -507,14 +543,16 @@ _Formatting_ is a mostly implementation-defined process,
507543
as it depends on the implementation's shape for resolved values
508544
and the result type of the formatting.
509545
510-
Formatting errors MAY be emitted during _formatting_,
511-
as formatting is not necessarily defined on every resolved value.
512-
A formatter MAY provide a value to use in such a case instead of a _fallback value_.
546+
Resolved values cannot always be formatted by a given implementation.
547+
When such an error occurs during _formatting_,
548+
an implementation SHOULD emit a _formatting error_ and produce a
549+
_fallback value_ for the _placeholder_ that produced the error.
550+
A formatting function MAY substitute a value to use instead of a _fallback value_.
513551
514-
_Formatting_ MAY produce formatted messages with the following data types,
515-
as well as any others:
552+
Implementations MAY represent the result of _formatting_ using the most
553+
appropriate data type or structure. Some examples of these include:
516554
517-
- A single concatenated string.
555+
- A single string concatenated from the parts of the resolved _pattern_.
518556
- A string with associated attributes for portions of its text.
519557
- A flat sequence of objects corresponding to each resolved value.
520558
- A hierarchical structure of objects that group spans of resolved values,

0 commit comments

Comments
 (0)