Proposal: paren-free function calls and definitions

Claus Reinke claus.reinke at talk21.com
Mon Jun 20 01:49:00 PDT 2011


> This is not just awkward, of course -- the grammar you propose is
> ambiguous.

No ambiguity intended - function bodies extend as far to the right
as possible (see Note 1).

> The precedence inversion means there are two ways to parse
>
>  z = a + function (b) => b ? c : d;
>..
>  z = a + (function (b) => (b ? c : d));

This is the intended parse, and also the one used by the prototype
(you can change 'opts ="pu"' to 'opts = "pua"' to get the ast). To
get the other parse, one would need explicit parens.

The idea is to get the longest parse paren-free, with parens as a
means to get more fine-control to limit function bodies. That does
imply that things to the right of a function tend to get swallowed
up in the function body.

As for your other example,

>  function f(x) => x;
>  z = a + function (b) => b ? f : x++(1);
>
>parses awkwardly, as ( z = ( a + ( function (b) => ( b ? f : ( x ++ ) ) ) 
>(1) ) ).

I'm not following yet - what parse would you like to see instead
of this one? If you wanted the function body to end earlier, you
can get that by adding parens, right?

Claus
 



More information about the es-discuss mailing list