From e854365aee2c20b187680dd2e6099b5209205413 Mon Sep 17 00:00:00 2001 From: Addison Phillips Date: Wed, 1 Nov 2023 08:33:25 -0700 Subject: [PATCH 1/8] Clarify declaration immutability Having reviewed @catamorphism's previous text and looking at our current text, these are proposed **_editorial_** changes to make variable immutability clearer in the spec. --- spec/syntax.md | 44 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/spec/syntax.md b/spec/syntax.md index 005133fec1..efbc4c9ead 100644 --- a/spec/syntax.md +++ b/spec/syntax.md @@ -148,19 +148,49 @@ MAY include an _annotation_ that is applied to the external value. A **_local-declaration_** binds a _variable_ to the resolved value of an _expression_. -Declared _variables_ MUST NOT be used before their _declaration_, -and their values MUST NOT be self-referential; -otherwise, a _message_ is not considered _valid_. - -Multiple _declarations_ MUST NOT bind a value to the same _variable_; -otherwise, a _message_ is not considered _valid_. - ```abnf declaration = input-declaration / local-declaration input-declaration = input [s] variable-expression local-declaration = local s variable [s] "=" [s] expression ``` +_Variables_, once declared, MUST NOT be redeclared. +A _message_ that does any of the following is not _valid_ and will produce a +Duplicate Declaration error during formatting: +- An _input-declaration_ MUST NOT bind a _variable_ that appears as a _variable_ in a previous + _declaration_. +- A _local-declaration_ MUST NOT bind a _variable_ that appears as a _variable_ in a previous + _declaration_. +- A _local-declaration_ MUST NOT bind a _variable_ that appears in its _expression_. + +> Examples of invalid messages: +> ``` +> {{ +> input {$var :number maxFractionDigits=0} +> input {$var :number minFractionDigits=0} +> {{Redeclaration of the same variable}} +> }} +> {{ +> local $var = {$ext :someFunction} +> local $var = {$error} +> local $var2 = {$var2 :error} +> {{{$var} cannot be redefined. {$var2} cannot refer to itself}} +> }} +> ``` + +> [!Note] +> These restrictions only apply to _declarations_. +> A _placeholder_ or _selector_ MAY override the annotation provided in a _declaration_. +> For example, this message is _valid_: +> ``` +> {{ +> input {$var :number maxFractionDigits=0} +> match {$var :plural maxFractionDigits=2} +> when 0 {{The selector can re-annotate {$var}}} +> when * {{This pattern can re-annotate {$var :number maxFractionDigits=3}}} +> }} +> ``` + ### Body The **_body_** of a _complex message_ is the part that will be formatted. From 0c1b8bbdee14035417d663a7d09807c87d56d48d Mon Sep 17 00:00:00 2001 From: Addison Phillips Date: Wed, 1 Nov 2023 08:41:43 -0700 Subject: [PATCH 2/8] Update formatting.md --- spec/formatting.md | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/spec/formatting.md b/spec/formatting.md index a2d9ceee80..79cf43b37f 100644 --- a/spec/formatting.md +++ b/spec/formatting.md @@ -758,7 +758,7 @@ These are divided into the following categories: contains a _selector_ that does not have an _annotation_, or contains a _variable_ that does not directly or indirectly reference a _declaration_ with an _annotation_. - > Example invalid messages resulting in a _Missing Selector Annotation error_: + > Examples of invalid messages resulting in a _Missing Selector Annotation error_: > > ``` > {{ @@ -786,11 +786,32 @@ These are divided into the following categories: > }} > ``` + - **Duplicate Declaration errors** occur when a _variable_ appears in two _declarations_. + This includes when an _input-declaration_ binds a _variable_ that appears in a previous _declaration_, + when a _local-declaration_ binds a _variable_ that appears in a previous _declaration_, + or when a _local-declaration_ refers to its _variable_ in its _expression_. + + > Examples of invalid messages resulting in a Duplicate Declaration error: + > + > ``` + > {{ + > input {$var :number maxFractionDigits=0} + > input {$var :number minFractionDigits=0} + > {{Redeclaration of the same variable}} + > }} + > {{ + > local $var = {$ext :someFunction} + > local $var = {$error} + > local $var2 = {$var2 :error} + > {{{$var} cannot be redefined. {$var2} cannot refer to itself}} + > }} + > ``` + - **Duplicate Option Name errors** occur when the same _name_ appears on the left-hand side of more than one _option_ in the same _expression_. - > Example invalid messages resulting in a Duplicate Option Name error: + > Examples of invalid messages resulting in a Duplicate Option Name error: > > ``` > Value is {42 :number style=percent style=decimal} From a67a185cf8035d1e649187afb0115aaed1e9776a Mon Sep 17 00:00:00 2001 From: Addison Phillips Date: Wed, 1 Nov 2023 08:43:31 -0700 Subject: [PATCH 3/8] Consistency of referring to an error --- spec/formatting.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/formatting.md b/spec/formatting.md index 79cf43b37f..cc0c189c0c 100644 --- a/spec/formatting.md +++ b/spec/formatting.md @@ -786,7 +786,7 @@ These are divided into the following categories: > }} > ``` - - **Duplicate Declaration errors** occur when a _variable_ appears in two _declarations_. + - A **Duplicate Declaration error** occurs when a _variable_ appears in two _declarations_. This includes when an _input-declaration_ binds a _variable_ that appears in a previous _declaration_, when a _local-declaration_ binds a _variable_ that appears in a previous _declaration_, or when a _local-declaration_ refers to its _variable_ in its _expression_. @@ -807,7 +807,7 @@ These are divided into the following categories: > }} > ``` - - **Duplicate Option Name errors** occur when the same _name_ + - A **Duplicate Option Name error** occurs when the same _name_ appears on the left-hand side of more than one _option_ in the same _expression_. From 5d3790702943d656b292fec50c61af55934e16b0 Mon Sep 17 00:00:00 2001 From: Addison Phillips Date: Wed, 1 Nov 2023 08:47:25 -0700 Subject: [PATCH 4/8] Moved the examples to formatting --- spec/syntax.md | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/spec/syntax.md b/spec/syntax.md index efbc4c9ead..5d8f90a06c 100644 --- a/spec/syntax.md +++ b/spec/syntax.md @@ -163,21 +163,6 @@ Duplicate Declaration error during formatting: _declaration_. - A _local-declaration_ MUST NOT bind a _variable_ that appears in its _expression_. -> Examples of invalid messages: -> ``` -> {{ -> input {$var :number maxFractionDigits=0} -> input {$var :number minFractionDigits=0} -> {{Redeclaration of the same variable}} -> }} -> {{ -> local $var = {$ext :someFunction} -> local $var = {$error} -> local $var2 = {$var2 :error} -> {{{$var} cannot be redefined. {$var2} cannot refer to itself}} -> }} -> ``` - > [!Note] > These restrictions only apply to _declarations_. > A _placeholder_ or _selector_ MAY override the annotation provided in a _declaration_. @@ -190,6 +175,7 @@ Duplicate Declaration error during formatting: > when * {{This pattern can re-annotate {$var :number maxFractionDigits=3}}} > }} > ``` +> (See [Error Handling](./formatting.md#error-handling) for examples of invalid messages) ### Body From e9908c8b0e987829049c9926c3987bd9c953f340 Mon Sep 17 00:00:00 2001 From: Addison Phillips Date: Wed, 1 Nov 2023 11:43:38 -0700 Subject: [PATCH 5/8] Address @catamorphism's comments --- spec/syntax.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/spec/syntax.md b/spec/syntax.md index 5d8f90a06c..a63b80f9fa 100644 --- a/spec/syntax.md +++ b/spec/syntax.md @@ -163,9 +163,13 @@ Duplicate Declaration error during formatting: _declaration_. - A _local-declaration_ MUST NOT bind a _variable_ that appears in its _expression_. +A _local-declaration_ MAY overwrite an external input value as long as the +external input value does not appear in a _declaration_. + > [!Note] > These restrictions only apply to _declarations_. -> A _placeholder_ or _selector_ MAY override the annotation provided in a _declaration_. +> A _placeholder_ or _selector_ MAY supply a different annotation than one +> provided in a _declaration_ for the same _variable_. > For example, this message is _valid_: > ``` > {{ From 4bb512e54dd61661c6053d45a250b847e29687eb Mon Sep 17 00:00:00 2001 From: Addison Phillips Date: Wed, 1 Nov 2023 16:48:58 -0700 Subject: [PATCH 6/8] Update syntax.md --- spec/syntax.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/syntax.md b/spec/syntax.md index a63b80f9fa..5c54ff14a5 100644 --- a/spec/syntax.md +++ b/spec/syntax.md @@ -168,15 +168,15 @@ external input value does not appear in a _declaration_. > [!Note] > These restrictions only apply to _declarations_. -> A _placeholder_ or _selector_ MAY supply a different annotation than one -> provided in a _declaration_ for the same _variable_. +> A _placeholder_ or _selector_ can apply a different annotation to a _variable_ +> than one applied to the same _variable_ name in a _declaration_. > For example, this message is _valid_: > ``` > {{ > input {$var :number maxFractionDigits=0} > match {$var :plural maxFractionDigits=2} -> when 0 {{The selector can re-annotate {$var}}} -> when * {{This pattern can re-annotate {$var :number maxFractionDigits=3}}} +> when 0 {{The selector can apply a different annotation to {$var} for the purposes of selection}} +> when * {{A placeholder in a pattern can apply a different annotation to {$var :number maxFractionDigits=3}}} > }} > ``` > (See [Error Handling](./formatting.md#error-handling) for examples of invalid messages) From ebd31e1378fbcf1abdd45ae2cf9222dededfca40 Mon Sep 17 00:00:00 2001 From: Addison Phillips Date: Mon, 6 Nov 2023 07:27:10 -0800 Subject: [PATCH 7/8] Update spec/formatting.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Stanisław Małolepszy --- spec/formatting.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/formatting.md b/spec/formatting.md index cc0c189c0c..bf73eaaeab 100644 --- a/spec/formatting.md +++ b/spec/formatting.md @@ -789,7 +789,7 @@ These are divided into the following categories: - A **Duplicate Declaration error** occurs when a _variable_ appears in two _declarations_. This includes when an _input-declaration_ binds a _variable_ that appears in a previous _declaration_, when a _local-declaration_ binds a _variable_ that appears in a previous _declaration_, - or when a _local-declaration_ refers to its _variable_ in its _expression_. + or when a _local-declaration_ refers to its bound _variable_ in its _expression_. > Examples of invalid messages resulting in a Duplicate Declaration error: > From a2305b150cf0c6117cdfbe3e5ad348f3a6b3ed1c Mon Sep 17 00:00:00 2001 From: Addison Phillips Date: Mon, 6 Nov 2023 07:27:52 -0800 Subject: [PATCH 8/8] Update spec/formatting.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Stanisław Małolepszy --- spec/formatting.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/spec/formatting.md b/spec/formatting.md index bf73eaaeab..85ea0288d1 100644 --- a/spec/formatting.md +++ b/spec/formatting.md @@ -800,6 +800,16 @@ These are divided into the following categories: > {{Redeclaration of the same variable}} > }} > {{ + > local $var = {$ext :number maxFractionDigits=0} + > input {$var :number minFractionDigits=0} + > {{Redeclaration of a local variable}} + > }} + > {{ + > input {$var :number minFractionDigits=0} + > local $var = {$ext :number maxFractionDigits=0} + > {{Redeclaration of an input variable}} + > }} + > {{ > local $var = {$ext :someFunction} > local $var = {$error} > local $var2 = {$var2 :error}