[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua grammar question
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Thu, 25 Mar 2010 13:21:27 -0300
> 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.