2020-05-07 11:27:37 +02:00
|
|
|
local common = require "core.common"
|
2019-12-28 12:16:32 +01:00
|
|
|
|
2020-05-07 11:27:37 +02:00
|
|
|
local syntax = {}
|
2019-12-28 12:16:32 +01:00
|
|
|
syntax.items = {}
|
|
|
|
|
|
|
|
local plain_text_syntax = { patterns = {}, symbols = {} }
|
|
|
|
|
|
|
|
|
|
|
|
function syntax.add(t)
|
|
|
|
table.insert(syntax.items, t)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2020-06-08 10:44:51 +02:00
|
|
|
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]
|
2020-06-08 10:44:51 +02:00
|
|
|
if common.match_pattern(string, t[field] or {}) then
|
2019-12-28 12:16:32 +01:00
|
|
|
return t
|
|
|
|
end
|
|
|
|
end
|
2020-06-08 10:44:51 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function syntax.get(filename, header)
|
|
|
|
return find(filename, "files")
|
2021-10-25 14:06:07 +02:00
|
|
|
or (header and find(header, "headers"))
|
2020-06-08 10:44:51 +02:00
|
|
|
or plain_text_syntax
|
2019-12-28 12:16:32 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
return syntax
|