Friday, June 16, 2017, 8:41:37 PM, Daniel Dekany wrote:

> A problem in FM2 is that when calling a directive (as a macro), either
> all parameters are positional (`<@message "Hi" 2 />`), or all
> parameters are named (`<@message content="Hi" height=2 />`); you can't
> mix the two (`<@message "Hi" height=2 />`). Also you can't use named
> parameters for functions/methods, only for directives. Worse, core
> directives don't even use named parameters, but some keyword like
> `as`, `using`... their syntax is hard coded into the parser, which is
> not nice, and will be a problem for the custom dialects feature.
>
> I think that with the exception of a few core directives (see them
> later) all directive calls should be like this, if for now (in this
> thread) we ignore loop variables:
>
>   <#name posPar1 posPar2 namedPar1Name=namedPar1Value 
> namedPar2=namedPar2Value>

An adjustment to the above... I think that we should require comma
between positional arguments (but not between positional and named
arguments and between named arguments):

  <#name posPar1, posPar2 namedPar1Name=namedPar1Value namedPar2=namedPar2Value>

FM2 supports both the <@foo 1, 2, 3 /> and <@foo 1 2 3 /> variation
(and has no core directive with more the one positional argument,
hence I demonstrated it with a custom directive). I believe it's
better stick to one syntax or the other in FM3, not supporting both.
Question is, which one.

While <@foo 1 2 3 /> fits HTML style better, it can be ambiguous.
Consider:

- In `<@foo x - 1 />` is the argument `x - 1`, or we have an `x` and a `-1` 
argument?

- In `<@foo x! 1 />` is the argument `x!1`, or we have an `x!` and a `1` 
argument?

Technically, you can make whitespace significant, so that `<@foo x -1 />`
and `<@foo x - 1 />` has different meaning, but its a quite extreme
syntax design, and when you writing templates, I doubt many users will
even realize that such subtle rules exist. With comma, it's obvious to
do (`<@foo x - 1 />` VS `<@foo x, -1 />`, or even `<@foo x, - 1 />`). It
looks a bit odd next to named parameters, but certainly by far the
most common application of mixed positional and named parameters is
when you have only one positional parameters (<@launch rocket1 delay=3 />),
in which case the comma doesn't appear anyway.

For function calls, which follow typical C-ish expression syntax,
using commas even between named parameters is the natural thing (as in
`f(1, 2, foo=3, bar=4)`), so I would stick to that.

[snip]
> parameters is `<#ftl outputFormat='RTF'>`. So far it's the same as in
> FM2. But now we could have both in once call, such as
> `<#visit node handlers=myNamespace>` (regular syntax), which was
> `<#visit node using myNamespace>` in FM2 (irregular syntax hard coded
> into the parser).
[snip]

For completeness, let's see what other non-regular core directives we
have.

- For #import I would switch to assignment-like approach:
  FM2: <#import "foo.ftl" as f> <#import "bar.ftl" as b>
  FM3: <#import f="foo.ftl" b="bar.ftl">

- #escape doesn't mater, as it will be removed (in favor of output
  formats introduced in 2.3.24).

- #assign has this `in` thing, like `<#assign x = 1 in ns>`. We will
  want to allow <#assign ns.x = 1> (actually, #set) anyway, so that
  won't mater either.

-- 
Thanks,
 Daniel Dekany

Reply via email to