lua-users home
lua-l archive

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


> Recently I stumbled upon that `print({}[1])` fails to parse with "')'
> expected near '['". However `print(({})[1])` parses without problem.
> 
> I checked Lua's grammar and found out that this is the expected
> behavior and not a bug in Lua's parser.
> 
> Is there a reason for this? Would allowing expressions like
> `{foo}[bar]` overcomplicate Lua's grammar and parsing?

Consider
	a=f
	{}[1].x=2

This can be confused with a=f{}[1].x=2, which is only seen to be an error
when the second = is seen, and this may require arbitrarily long lookahead.
Note that a=f{}[1].x is legal.