From fc59ca5ea34268fa2c292b1b2ffac658830973bb Mon Sep 17 00:00:00 2001 From: Eemeli Aro Date: Tue, 20 Aug 2024 16:44:37 +0300 Subject: [PATCH 1/3] Add new selection-declaration alternative: Require annotation of selector variables in placeholders --- exploration/selection-declaration.md | 36 ++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/exploration/selection-declaration.md b/exploration/selection-declaration.md index 0e2c8abc7..0cf22750b 100644 --- a/exploration/selection-declaration.md +++ b/exploration/selection-declaration.md @@ -182,6 +182,42 @@ 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 valid message: +``` +.input {$n :integer} +.match {$n :number minimumFractionDigits=2} +* {{Formats '$n' as an integer: {$n}}} +``` + +Example invalid message: +``` +.match {$n :integer} +* {{If $n==1.2 formats {$n} as 1.2 in en-US}} +``` + +**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 From 60441b37ad0ee4ddeaed7c02edf78b016c021d83 Mon Sep 17 00:00:00 2001 From: Eemeli Aro Date: Sun, 25 Aug 2024 18:27:19 +0300 Subject: [PATCH 2/3] Improve examples --- exploration/selection-declaration.md | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/exploration/selection-declaration.md b/exploration/selection-declaration.md index 0cf22750b..fb9ed37a5 100644 --- a/exploration/selection-declaration.md +++ b/exploration/selection-declaration.md @@ -195,17 +195,27 @@ is expanded to also require later uses of a variable that's used as a selector t > 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 valid message: +Example invalid message with this alternative: ``` -.input {$n :integer} .match {$n :number minimumFractionDigits=2} -* {{Formats '$n' as an integer: {$n}}} +* {{Data model error: {$n}}} ``` -Example invalid message: +Valid, recommended form for the above message: ``` -.match {$n :integer} -* {{If $n==1.2 formats {$n} as 1.2 in en-US}} +.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}}} + +.input {$n :integer} +.match {$n :number minimumFractionDigits=2} +* {{Formats '$n' as an integer: {$n}}} ``` **Pros** From e60cc6f9e3ab3c66adb21a8cf849f261fb6b5fd1 Mon Sep 17 00:00:00 2001 From: Eemeli Aro Date: Sun, 25 Aug 2024 18:37:18 +0300 Subject: [PATCH 3/3] Switch example order --- exploration/selection-declaration.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/exploration/selection-declaration.md b/exploration/selection-declaration.md index fb9ed37a5..1e9d48dc1 100644 --- a/exploration/selection-declaration.md +++ b/exploration/selection-declaration.md @@ -210,12 +210,12 @@ Valid, recommended form for the above message: Technically valid but not recommended: ``` -.match {$n :number minimumFractionDigits=2} -* {{Formats '$n' as an integer: {$n :integer}}} - .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**