[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Thoughts on optional commas
- From: Wolfgang Pupp <wolfgang.pupp@...>
- Date: Tue, 6 Mar 2012 02:57:46 +0100
I agree that forgetting commas in table-constructors this is a pretty
common annoyance (speaking from personal experience :P).
I think it's possible to make this smoother and more
beginner-friendly, without breaking *anything*:
Make commas optional for *consequent* <tkey> = <tvalue> 'assignments'
in table constructors.
Here is the relevant part of the Lua (5.1)-syntax:
tableconstructor ::= '{' [fieldlist] '}'
fieldlist ::= field {fieldsep field} [fieldsep]
field ::= '[' exp ']' '=' exp | Name '=' exp | exp
The only change would be:
field ::= tassign {tassign} | exp
tassign ::= '[' exp ']' '=' exp | Name '=' exp
I think this would allow to omit commas where they annoy most
("statement-like" table constructors), without introducing unnecessary
ambiguities.
Gregs initial example would only require 2 commas instead of 12 with
this change (AFAICT).
It would also be pretty simple to remember: Commas only needed when
constructing sequences (without specifying the keys explicitly).
Discuss! (I like this better and better the more I think about it; are
there any hidden flaws?)