Re: Syntax error message from LuaJIT-2.1.0-beta3

  • From: Javier Guerra Giraldez <javier@xxxxxxxxxxx>
  • To: LuaJIT <luajit@xxxxxxxxxxxxx>
  • Date: Sun, 14 May 2017 01:46:45 +0200

On 11 May 2017 at 02:59, DAVID SLATE <dslate1@xxxxxxxxxxx> wrote:

Does this change in behavior represent a bug, or is it just some tightening
up of syntax checking?


remember that while LuaJT follows Lua 5.1 design and semantics, it
"backports" a few features from Lua 5.2 and 5.3, like the goto
statement and labels.

From the 5.1 manual, section 2.4.2 — Blocks: "Explicit blocks are also
sometimes used to add a return or break statement in the middle of
another block (see §2.4.4)."

and at the end of §2.4.4 — Control Structures: "The return and break
statements can only be written as the last statement of a block. If it
is really necessary to return or break in the middle of a block, then
an explicit inner block can be used, as in the idioms 'do return end'
and 'do break end', because now return and break are the last
statements in their (inner) blocks."

but from the 5.2 manual, same section 3.3.4 — Control Structures also
points that "For syntactical reasons, labels in Lua are considered
statements too".

Curiously, the 5.2 manual removes the 'do break end' form, and only
keeps 'do return end', it seems that the requirement for it to be the
last statement in a block was removed.  I didn't remember that.

So it looks like the latest beta is closer to Lua 5.2 respecting
labels syntax (probably as part of issue #228 [1]), but not about
where a break is allowed.

Still, you only need to use the commonly accepted 'do break end' form,
and not necessarily a whole "meaningless test" as you show in your
example.  This only changes how the parser sees it, the emitted
bytecode should be the same as if a bare 'break' was allowed there.

In short, the situation you mention seems to come from the not perfect
fit between 5.1 syntax and 5.2 features.


[1]: https://github.com/LuaJIT/LuaJIT/issues/228

-- 
Javier

Other related posts: