Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improved line break heuristics #748

Merged
merged 1 commit into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading