From 16996d3a8c395a0076e77ed745f98f6085292b9d Mon Sep 17 00:00:00 2001 From: Eemeli Aro Date: Tue, 28 Jan 2025 00:51:50 +0200 Subject: [PATCH 1/3] Allow name-char as first character of unquoted-literal --- spec/functions/datetime.md | 14 +------------- spec/functions/number.md | 8 ++++++-- spec/message.abnf | 4 +--- spec/syntax.md | 10 ++++------ test/tests/functions/datetime.json | 2 +- test/tests/functions/integer.json | 4 ++-- test/tests/functions/number.json | 4 ++-- test/tests/syntax.json | 28 ++++++++++++++-------------- 8 files changed, 31 insertions(+), 43 deletions(-) diff --git a/spec/functions/datetime.md b/spec/functions/datetime.md index 2fb05dd46e..98f21e1bda 100644 --- a/spec/functions/datetime.md +++ b/spec/functions/datetime.md @@ -74,19 +74,7 @@ and what format to use for that field. > [!NOTE] > _Field options_ do not have default values because they are only to be used > to compose the formatter. -The _field options_ are defined as follows: - -> [!IMPORTANT] -> The value `2-digit` for some _field options_ MUST be quoted -> in the MessageFormat syntax because it starts with a digit -> but does not match the `number-literal` production in the ABNF. -> -> ``` -> .local $correct = {$someDate :datetime year=|2-digit|} -> .local $syntaxError = {$someDate :datetime year=2-digit} -> ``` - -The function `:datetime` has the following options: +The function `:datetime` has the following _field options_: - `weekday` - `long` diff --git a/spec/functions/number.md b/spec/functions/number.md index c30baa2c2e..198b0d9f9a 100644 --- a/spec/functions/number.md +++ b/spec/functions/number.md @@ -655,9 +655,13 @@ Implementations MUST NOT substitute the unit without performing the associated c ### Number Operands The _operand_ of a number function is either an implementation-defined type or -a literal whose contents match the `number-literal` production in the [ABNF](/spec/message.abnf). +a literal whose contents match the following `number-literal` production. All other values produce a _Bad Operand_ error. +```abnf +number-literal = ["-"] (%x30 / (%x31-39 *DIGIT)) ["." 1*DIGIT] +``` + > For example, in Java, any subclass of `java.lang.Number` plus the primitive > types (`byte`, `short`, `int`, `long`, `float`, `double`, etc.) > might be considered as the "implementation-defined numeric types". @@ -667,7 +671,7 @@ All other values produce a _Bad Operand_ error. > [!NOTE] > String values passed as variables in the _formatting context_'s > _input mapping_ can be formatted as numeric values as long as their -> contents match the `number-literal` production in the [ABNF](/spec/message.abnf). +> contents match the `number-literal` production. > > For example, if the value of the variable `num` were the string > `-1234.567`, it would behave identically to the local diff --git a/spec/message.abnf b/spec/message.abnf index 0f3a1c644b..71bd314934 100644 --- a/spec/message.abnf +++ b/spec/message.abnf @@ -41,9 +41,7 @@ variable = "$" name literal = quoted-literal / unquoted-literal quoted-literal = "|" *(quoted-char / escaped-char) "|" -unquoted-literal = name / number-literal -; number-literal matches JSON number (https://www.rfc-editor.org/rfc/rfc8259#section-6) -number-literal = ["-"] (%x30 / (%x31-39 *DIGIT)) ["." 1*DIGIT] [%i"e" ["-" / "+"] 1*DIGIT] +unquoted-literal = 1*name-char ; Keywords; Note that these are case-sensitive input = %s".input" diff --git a/spec/syntax.md b/spec/syntax.md index d91ce8ad37..9119f32b79 100644 --- a/spec/syntax.md +++ b/spec/syntax.md @@ -735,19 +735,17 @@ escaped as `\\` and `\|`. An **_unquoted literal_** is a _literal_ that does not require the `|` quotes around it to be distinct from the rest of the _message_ syntax. An _unquoted literal_ MAY be used when the content of the _literal_ -contains no whitespace and otherwise matches the `unquoted` production. +contains no whitespace and otherwise matches the `unquoted-literal` production. Implementations MUST NOT distinguish between _quoted literals_ and _unquoted literals_ that have the same sequence of code points. -_Unquoted literals_ can contain a _name_ or consist of a _number-literal_. -A _number-literal_ uses the same syntax as JSON and is intended for the encoding -of number values in _operands_ or _options_, or as _keys_ for _variants_. +_Unquoted literals_ can contain any characters also valid in _name_, +but with none of its additional restrictions on its first character. ```abnf literal = quoted-literal / unquoted-literal quoted-literal = "|" *(quoted-char / escaped-char) "|" -unquoted-literal = name / number-literal -number-literal = ["-"] (%x30 / (%x31-39 *DIGIT)) ["." 1*DIGIT] [%i"e" ["-" / "+"] 1*DIGIT] +unquoted-literal = 1*name-char ``` ### Names and Identifiers diff --git a/test/tests/functions/datetime.json b/test/tests/functions/datetime.json index a5f3bd00bc..d8e8b6dad9 100644 --- a/test/tests/functions/datetime.json +++ b/test/tests/functions/datetime.json @@ -45,7 +45,7 @@ "src": "{|2006-01-02T15:04:06| :datetime}" }, { - "src": "{|2006-01-02T15:04:06| :datetime year=numeric month=|2-digit|}" + "src": "{|2006-01-02T15:04:06| :datetime year=numeric month=2-digit}" }, { "src": "{|2006-01-02T15:04:06| :datetime dateStyle=long}" diff --git a/test/tests/functions/integer.json b/test/tests/functions/integer.json index f249cb27e5..576c037b28 100644 --- a/test/tests/functions/integer.json +++ b/test/tests/functions/integer.json @@ -16,8 +16,8 @@ "exp": "hello -4" }, { - "src": "hello {0.42e+1 :integer}", - "exp": "hello 4" + "src": "hello {0.42 :integer}", + "exp": "hello 0" }, { "src": ".input {$foo :integer} .match $foo 1 {{=1}} * {{other}}", diff --git a/test/tests/functions/number.json b/test/tests/functions/number.json index dee7b9c013..fc4418606f 100644 --- a/test/tests/functions/number.json +++ b/test/tests/functions/number.json @@ -16,8 +16,8 @@ "exp": "hello -4.2" }, { - "src": "hello {0.42e+1 :number}", - "exp": "hello 4.2" + "src": "hello {0.42 :number}", + "exp": "hello 0.42" }, { "src": "hello {foo :number}", diff --git a/test/tests/syntax.json b/test/tests/syntax.json index d03024bc81..5d1a8be13c 100644 --- a/test/tests/syntax.json +++ b/test/tests/syntax.json @@ -421,72 +421,72 @@ ] }, { - "description": "... literal -> quoted-literal -> \"|\" \"|\" ...", + "description": "... quoted-literal", "src": "{||}", "exp": "" }, { - "description": "... quoted-literal -> \"|\" quoted-char \"|\"", + "description": "... quoted-literal", "src": "{|a|}", "exp": "a" }, { - "description": "... quoted-literal -> \"|\" escaped-char \"|\"", + "description": "... quoted-literal", "src": "{|\\\\|}", "exp": "\\" }, { - "description": "... quoted-literal -> \"|\" quoted-char 1*escaped-char \"|\"", + "description": "... quoted-literal", "src": "{|a\\\\\\{\\|\\}|}", "exp": "a\\{|}" }, { - "description": "... unquoted-literal -> number-literal -> %x30", + "description": "... unquoted-literal", "src": "{0}", "exp": "0" }, { - "description": "... unquoted-literal -> number-literal -> \"-\" %x30", + "description": "... unquoted-literal", "src": "{-0}", "exp": "-0" }, { - "description": "... unquoted-literal -> number-literal -> (%x31-39 *DIGIT) -> %x31", + "description": "... unquoted-literal", "src": "{1}", "exp": "1" }, { - "description": "... unquoted-literal -> number-literal -> (%x31-39 *DIGIT) -> %x31 DIGIT -> 11", + "description": "... unquoted-literal", "src": "{11}", "exp": "11" }, { - "description": "... unquoted-literal -> number-literal -> %x30 \".\" 1*DIGIT -> 0 \".\" 1", + "description": "... unquoted-literal", "src": "{0.1}", "exp": "0.1" }, { - "description": "... unquoted-literal -> number-literal -> %x30 \".\" 1*DIGIT -> %x30 \".\" DIGIT DIGIT -> 0 \".\" 1 2", + "description": "... unquoted-literal", "src": "{0.12}", "exp": "0.12" }, { - "description": "... unquoted-literal -> number-literal -> %x30 %i\"e\" 1*DIGIT -> %x30 \"e\" DIGIT", + "description": "... unquoted-literal", "src": "{0e1}", "exp": "0e1" }, { - "description": "... unquoted-literal -> number-literal -> %x30 %i\"e\" 1*DIGIT -> %x30 \"E\" DIGIT", + "description": "... unquoted-literal", "src": "{0E1}", "exp": "0E1" }, { - "description": "... unquoted-literal -> number-literal -> %x30 %i\"e\" \"-\" 1*DIGIT ...", + "description": "... unquoted-literal", "src": "{0E-1}", "exp": "0E-1" }, { - "description": "... unquoted-literal -> number-literal -> %x30 %i\"e\" \"+\" 1*DIGIT ...", + "description": "... unquoted-literal", "src": "{0E-1}", "exp": "0E-1" }, From 894567e2571cc3ed20e73fd33cfd0b4df53dd98f Mon Sep 17 00:00:00 2001 From: Eemeli Aro Date: Wed, 12 Feb 2025 21:22:52 +0200 Subject: [PATCH 2/3] Add exponents back in number-literal --- spec/functions/number.md | 2 +- test/tests/functions/integer.json | 4 ++++ test/tests/functions/number.json | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/spec/functions/number.md b/spec/functions/number.md index 198b0d9f9a..5e56dc9bdd 100644 --- a/spec/functions/number.md +++ b/spec/functions/number.md @@ -659,7 +659,7 @@ a literal whose contents match the following `number-literal` production. All other values produce a _Bad Operand_ error. ```abnf -number-literal = ["-"] (%x30 / (%x31-39 *DIGIT)) ["." 1*DIGIT] +number-literal = ["-"] (%x30 / (%x31-39 *DIGIT)) ["." 1*DIGIT] [%i"e" ["-" / "+"] 1*DIGIT] ``` > For example, in Java, any subclass of `java.lang.Number` plus the primitive diff --git a/test/tests/functions/integer.json b/test/tests/functions/integer.json index 576c037b28..3e7f933418 100644 --- a/test/tests/functions/integer.json +++ b/test/tests/functions/integer.json @@ -19,6 +19,10 @@ "src": "hello {0.42 :integer}", "exp": "hello 0" }, + { + "src": "hello {|0.42e+1| :integer}", + "exp": "hello 4" + }, { "src": ".input {$foo :integer} .match $foo 1 {{=1}} * {{other}}", "params": [{ "name": "foo", "value": 1.2 }], diff --git a/test/tests/functions/number.json b/test/tests/functions/number.json index fc4418606f..c16ddda646 100644 --- a/test/tests/functions/number.json +++ b/test/tests/functions/number.json @@ -19,6 +19,10 @@ "src": "hello {0.42 :number}", "exp": "hello 0.42" }, + { + "src": "hello {|0.42e+1| :number}", + "exp": "hello 4.2" + }, { "src": "hello {foo :number}", "exp": "hello {|foo|}", From b35f97afb5125c5907b704d9c75d17b58c295da9 Mon Sep 17 00:00:00 2001 From: Eemeli Aro Date: Wed, 12 Feb 2025 22:19:25 +0200 Subject: [PATCH 3/3] Update spec/syntax.md Co-authored-by: Addison Phillips --- spec/syntax.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/syntax.md b/spec/syntax.md index 9119f32b79..acdb573853 100644 --- a/spec/syntax.md +++ b/spec/syntax.md @@ -740,7 +740,7 @@ Implementations MUST NOT distinguish between _quoted literals_ and _unquoted lit that have the same sequence of code points. _Unquoted literals_ can contain any characters also valid in _name_, -but with none of its additional restrictions on its first character. +less _name_'s additional restrictions on the first character. ```abnf literal = quoted-literal / unquoted-literal