lua-users home
lua-l archive

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


On Thu, Jun 11, 2009 at 10:58 PM, David Manura wrote:
> On Thu, Jun 11, 2009 at 12:45 PM, Michael Newberry wrote:
>> Here's another one:
>>
>>   `=' expected near `ot'
>>
>> is thrown by
>>
>>   ifn ot CMyClass then
>
> ... You might do this patch on assignments: ...
>
>  ifn ot CMyClass then print() end
>  --> stdin:1: ',', '(', or '=' expected near 'ot'

This patch to lparser.c:assignment may more practical:

--- lua-5.1.4/src/lparser.c
+++ lua-5.1.4-better-errors-2/src/lparser.c
@@ -944,7 +944,9 @@
   }
   else {  /* assignment -> `=' explist1 */
     int nexps;
-    checknext(ls, '=');
+    if (ls->t.token != '=')
+      luaX_syntaxerror(ls, "unrecognized statement");
+    luaX_next(ls);
     nexps = explist1(ls, &e);
     if (nexps != nvars) {
       adjust_assign(ls, nvars, nexps, &e);

Tests (old and new errors respectively):

a b c
--> stdin:1: '=' expected near 'b'
--> stdin:1: unrecognized statement near 'b'

If x then end
--> stdin:1: '=' expected near 'x'
--> stdin:1: unrecognized statement near 'x'

> x[1][2] y
--> stdin:1: '=' expected near 'y'
--> stdin:1: unrecognized statement near 'y'

a,b c
--> stdin:1: '=' expected near 'c'
--> stdin:1: unrecognized statement near 'c'