Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Aug 26, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions exploration/selection-declaration.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,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}}}
```
eemeli marked this conversation as resolved.
Show resolved Hide resolved

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:
```
.match {$n :number minimumFractionDigits=2}
* {{Formats '$n' as an integer: {$n :integer}}}
eemeli marked this conversation as resolved.
Show resolved Hide resolved

.input {$n :integer}
.match {$n :number minimumFractionDigits=2}
* {{Formats '$n' as an integer: {$n}}}
```

**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