Skip to content

Use (parentheses) rather than "quotes" around literal values #276

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

Merged
merged 3 commits into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
14 changes: 7 additions & 7 deletions spec/message.ebnf
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ Selector ::= (Variable '=')? '{' Expression '}'

/* Variants and Patterns */
Variant ::= VariantKey* Pattern
VariantKey ::= String | Nmtoken | '*'
VariantKey ::= Literal | Nmtoken | '*'
Pattern ::= '[' (Text | Placeholder)* ']' /* ws: explicit */

/* Placeholders */
Placeholder ::= '{' (Expression | MarkupStart | MarkupEnd)? '}'

/* Expressions */
Expression ::= Operand Annotation? | Annotation
Operand ::= String | Variable
Operand ::= Literal | Variable
Annotation ::= Function Option*
Option ::= Name '=' (String | Nmtoken | Variable)
Option ::= Name '=' (Literal | Nmtoken | Variable)

/* Markup Tags */
MarkupStart ::= Name Option*
Expand Down Expand Up @@ -48,14 +48,14 @@ NameStart ::= [a-zA-Z] | "_"
NameChar ::= NameStart | [0-9] | "-" | "." | #xB7
| [#x0300-#x036F] | [#x203F-#x2040]

/* Quoted strings */
String ::= '"' (StringChar | StringEscape)* '"' /* ws: explicit */
StringChar ::= AnyChar - ('"'| Esc)
/* Literals */
Literal ::= '(' (LiteralChar | LiteralEscape)* ')' /* ws: explicit */
LiteralChar ::= AnyChar - ('(' | ')' | Esc)

/* Escape sequences */
Esc ::= '\'
TextEscape ::= Esc Esc | Esc '[' | Esc ']' | Esc '{' | Esc '}'
StringEscape ::= Esc Esc | Esc '"'
LiteralEscape ::= Esc Esc | Esc '(' | Esc ')'

/* WhiteSpace */
WhiteSpace ::= #x9 | #xD | #xA | #x20 /* ws: definition */
36 changes: 18 additions & 18 deletions spec/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ The key `*` is a "catch-all" key, matching all selector values.

```ebnf
Variant ::= VariantKey* Pattern
VariantKey ::= String | Nmtoken | '*'
VariantKey ::= Literal | Nmtoken | '*'
```

A well-formed message is considered valid if the following requirements are satisfied:
Expand All @@ -300,8 +300,8 @@ This serves 3 purposes:
`hello = [Hello]` will unambiguously define the `Hello` message without the space in front of it.
- The message should be conveniently embeddable in various programming languages
without the need to escape characters commonly related to strings, e.g. `"` and `'`.
Such need may still occur when a singe or double quote is
used in the translatable content or to delimit a string literal.
Such need may still occur when a single or double quote is
used in the translatable content.
- The syntax should make it as clear as possible which parts of the message body
are translatable and which ones are part of the formatting logic definition.

Expand All @@ -327,7 +327,7 @@ Placeholder ::= '{' (Expression | MarkupStart | MarkupEnd) '}'

Expressions can either start with an operand, or be standalone function calls.

The operand is a quoted string literal or a variable name.
The operand is a literal or a variable name.
The operand can be optionally followed by an _annotation_:
a formatting function and its named options.
Formatting functions do not accept any positional arguments
Expand All @@ -337,27 +337,27 @@ Standalone function calls don't have any operands in front of them.

```ebnf
Expression ::= Operand Annotation? | Annotation
Operand ::= String | Variable
Operand ::= Literal | Variable
Annotation ::= Function Option*
Option ::= Name '=' (String | Nmtoken | Variable)
Option ::= Name '=' (Literal | Nmtoken | Variable)
```

Examples:

```
"1.23"
(1.23)
```

```
"1.23" :number maxFractionDigits=1
(1.23) :number maxFractionDigits=1
```

```
"1970-01-01T13:37:00.000Z" :datetime weekday=long
(1970-01-01T13:37:00.000Z) :datetime weekday=long
```

```
"Thu Jan 01 1970 14:37:00 GMT+0100 (CET)" :datetime weekday=long
(Thu Jan 01 1970 14:37:00 GMT+0100 \(CET\)) :datetime weekday=long
```

```
Expand Down Expand Up @@ -388,7 +388,7 @@ Examples:
```

```
[{h1 name="above-and-beyond"}Above And Beyond{/h1}]
[{h1 name=(above-and-beyond)}Above And Beyond{/h1}]
```

## Tokens
Expand Down Expand Up @@ -440,26 +440,26 @@ NameChar ::= NameStart | [0-9] | "-" | "." | #xB7
| [#x0300-#x036F] | [#x203F-#x2040]
```

### Quoted Strings
### Literal

Any Unicode codepoint is allowed in quoted string literals, with the exception of
`"` (which ends the string literal),
Any Unicode code point is allowed in literals,
with the exception of its delimiters `(` and `)`,
and `\` (which starts an escape sequence).

```ebnf
String ::= '"' (StringChar | StringEscape)* '"' /* ws: explicit */
StringChar ::= AnyChar - ('"'| Esc)
Literal ::= '(' (LiteralChar | LiteralEscape)* ')' /* ws: explicit */
LiteralChar ::= AnyChar - ('(' | ')' | Esc)
```

### Escape Sequences

Escape sequences are introduced by the backslash character (`\`).
They are allowed in translatable text as well as in string literals.
They are allowed in translatable text as well as in literals.

```ebnf
Esc ::= '\'
TextEscape ::= Esc Esc | Esc '[' | Esc ']' | Esc '{' | Esc '}'
StringEscape ::= Esc Esc | Esc '"'
LiteralEscape ::= Esc Esc | Esc '(' | Esc ')'
```

### Whitespace
Expand Down