lua-users home
lua-l archive

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

"Juris Kalnins" <> writes:

>> If you want to make a statement about the function of \n in the Lua
>> language, please write it into a complete file you feed into Lua (and
>> obviously not via input redirection).
> From lparse.c:609
> static void funcargs (LexState *ls, expdesc *f) {
>   FuncState *fs = ls->fs;
>   expdesc args;
>   int base, nparams;
>   int line = ls->linenumber;
>   switch (ls->t.token) {
>     case '(': {  /* funcargs -> `(' [ explist1 ] `)' */
>       if (line != ls->lastline)
>         luaX_syntaxerror(ls,"ambiguous syntax (function call x new
> statement)");
> .....
> That if checks and fails if there is newline before '(' where function
> arguments are expected
> Example file:
> ======8<==========8<=========
> print
> (1)
> ======8<==========8<=========

The Lua reference manual 5.1 (printed version) has a (rather
self-contradictory) statement

    As an exception to the free-format syntax of Lua, you cannot put a
    line break before the `(' in a function call.  This restriction
    avoids some ambiguities in the language.  If you write

       a = f

    Lua would see that as a single statement, a=f(g).x(a).  So, if you
    want two statements, you must add a semi-colon between them.  If you
    actually want to call f, you must remove the line break before (g).

While this more or less tells us that Lua is indeed a mess, it does not
tell us what the above input will give.  "Lua would see that" does not
suggest that Lua would actually throw an error.  Indeed, "Lua would see
that" suggests that _if_ you want to have Lua see that as a single
statement, writing it like that should work, on contradiction to the
last sentence of the quote (which turns out more correct).

David Kastrup