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

Specify pattern resolution behavior for patterns with syntax errors #462

Closed
wants to merge 1 commit into from
Closed
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
23 changes: 19 additions & 4 deletions spec/formatting.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,21 @@ _Pattern selection_ is not supported for _fallback values_.

## Pattern Selection

### Messages without Selectors

When a _message_ does not contain a _match_ construct,
and does not begin with a U+007B LEFT CURLY BRACKET `{`,
the result of pattern selection MUST be the concatenation of
a U+007B LEFT CURLY BRACKET `{`,
the contents of the message as a string,
and a U+007D RIGHT CURLY BRACKET `}`.

> For example, the following message:
> `no braces`
> would format to a string as `{no braces}`.
Comment on lines +240 to +251
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is "pattern selection". This is a parse error, since the message is not, well, a message. What's more, the message "no braces {some braces}" is not a message.

I think the thing that is missing in formatting.md is the first step, which is: parsing. This should result in an syntax error. We could then go on to define what happens to the string that wants to be a message.

To be honest, I would not add the curly brackets. If you give me a string and it produces a syntax error, I should probably give you back the string as you gave it to me. If you thought it should be a valid message, you can debug it. If you are a runtime process, you can just display it (as we didn't damage it).


Note well: I argued long and hard that a plain old string with no placeholders should be a valid message. This is the old argument code-mode vs. string-mode. I am not reopening this, but we're going to tangle with the fact that you have to grope strings before feeding them to MF2 as a result.


### Messages with Selectors

When a _message_ contains a _match_ construct with one or more _expressions_,
the implementation needs to determine which _variant_ will be used
to provide the _pattern_ for the formatting operation.
Expand Down Expand Up @@ -278,7 +293,7 @@ the result of pattern selection MUST be a pattern resolving to a single _fallbac
using the message's fallback string defined in the _formatting context_
or if this is not available or empty, the U+FFFD REPLACEMENT CHARACTER `�`.

### Resolve Selectors
#### Resolve Selectors

First, resolve the values of each _selector_ _expression_:

Expand All @@ -295,7 +310,7 @@ First, resolve the values of each _selector_ _expression_:
The shape of the resolved values is determined by each implementation,
along with the manner of determining their support for selection.

### Resolve Preferences
#### Resolve Preferences

Next, using `res`, resolve the preferential order for all message keys:

Expand All @@ -320,7 +335,7 @@ The returned list MAY be empty.
The most-preferred key is first,
with each successive key appearing in order by decreasing preference.

### Filter Variants
#### Filter Variants

Then, using the preferential key orders `pref`,
filter the list of _variants_ to the ones that match with some preference:
Expand All @@ -340,7 +355,7 @@ filter the list of _variants_ to the ones that match with some preference:
1. Continue the outer loop on message _variants_.
1. Append `var` as the last element of the list `vars`.

### Sort Variants
#### Sort Variants

Finally, sort the list of variants `vars` and select the _pattern_:

Expand Down