lua-users home
lua-l archive

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


On Fri, Jun 12, 2009 at 10:42 AM, Henk Boom wrote:
> In the context, this makes more sense than the original error message,
> which would imply that Lua only expects 'then' after 'a'.

More generally, we might instead patch lparser.c:subexpr to suggest
"==" if an r-value sub-expression is followed by an "=" :

--- lua-5.1.4/src/lparser.c
+++ lua-5.1.4-better-errors/src/lparser.c
400
@@ -849,6 +849,8 @@
     op = nextop;
   }
   leavelevel(ls);
+  if (ls->t.token == '=')
+    error_expected(ls, TK_EQ);
   return op;  /* return first untreated operator */
 }

Tests (old and new errors respectively):

if x = y then end
--> stdin:1: 'then' expected near '='
--> stdin:1: '==' expected near '='

while x = f() do end
--> stdin:1: 'do' expected near '='
--> stdin:1: '==' expected near '='

repeat until x = y
--> stdin:1: unexpected symbol near '='
--> stdin:1: '==' expected near '='

x = y = z
--> stdin:1: unexpected symbol near '='
--> stdin:1: '==' expected near '='

x = w or (y = z)
--> stdin:1: ')' expected near '='
--> stdin:1: '==' expected near '='

if a b then end
--> stdin:1: 'then' expected near 'b'
--> stdin:1: 'then' expected near 'b'