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
6 changes: 5 additions & 1 deletion src/model/lang/lua/parser.lua
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,11 @@ return function(lib)
--- @param code str
--- @return SyntaxColoring
local highlighter = function(code)
return syntax_hl(tokenize(code))
local ok, tokens = pcall(tokenize, code)
if not ok then
return SyntaxColoring()
end
return syntax_hl(tokens)
end

--- @param text string[]
Expand Down
7 changes: 7 additions & 0 deletions tests/interpreter/parser_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,11 @@ describe('highlight #parser', function()
end
end)
end

it('does not propagate lexer errors', function()
local invalid = 'local s = "\\999"'
local ok, hl = pcall(parser.highlighter, invalid)
assert.is_true(ok)
assert.are_equal('table', type(hl))
end)
end)
Loading