Skip to content
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
27 changes: 27 additions & 0 deletions spec/lang/lexer/comments_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,31 @@ describe("lexer", function()
}, tokens[11].comments)
end)

it("preserves line comment at end of file without trailing newline", function()
local tokens = tl.lex("-- a comment")
assert.same(1, #tokens)
assert.same("$EOF$", tokens[1].tk)
assert.same({
{text = "-- a comment", x = 1, y = 1}
}, tokens[1].comments)
end)

it("preserves empty line comment at end of file without trailing newline", function()
local tokens = tl.lex("--")
assert.same(1, #tokens)
assert.same("$EOF$", tokens[1].tk)
assert.same({
{text = "--", x = 1, y = 1}
}, tokens[1].comments)
end)

it("preserves line comment starting with [ at end of file without trailing newline", function()
local tokens = tl.lex("--[")
assert.same(1, #tokens)
assert.same("$EOF$", tokens[1].tk)
assert.same({
{text = "--[", x = 1, y = 1}
}, tokens[1].comments)
end)

end)
4 changes: 4 additions & 0 deletions teal/lexer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,10 @@ do
end
end

if state == "comment short" or state == "got --" or state == "got --[" then
add_comment(input:sub(ti, #input))
end

table.insert(tokens, { x = x + 1, y = y, tk = "$EOF$", kind = "$EOF$", comments = comments })

return tokens, errs
Expand Down
4 changes: 4 additions & 0 deletions teal/lexer.tl
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,10 @@ do
end
end

if state == "comment short" or state == "got --" or state == "got --[" then
add_comment(input:sub(ti, #input))
end

table.insert(tokens, { x = x + 1, y = y, tk = "$EOF$", kind = "$EOF$", comments = comments })

return tokens, errs
Expand Down
4 changes: 4 additions & 0 deletions tl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13302,6 +13302,10 @@ do
end
end

if state == "comment short" or state == "got --" or state == "got --[" then
add_comment(input:sub(ti, #input))
end

table.insert(tokens, { x = x + 1, y = y, tk = "$EOF$", kind = "$EOF$", comments = comments })

return tokens, errs
Expand Down
Loading