Skip to content

Commit

Permalink
Add new selection-declaration alternative: Require annotation of sele…
Browse files Browse the repository at this point in the history
…ctor variables in placeholders (#860)

* Add new selection-declaration alternative: Require annotation of selector variables in placeholders

* Improve examples

* Switch example order
  • Loading branch information
eemeli authored Aug 26, 2024
1 parent e64c987 commit 343ef56
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions exploration/selection-declaration.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,52 @@ Examples:
- Can produce a mismatch between formatting and selection, since the operand's formatting
isn't visible to the selector.

### Require annotation of selector variables in placeholders

In this alternative, the pre-existing validity requirement

> Each _selector_ MUST have an _annotation_,
> or contain a _variable_ that directly or indirectly references a _declaration_ with an _annotation_.
is expanded to also require later uses of a variable that's used as a selector to be annotated:

> In a _complex message_,
> each _placeholder_ _expression_ using the same _operand_ as a _selector_ MUST have an _annotation_,
> or contain a _variable_ that directly or indirectly references a _declaration_ with an _annotation_.
Example invalid message with this alternative:
```
.match {$n :number minimumFractionDigits=2}
* {{Data model error: {$n}}}
```

Valid, recommended form for the above message:
```
.input {$n :number minimumFractionDigits=2}
.match {$n}
* {{Formats '$n' as a number with fraction digits: {$n}}}
```

Technically valid but not recommended:
```
.input {$n :integer}
.match {$n :number minimumFractionDigits=2}
* {{Formats '$n' as an integer: {$n}}}
.match {$n :number minimumFractionDigits=2}
* {{Formats '$n' as an integer: {$n :integer}}}
```

**Pros**
- No syntax changes required.
- `.local` can be used to solve problems with variations in selection and formatting
- Supports multiple selectors on the same operand
- Avoids mismatches between formatting and selection by requiring their annotation.

**Cons**
- May require the user to annotate the operand for both formatting and selection,
unless they use a declaration.

### Allow both local and input declarative selectors with immutability

In this alternative, we modify the syntax to allow selectors to
Expand Down

0 comments on commit 343ef56

Please sign in to comment.