Open mpeterv opened 10 years ago
test.lua:
x = function(y) print(y) end (function() end)()
Standard Lua interprets this block as two separate statements, and executing it prints nothing. However, metalua-parser considers it one chain call:
case.lua:
local parser = require "metalua.compiler".new() pprint(inspect(parser:srcfile_to_ast("test.lua")))
{ { { { -- `Id "x" "x", tag = "Id" } }, { { { { { { -- `Id "y" "y", tag = "Id" } }, { { { -- `Id "print" "print", tag = "Id" }, { -- `Id "y" "y", tag = "Id" }, tag = "Call" } }, tag = "Function" }, { {}, {}, tag = "Function" }, tag = "Call" }, tag = "Call" } }, tag = "Set" }, source = "@test.lua" }
... which is equivalent to
x = (function(y) print(y) end)(function() end)()
Expected AST is
{ { { { -- `Id "x" "x", tag = "Id" } }, { { { { -- `Id "y" "y", tag = "Id" } }, { { { -- `Id "print" "print", tag = "Id" }, { -- `Id "y" "y", tag = "Id" }, tag = "Call" } }, tag = "Function" } }, tag = "Set" }, { { { {}, {}, tag = "Function" }, tag = "Paren" }, tag = "Call" }, source = "@test.lua" }
... which can be currently produced by adding a semicolon:
x = function(y) print(y) end; (function() end)()
Observed with metalua-parser 0.7.3-2
test.lua:
Standard Lua interprets this block as two separate statements, and executing it prints nothing. However, metalua-parser considers it one chain call:
case.lua:
... which is equivalent to
Expected AST is
... which can be currently produced by adding a semicolon:
Observed with metalua-parser 0.7.3-2