[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Next Version of Lua
- From: Patrick Donnelly <batrick@...>
- Date: Thu, 11 Jun 2009 23:29:22 -0600
On Thu, Jun 11, 2009 at 8:58 PM, David Manura<firstname.lastname@example.org> wrote:
> On Thu, Jun 11, 2009 at 12:45 PM, Michael Newberry wrote:
>> it would be nice to have more detailed compiler messages.
>> For example, considering assignment instead of a test:
>> a = 1
>> if a = 1 then foo end
>> Error: Loading Module 'Script Document1': :2: `then' expected near `='
> The error does make sense in a way. "a" forms a complete expression.
> "if <exp>" should be followed by "then".
> But you are correct in that the problem almost certainly lies with an
> incorrect expression rather than the "then". Here's a patch:
> --- lua-5.1.4/src/lparser.c
> +++ lua-5.1.4-better-errors/src/lparser.c
> @@ -1132,6 +1132,8 @@
> int condexit;
> luaX_next(ls); /* skip IF or ELSEIF */
> condexit = cond(ls);
> + if (ls->t.token == '=')
> + error_expected(ls, TK_EQ);
> checknext(ls, TK_THEN);
> block(ls); /* `then' part */
> return condexit;
> if a = 1 then print() end
> --> stdin:1: '==' expected near '='
I don't agree with this because it implies that Lua only expects the
'==' token after 'a'. I think that could be more confusing.
"Let all men know thee, but no man know thee thoroughly: Men freely
ford that see the shallows."
- Benjamin Franklin