diff --git a/guide/functions.md b/guide/functions.md index 81329ba..fb91239 100644 --- a/guide/functions.md +++ b/guide/functions.md @@ -30,6 +30,10 @@ are only available to developers when they pre-format variables passed as arguments to translations (see [Partially-formatted variables](#partially-formatted-variables) below). +Any inline expression may be used as a positional argument, +but named argument values are limited to literal values in Fluent 1.0. +In Fluent 1.1, a variable reference may also be used as a named argument value. + ## Built-in Functions Built-in functions are very generic and should be applicable to any translation diff --git a/guide/terms.md b/guide/terms.md index 2d6e880..87f62b2 100644 --- a/guide/terms.md +++ b/guide/terms.md @@ -20,7 +20,8 @@ or they can interpolate other expressions, including variables. However, while messages receive data for variables directly from the app, terms receive such data from messages in which they are used. Such references take the form of `-term(…)` where the variables available inside of the term are -defined between the parentheses, e.g. `-term(param: "value")`. +defined between the parentheses, e.g. `-term(param: "value")` or +`-term(param: $arg)` (starting from Fluent 1.1). ``` # A contrived example to demonstrate how variables diff --git a/spec/fluent.ebnf b/spec/fluent.ebnf index ec29c8c..1fbf956 100644 --- a/spec/fluent.ebnf +++ b/spec/fluent.ebnf @@ -72,7 +72,7 @@ CallArguments ::= blank? "(" blank? argument_list blank? ")" argument_list ::= (Argument blank? "," blank?)* Argument? Argument ::= NamedArgument | InlineExpression -NamedArgument ::= Identifier blank? ":" blank? (StringLiteral | NumberLiteral) +NamedArgument ::= Identifier blank? ":" blank? (StringLiteral | NumberLiteral | VariableReference) /* Block Expressions */ SelectExpression ::= InlineExpression blank? "->" blank_inline? variant_list diff --git a/syntax/grammar.js b/syntax/grammar.js index 0047932..731d0ff 100644 --- a/syntax/grammar.js +++ b/syntax/grammar.js @@ -302,7 +302,8 @@ let NamedArgument = defer(() => maybe(blank), either( StringLiteral, - NumberLiteral).abstract) + NumberLiteral, + VariableReference).abstract) .map(keep_abstract) .chain(list_into(FTL.NamedArgument))); diff --git a/test/fixtures/call_expressions.ftl b/test/fixtures/call_expressions.ftl index 03f3a61..e9dfe71 100644 --- a/test/fixtures/call_expressions.ftl +++ b/test/fixtures/call_expressions.ftl @@ -19,6 +19,7 @@ positional-args = {FUN(1, "a", msg)} named-args = {FUN(x: 1, y: "Y")} dense-named-args = {FUN(x:1, y:"Y")} mixed-args = {FUN(1, "a", msg, x: 1, y: "Y")} +variable-args = {FUN($foo, arg: $bar)} # ERROR Positional arg must not follow keyword args shuffled-args = {FUN(1, x: 1, "a", y: "Y", msg)} diff --git a/test/fixtures/call_expressions.json b/test/fixtures/call_expressions.json index 1e85992..25e566e 100644 --- a/test/fixtures/call_expressions.json +++ b/test/fixtures/call_expressions.json @@ -351,6 +351,58 @@ "attributes": [], "comment": null }, + { + "type": "Message", + "id": { + "type": "Identifier", + "name": "variable-args" + }, + "value": { + "type": "Pattern", + "elements": [ + { + "type": "Placeable", + "expression": { + "type": "FunctionReference", + "id": { + "type": "Identifier", + "name": "FUN" + }, + "arguments": { + "type": "CallArguments", + "positional": [ + { + "type": "VariableReference", + "id": { + "type": "Identifier", + "name": "foo" + } + } + ], + "named": [ + { + "type": "NamedArgument", + "name": { + "type": "Identifier", + "name": "arg" + }, + "value": { + "type": "VariableReference", + "id": { + "type": "Identifier", + "name": "bar" + } + } + } + ] + } + } + } + ] + }, + "attributes": [], + "comment": null + }, { "type": "Comment", "content": "ERROR Positional arg must not follow keyword args" diff --git a/test/fixtures/term_parameters.ftl b/test/fixtures/term_parameters.ftl index 600c12c..02aff9a 100644 --- a/test/fixtures/term_parameters.ftl +++ b/test/fixtures/term_parameters.ftl @@ -6,3 +6,4 @@ key01 = { -term } key02 = { -term () } key03 = { -term(arg: 1) } key04 = { -term("positional", narg1: 1, narg2: 2) } +key05 = { -term(arg: $foo) } diff --git a/test/fixtures/term_parameters.json b/test/fixtures/term_parameters.json index 18d97cd..59bbce0 100644 --- a/test/fixtures/term_parameters.json +++ b/test/fixtures/term_parameters.json @@ -202,6 +202,51 @@ }, "attributes": [], "comment": null + }, + { + "type": "Message", + "id": { + "type": "Identifier", + "name": "key05" + }, + "value": { + "type": "Pattern", + "elements": [ + { + "type": "Placeable", + "expression": { + "type": "TermReference", + "id": { + "type": "Identifier", + "name": "term" + }, + "attribute": null, + "arguments": { + "type": "CallArguments", + "positional": [], + "named": [ + { + "type": "NamedArgument", + "name": { + "type": "Identifier", + "name": "arg" + }, + "value": { + "type": "VariableReference", + "id": { + "type": "Identifier", + "name": "foo" + } + } + } + ] + } + } + } + ] + }, + "attributes": [], + "comment": null } ] }