diff --git a/data/core/common.lua b/data/core/common.lua index fce50a1e..d83a7afc 100644 --- a/data/core/common.lua +++ b/data/core/common.lua @@ -102,6 +102,18 @@ function common.path_suggest(text) end +function common.matches_pattern(text, pattern, ...) + if type(pattern) == "string" then + return text:find(pattern, ...) + end + for _, p in ipairs(pattern) do + local s, e = common.matches_pattern(text, p, ...) + if s then return s, e end + end + return false +end + + function common.draw_text(font, color, text, align, x,y,w,h) local tw, th = font:get_width(text), font:get_height(text) if align == "center" then diff --git a/data/core/syntax.lua b/data/core/syntax.lua index 08db473c..ddc1b2f2 100644 --- a/data/core/syntax.lua +++ b/data/core/syntax.lua @@ -1,21 +1,11 @@ -local syntax = {} +local common = require "core.common" +local syntax = {} syntax.items = {} local plain_text_syntax = { patterns = {}, symbols = {} } -local function matches_pattern(text, pattern) - if type(pattern) == "string" then - return text:find(pattern) - end - for _, p in ipairs(pattern) do - if matches_pattern(text, p) then return true end - end - return false -end - - function syntax.add(t) table.insert(syntax.items, t) end @@ -24,7 +14,7 @@ end function syntax.get(filename) for i = #syntax.items, 1, -1 do local t = syntax.items[i] - if matches_pattern(filename, t.files) then + if common.matches_pattern(filename, t.files) then return t end end