lua-users home
lua-l archive

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


If the statement terminator was mandatory, then it would clearly be a block
because it's at the start of the statement. But really, I was not asking
about freestanding blocks, but about if <condition> then <statements> end
being sugared as if <condition> { statements } (same for while, for,
function, etc). I believe this does have quite a context right?

It's still ambiguous. "if(a) { b = 1 }" is likewise either a
brace-delineated if statement, or a table constructor in an
unterminated if statement.

I'm not sure I'm following you here. The above looks like a syntax error, not like any valid Lua code. See what the interpreter has to say:

if(a) { b = 1 }
error: `then' expected;
 last token read: `{' at line 1 in string "if(a) { b = 1 }"

So, it seems to me that the parser is aware of where the condition ends.

Another thing would be if you remove the round braces:

if a { b = 1 } then print(1) else print(2) end

If "a" is a function that returns true, 1 is printed, otherwise 2 is printed.

So, I'm lead to conclusion that if you have round braces around if's condition you can pretty well have curly braces around its block without a problem. What do you think?

Thanks,
Alen