Skip to content

Commit 343ef56

Browse files
authored
Add new selection-declaration alternative: Require annotation of selector variables in placeholders (#860)
* Add new selection-declaration alternative: Require annotation of selector variables in placeholders * Improve examples * Switch example order
1 parent e64c987 commit 343ef56

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

exploration/selection-declaration.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,52 @@ Examples:
193193
- Can produce a mismatch between formatting and selection, since the operand's formatting
194194
isn't visible to the selector.
195195

196+
### Require annotation of selector variables in placeholders
197+
198+
In this alternative, the pre-existing validity requirement
199+
200+
> Each _selector_ MUST have an _annotation_,
201+
> or contain a _variable_ that directly or indirectly references a _declaration_ with an _annotation_.
202+
203+
is expanded to also require later uses of a variable that's used as a selector to be annotated:
204+
205+
> In a _complex message_,
206+
> each _placeholder_ _expression_ using the same _operand_ as a _selector_ MUST have an _annotation_,
207+
> or contain a _variable_ that directly or indirectly references a _declaration_ with an _annotation_.
208+
209+
Example invalid message with this alternative:
210+
```
211+
.match {$n :number minimumFractionDigits=2}
212+
* {{Data model error: {$n}}}
213+
```
214+
215+
Valid, recommended form for the above message:
216+
```
217+
.input {$n :number minimumFractionDigits=2}
218+
.match {$n}
219+
* {{Formats '$n' as a number with fraction digits: {$n}}}
220+
```
221+
222+
Technically valid but not recommended:
223+
```
224+
.input {$n :integer}
225+
.match {$n :number minimumFractionDigits=2}
226+
* {{Formats '$n' as an integer: {$n}}}
227+
228+
.match {$n :number minimumFractionDigits=2}
229+
* {{Formats '$n' as an integer: {$n :integer}}}
230+
```
231+
232+
**Pros**
233+
- No syntax changes required.
234+
- `.local` can be used to solve problems with variations in selection and formatting
235+
- Supports multiple selectors on the same operand
236+
- Avoids mismatches between formatting and selection by requiring their annotation.
237+
238+
**Cons**
239+
- May require the user to annotate the operand for both formatting and selection,
240+
unless they use a declaration.
241+
196242
### Allow both local and input declarative selectors with immutability
197243

198244
In this alternative, we modify the syntax to allow selectors to

0 commit comments

Comments
 (0)