On Tue, Nov 28, 2017 at 4:45 AM, Daniel Dekany <[email protected]> wrote:
> This problem comes up again and again: the ${exp} syntax clashes with
> the syntax of the thing the user wants to generate. So I believe we
> need a Configuration option to address this. Something like
> cfg.setInterpolationSyntax(FOO_INTERPOLATION_SYNTAX), and also
> <#ftl interpolationSyntax="foo">.
>
> Like any syntax option, this is potentially confusing for users and
> problem for tools, but I don't think there's a way around this. Users
> have to deal with those clashing ${}-s somehow, and certainly an
> in-house hack will be worse and even more confusing. (Surely they can
> write ${'$'}{foo} or use #noparse, but if you need a lot of those,
> then it's obviously not an acceptable workaround.)
>
> So, what the syntax would be? Some of my ideas:
>
> - {{exp}} is probably the nicest. For the same reason it potentially
> clashes with something yet again, though I guess it's unlikely
> enough that neither ${exp} nor {{exp}} works for you.
>
> - @{exp}. It's similar to ${exp}, which I think is an advantage.
> There's however a very small but still real chance that for someone
> both ${} and @{} clashes with what they want to generate, because
> using <someChar>{name} is somewhat popular.
>
> - #{exp}. That looks like the natural choice as we use # in tags as
> well (also @, though). The reason I don't like it is that
> we already have #{exp} in the standard syntax, but it's deprecated.
> That's not a problem technically, as you can say that if you select
> the #{} syntax, then it's not deprecated, and ${} will be treated
> as static text. But now if someone sees #{exp}, they can't tell if
> the template uses a deprecated syntax, or it uses the alternative
> interpolation syntax. Also it's perhaps more likely that for someone
> both ${} and #{} clashes (e.g. in the case you generate JSF JSP-s),
> than that that both ${} and @{} clashes.
>
> - <=exp> and [=exp] depending on if you are using square- or
> angle-bracket tag syntax. Look somewhat exotic... which also means
> that hopefully it won't clash with anything.
I personally prefer the style with square-bracket: [=exp], which seems
most unique and intuitive.
It is also most productive as no shift key is required.
I like [=exp] better than <=exp> by the way, because the latter is
confusing (looks like <%=exp>) and requiring shift keys.
Regards,
Woonsan
>
> There's also the idea that we just let the user specify any separator,
> like `cfg.setInterpolationStart("@{"); cfg.setInterpolationEnd("}")`.
> But if all kind of random syntax is possible, it's harder for users to
> figure out what's going on (their syntax isn't mentioned in the
> Manual, and nobody on StackOverlfow recognizes it either), and it's
> more difficult to support that in tools as well. So I believe it's
> better for everyone if there's one, or maybe two standard
> alternatives. (Not to mention that I don't yet see how to implement
> such a runtime-configured syntax with the current JavaCC-based parser.
> Probably it would be a horrid hack if possible at all.)
>
> Opinions, ideas?
>
> --
> Thanks,
> Daniel Dekany
>