Skip to content

Commit

Permalink
improved line break heuristics
Browse files Browse the repository at this point in the history
Closes #740.
  • Loading branch information
hishamhm committed Jun 10, 2024
1 parent d8ad610 commit 97090fa
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
31 changes: 31 additions & 0 deletions spec/code_gen/linebreak_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
local util = require("spec.util")

describe("improved line break heuristics", function()
it("a line starting with ( is not a function call for the previous line", util.gen([[
local record Obj
end
function Obj:meth1()
print("hehe")
end
local t = setmetatable({}, { __index = Obj })
do
(t as Obj):meth1()
(t as Obj):meth1()
end
]], [[
local Obj = {}
function Obj:meth1()
print("hehe")
end
local t = setmetatable({}, { __index = Obj })
do
(t):meth1();
(t):meth1()
end
]]))
end)
6 changes: 6 additions & 0 deletions tl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2973,6 +2973,12 @@ do

e1 = { f = ps.filename, y = tkop.y, x = tkop.x, kind = "op", op = op, e1 = e1, e2 = key }
elseif tkop.tk == "(" then
local prev_tk = ps.tokens[i - 1]
if tkop.y > prev_tk.y then
table.insert(ps.tokens, i, { y = prev_tk.y, x = prev_tk.x + #prev_tk.tk, tk = ";", kind = ";" })
break
end

local op = new_operator(tkop, 2, "@funcall")

local prev_i = i
Expand Down
6 changes: 6 additions & 0 deletions tl.tl
Original file line number Diff line number Diff line change
Expand Up @@ -2973,6 +2973,12 @@ do

e1 = { f = ps.filename, y = tkop.y, x = tkop.x, kind = "op", op = op, e1 = e1, e2 = key }
elseif tkop.tk == "(" then
local prev_tk = ps.tokens[i - 1]
if tkop.y > prev_tk.y then
table.insert(ps.tokens, i, { y = prev_tk.y, x = prev_tk.x + #prev_tk.tk, tk = ";", kind = ";" })
break
end

local op: Operator = new_operator(tkop, 2, "@funcall")

local prev_i = i
Expand Down

0 comments on commit 97090fa

Please sign in to comment.