Re: Ambiguous syntax
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: Ambiguous syntax
- From: Sven Olsen <sven2718@...>
- Date: 2012年12月12日 00:34:47 -0800
There's no honest ambiguity in the syntax -- it's just a question of protecting against likely bugs.
f()
(g or h)()
is naturally read as 2 statements, though given Lua's grammar it should be parsed as just one. Lua 5.1 was newline sensitive: it would throw an error if an otherwise complete _expression_ was continued by a newline, followed by an open paren. Lua 5.2 removed the check.
My feeling is that this was a bad change -- I've never come across a case where the error was triggered by bug-free code. I've actually changed my own 5.2 parser to restore 5.1's newline sensitivity, though, rather than throwing an error, I just terminate the _expression_ -- and I wrote a long post about the pros and cons of this idea, a few months back :)
-Sven
On Tuesday, December 11, 2012, Peter Loveday wrote:
This does it in 5.1:
print
("hello")
- Peter
-----Original Message----- From: Coda Highland
Sent: Wednesday, December 12, 2012 5:10 PM
To: Lua mailing list
Subject: Re: Ambiguous syntax
On Tue, Dec 11, 2012 at 10:00 PM, Dirk Laurie <dirk.laurie@gmail.com> wrote:
Can someone who understands the matter please explain
why Lua 5.1 sometimes gave the message
ambiguous syntax (function call x new statement)
whereas Lua 5.2 never does?
I think I remember hearing about 5.2 arbitrarily defining a resolution
for the grammatical ambiguity. Do you have an example of code that
triggers this?
/s/ Adam
-----
No virus found in this message.
Checked by AVG - www.avg.com
Version: 201202221 / Virus Database: 2634/5452 - Release Date: 12/11/12