diff --git a/fluent.asdl b/fluent.asdl index cc1011d..703499a 100644 --- a/fluent.asdl +++ b/fluent.asdl @@ -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) diff --git a/fluent.ebnf b/fluent.ebnf index dccfef9..5e88483 100644 --- a/fluent.ebnf +++ b/fluent.ebnf @@ -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 ']'; diff --git a/functions.rst b/functions.rst index 58b737e..0635af3 100644 --- a/functions.rst +++ b/functions.rst @@ -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. @@ -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 } diff --git a/guide.rst b/guide.rst index 26d7ce6..5a37d87 100644 --- a/guide.rst +++ b/guide.rst @@ -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. :: @@ -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.