fstirlitz / luaparse

A Lua parser written in JavaScript
https://fstirlitz.github.io/luaparse/
MIT License
459 stars 91 forks source link

Reject newlines between an expression and opening parenthesis #55

Closed fstirlitz closed 6 years ago

fstirlitz commented 7 years ago

PUC Lua 5.1 (and LuaJIT without the LUAJIT_ENABLE_LUA52COMPAT option) rejects code in which an expression is followed by a newline and an opening parenthesis. This is to avoid a parsing ambiguity discussed in the Lua 5.2 manual, §3.3.1, which Lua 5.2 and later instead resolve by introducing an optional explicit statement terminator, ;. (One can also use do...end, which also works in Lua 5.1.)

Currently, luaparse accepts such code with Lua 5.2 semantics (that is, interprets it as a function call); in Lua 5.1 mode, which is the default, it should probably be rejected instead.

ghost commented 6 years ago

Okay, monthly-old issue; but I guess luaparse just needs to do something like this after encountering (...

if (options.version !== '5.1')
{
    if ( base_expr_loc_independent_end_lineNumber !== paren_token_loc_independent_start_lineNumber) /* report error */
}

Can't clone the repo right now bcuz it's over 30MB, but I think this evolves extending the Marker class.

fstirlitz commented 6 years ago

Fixed in fa257d08c9ae9fd4281930525f77c50440c6e802.