On Fri, Dec 16, 2016 at 11:15 AM, <
zbran...@mozilla.com> wrote:
> I suggest that we allow for range of selectors to be grouped.
I support this change although I have comments about the syntax below.
If we find a solution to address the comments, this proposal would
offer a convenient sugar for a use-case for which we want to encourage
a good practice.
> key = { $num, $gender ->
> [one, masculine] She likes when he dances
> [one, feminine] She likes when she dances
> [other, masculine] They like when he dances
> [other, feminine] They like when she dances
> }
>
> It requires small changes to the AST and syntax, since we already support lists ("key = { $user1, $user2 }") and we only would need to allow a selector expression to be a list and keyword key to be a list.
We need to decide what the operator precedence of ',' and '->' is. If
the comma binds tighter then the current syntax does not allow to
build a list formatted via Intl.ListFormat with a select expression as
one of its elements. OTOH, if the arrow binds tighter, the example
above will only use $gender as the selector.
To remove the ambiguity, we could (a) introduce parentheses for
selector grouping. { foo, (bar, baz) -> ... } or maybe { foo, [bar,
baz] -> ... } to make it consistent with the syntax for keywords.
Perhaps the meaning of [ ] could be changed to denote tuples.
Alternatively, we could (b) introduce parens for grouping expressions:
{ foo, (bar, baz -> ...) }. This would have the benefit of also being
unambiguous for trailing elements: { foo, (bar, baz -> ...), qux }
which is hard to achieve in (a). While { foo, (bar, baz) -> ..., qux
} may look feasible keep in mind that there are newline breaks hiding
behind that ... . A more appropriate example would need to be:
{ foo, (bar, baz) ->
[one, one] One bar, one baz.
[other, other] Many bars, many bazes.
, qux }
^-- this comma here is required to end the (bar, baz) -> ... select
expression.
Another solution (c) is a workaround that's possible right now: use
another Pattern with a placeable: { foo, "{ bar, baz -> .. }", qux }.
I'd consider this a hack around a shortcoming of the current syntax
design. If we're making changes, let's fix this one too.
My last idea (d) is to remove the implicit list syntax, i.e. { foo,
bar } being equal to { LIST(foo, bar) }. I wouldn't mind simplifying
the AST of placeables and making them single-valued. I assume lists
will be rare and calling the LIST builtin would improve the
readability by being more explicit. This would allow using { and }
for grouping, like so: { LIST(foo, { bar, baz -> ... }, qux) }. { and
} could be
My current vote goes to (d) as it doesn't introduce any new syntax
tokens and manages to simplify the AST for placeables. I'm curious to
hear what you think!
-stas