lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Thu, Jan 14, 2021 at 6:30 PM Viacheslav Usov <via.usov@gmail.com> wrote:
> The question is, why is the first version not accepted? I am not
> asking for an explanation why the details are such and such, but
> rather for a rationale, if there is one, that a table "literal"
> (constructor) should not appear in some expressions unless it is
> wrapped in parentheses.

Well, it is not accepted because the grammar says so ( prefixeps,
which is what you can index, are not general expressions ). And the
grammar probably says so to simplify the parsing, although the lua
team may have some thing to say on this. Probably for the same reason
you cannot use the : operator on string literal and some other
oddities, it complicates implementation, is not too useful and can be
easily done with just some parentheses, does not pull its weight.

> Especially when we consider that there is special syntax for a table
> "literal" in a function call that dispenses with parentheses.

IIRC the string / table literal are there to simplify use of lua in
DSLs and similar stuff, it may have been deemed worth some parser
complication. You find a lot of cases when you try to pile up things
in lua compared to other languages, probably due to it having a 1 page
grammar.

Francisco Olarte.