lua-users home
lua-l archive

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


Hi,

I ask for a relaxed syntax for the table constructors.  More
precisely, let the ',' separating the record fields be optional.
The list fields stay as they are.  The ',' is only needed if
the construct is ambiguous.  But if they are a syntax error
will be raised if the ',' is missing.  Examples:

{ a=a b=b }    -- no problem here
{ a=a [b]=b }  -- ambiguity but gives syntax error

Is there another problem?  I don't think so.

This would be the required patch for lparser.c:

 static int recfields (LexState *ls) {
   /* recfields -> recfield { ',' recfield } [','] */
   FuncState *fs = ls->fs;
   int n = 1;  /* at least one element */
   recfield(ls);
-  while (ls->t.token == ',') {
-    next(ls);
+  for (;;) {
+    optional(ls, ',');
     if (ls->t.token == ';' || ls->t.token == '}')
       break;
...


Ciao, ET.