Rename ExtensionTree -> ExtensionMap

This commit is contained in:
Folkert Kevelam 2024-10-08 22:13:30 +02:00
parent b42ba7f340
commit f7aa2cbdc0

View File

@ -1,14 +1,13 @@
local ExtMap = {}
ExtTree = {} function ExtMap:new (o)
function ExtTree:new (o)
o = o or {} o = o or {}
setmetatable(o, self) setmetatable(o, self)
self.__index = self self.__index = self
return o return o
end end
function ExtTree:add_single (in_ext, out_ext) function ExtMap:add_single (in_ext, out_ext)
if self[in_ext] ~= nil then if self[in_ext] ~= nil then
if type(out_ext) == "table" then if type(out_ext) == "table" then
for _, out in ipairs(out_ext) do for _, out in ipairs(out_ext) do
@ -26,7 +25,7 @@ function ExtTree:add_single (in_ext, out_ext)
end end
end end
function ExtTree:add_multiple (in_exts, out_exts) function ExtMap:add (in_exts, out_exts)
if type(in_exts) == "table" then if type(in_exts) == "table" then
for _, in_ext in ipairs(in_exts) do for _, in_ext in ipairs(in_exts) do
self:add_single( in_ext, out_exts) self:add_single( in_ext, out_exts)
@ -44,7 +43,7 @@ function ExtTree:add_multiple (in_exts, out_exts)
end end
end end
function ExtTree:print () function ExtMap:print ()
base = "%s -> " base = "%s -> "
for I in pairs(self) do for I in pairs(self) do
local in_map = string.format(base, I) local in_map = string.format(base, I)
@ -55,12 +54,4 @@ function ExtTree:print ()
end end
end end
p1 = ExtTree:new(nil) return ExtMap
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()