This throws a syntax error in PICO-8, but is valid Lua.
x = 4 y = 1 if (x == 1 and y == 1) or x == 2 or x == 3 or x == 4 then print('yo') end |
As far as I can tell, the parser seems to not like the linebreak in the series of ORs, if the first group has parentheses around it.
btw this is a contrived example just to demonstrate the syntax ;) but I actually did run into this bug in real code
It's because of the shorthand single-line if, which differentiates itself from multi-line by having parens around the condition and then having no 'then' keyword. The two following fragments are effectively identical:
if (cond) code() if cond then code() end |
Your code is unintentionally equivalent to this longhand version:
if x == 1 and y == 1 [b]then[/b] or x == 2 or x == 3 or x == 4) then print('yo') end |
Which is obviously not syntactically whole.
You can add parens around the whole condition, which do not cost performance but do cost one token, and it will parse correctly:
if ((x == 1 and y == 1) or x == 2 or x == 3 or x == 4) then print('yo') end |
I guess zep could take note of whether or not the next token after the closing paren is a binary operator and then cancel the single-line-if parsing, but that's his call, not mine. :)
Please consider the following valid Lua code as well; it does not have a binary operator but fails in PICO-8 too:
function f() return true end if (f) (x) then print("lol") end |
[Please log in to post a comment]