lua-users home
lua-l archive

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

I don't know the exact reasoning, but I'll note that these also won't work:

I suspect it has to due with semicolons. Because Lua doesn't have a required "end the statement" token, there's always a chance of bugs due to syntax ambiguities.  Specifically, you'll get in to trouble with lines like:

(f or g)()
(h or g)() 

Lua's string and table function call shorthand both terminate the statement they're a part of when they're evoked. Which means there's no ambiguity here:

(f or g) {}
(h or g) ()

Well I added this change to my patch as well. So my syntax patch seems to work, but know I am thinking if there are some other redundant brackets I could get rid of.

Be aware that if you patch the parser to allow suffix expressions that immediately follow tables or string literals, the meaning of vanilla Lua code may change.  See specifically the preceding code, which used to parse as 2 statements, though now it's just a single one (and a likely bug).

As an occasional parser hacker, I've been down this road myself.  By my best recollection, I think it may be possible to get really clever, and tweak the parser to only allow table and string suffix expressions in cases where doing so does not expand the set of possible syntax ambiguities -- i.e., to write a version of the table/string suffix patch that's guaranteed to be backwards compatible.  The diff would get considerably bigger though -- and it seems like a lot of work for a minor feature.