lite-xl/data/core/syntax.lua

31 lines
571 B
Lua
Raw Normal View History

local common = require "core.common"
2019-12-28 12:16:32 +01:00
local syntax = {}
2019-12-28 12:16:32 +01:00
syntax.items = {}
2021-12-02 22:34:49 +01:00
local plain_text_syntax = { name = "Plain Text", patterns = {}, symbols = {} }
2019-12-28 12:16:32 +01:00
function syntax.add(t)
table.insert(syntax.items, t)
end
local function find(string, field)
2019-12-28 12:16:32 +01:00
for i = #syntax.items, 1, -1 do
local t = syntax.items[i]
if common.match_pattern(string, t[field] or {}) then
2019-12-28 12:16:32 +01:00
return t
end
end
end
function syntax.get(filename, header)
return find(filename, "files")
or (header and find(header, "headers"))
or plain_text_syntax
2019-12-28 12:16:32 +01:00
end
return syntax