Skip to content

Fix #2. Disallow multiple expressions in a placeable. #14

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 1 commit into from
Jan 25, 2017
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
4 changes: 1 addition & 3 deletions fluent.asdl
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ module Fluent
| Comment(comment)
| Junk(string body)

pat = Pattern(elem* elements, bool quoted)
elem = Text(string)
| Placeable(expr* expressions)
pat = Pattern(expr* elements, bool quoted)

expr = MessageReference(iden id)
| ExternalArgument(iden id)
Expand Down
11 changes: 4 additions & 7 deletions fluent.ebnf
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,19 @@ unquoted-text ::= ([^{] | '\{')+;
quoted-text ::= ([^{"] | '\{' | '\"')+;
block-text ::= NL __ '|' unquoted-pattern;

placeable ::= '{' __ placeable-list __ '}';
placeable-list ::= placeable-expression (__ ',' __ placeable-list)?;
placeable-expression ::= expression
| select-expression
;
placeable ::= '{' __ expression __ '}';
expression ::= quoted-pattern
| number
| identifier
| variable
| call-expression
| select-expression
| member-expression
| call-expression
;
select-expression ::= expression __ ' ->' __ variants-list;
member-expression ::= identifier '[' keyword ']';
call-expression ::= builtin '(' __ arglist? __ ')';
arglist ::= argument (__ ',' __ arglist)?;
argument ::= expression
| keyword-argument;
keyword-argument ::= identifier __ ':' __ quoted-pattern;
member-expression ::= identifier '[' keyword ']';
12 changes: 1 addition & 11 deletions functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,6 @@ Implicit use
In order to simplify most common scenarios, FTL will run some default
functions while resolving placeables.

For the list of implicit functions, the implict example has exactly the same
result as the explicit one.

``NUMBER``
If the variable passed from the developer is a number and is used in
a placeable, FTL will implicitly call a `NUMBER` function on it.
Expand Down Expand Up @@ -198,18 +195,11 @@ result as the explicit one.
log-time2 = Entry time: { DATETIME($date) }

``LIST``
If the variable passed from the developer is a number and is used in
If the variable passed from the developer is an array and is used in
a placeable, FTL will implicitly call a `LIST` function on it.

Also, if the placeable is a list of variables, FTL will implicitly
call a `LIST` function on it.

Example::

users = { LIST($user1, $user2, $user3) }

users2 = { $user1, $user2, $user3 }

users = { LIST($users) }

users2 = { $users }
Expand Down
22 changes: 13 additions & 9 deletions guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -361,14 +361,15 @@ Complex Example
liked-photo = { LEN($people) ->
[1] { $people } likes
[2] { $people } like
[3] { TAKE(2, $people), "one more person" } like

*[other] { TAKE(2, $people),
"{ LEN(DROP(2, $people)) ->
[1] one more person like
*[other] { LEN(DROP(2, $people)) } more people like
}"
}
[3] { LIST(TAKE(2, $people), "one more person") } like

*[other] { LIST(
TAKE(2, $people),
"{ LEN(DROP(2, $people)) ->
[1] one more person like
*[other] { LEN(DROP(2, $people)) } more people like
}"
)}
} your photo.

::
Expand All @@ -388,7 +389,10 @@ people.

This example is very sophisticated and in fact could be simplified like so::

liked-photo = { LEN($people) } like your photo
liked-photo = { LEN($people) ->
[one] One person likes
*[other] { LEN($people) } people like
} your photo.

It would work well enough for English and could work for other languages
without increasing its complexity.
Expand Down