From afc410c531234f5830714baec28cc3b55620ea0e Mon Sep 17 00:00:00 2001 From: Folkert Kevelam Date: Sun, 29 Sep 2024 17:54:42 +0200 Subject: [PATCH] Initial commit --- plugin/ExtensionTree.lua | 66 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 plugin/ExtensionTree.lua diff --git a/plugin/ExtensionTree.lua b/plugin/ExtensionTree.lua new file mode 100644 index 0000000..2051cb4 --- /dev/null +++ b/plugin/ExtensionTree.lua @@ -0,0 +1,66 @@ + +ExtTree = {} + +function ExtTree:new (o) + o = o or {} + setmetatable(o, self) + self.__index = self + return o +end + +function ExtTree:add_single (in_ext, out_ext) + if self[in_ext] ~= nil then + if type(out_ext) == "table" then + for _, out in ipairs(out_ext) do + table.insert(self[in_ext], out) + end + else + table.insert(self[in_ext], out_ext) + end + else + if type(out_ext) == "table" then + self[in_ext] = out_ext + else + self[in_ext] = {out_ext} + end + end +end + +function ExtTree:add_multiple (in_exts, out_exts) + if type(in_exts) == "table" then + for _, in_ext in ipairs(in_exts) do + self:add_single( in_ext, out_exts) + end + else + self:add_single( in_exts, out_exts ) + end + + if type(out_exts) == "table" then + for _, out_ext in ipairs(out_exts) do + self:add_single( out_ext, in_exts) + end + else + self:add_single( out_exts, in_exts ) + end +end + +function ExtTree:print () + base = "%s -> " + for I in pairs(self) do + local in_map = string.format(base, I) + for _, O in ipairs(self[I]) do + in_map = in_map .. O .. "," + end + print(in_map) + end +end + +p1 = ExtTree:new(nil) + +p1:add_multiple("h", {"c", "cpp", "cxx", "cc", "CC"}) +p1:add_multiple("H", {"C", "CPP", "CXX", "CC"}) +p1:add_multiple("hpp", {"cpp", "c"}) +p1:add_multiple("HPP", {"CPP", "C"}) +p1:add_multiple("ads", "adb") + +p1:print()