diff --git a/src/model/lang/lua/parser.lua b/src/model/lang/lua/parser.lua index e7839b2c..9f4114ab 100644 --- a/src/model/lang/lua/parser.lua +++ b/src/model/lang/lua/parser.lua @@ -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[] diff --git a/tests/interpreter/parser_spec.lua b/tests/interpreter/parser_spec.lua index 9c48f646..7e3c20ea 100644 --- a/tests/interpreter/parser_spec.lua +++ b/tests/interpreter/parser_spec.lua @@ -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)