Module:User:Theknightwho/lua-uca/collation

Hello, you have come here looking for the meaning of the word Module:User:Theknightwho/lua-uca/collation. In DICTIOUS you will not only get to know all the dictionary meanings for the word Module:User:Theknightwho/lua-uca/collation, but we will also tell you about its etymology, its characteristics and you will know how to say Module:User:Theknightwho/lua-uca/collation in singular and plural. Everything you need to know about the word Module:User:Theknightwho/lua-uca/collation you have here. The definition of the word Module:User:Theknightwho/lua-uca/collation will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofModule:User:Theknightwho/lua-uca/collation, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.


local collation = {}
collation.__index = collation

function collation.new()
	local self = setmetatable({}, collation)
	self.keys = {}
	return self
end

local function unhex(num)
	return tonumber(num, 16)
end

local function get_elements(line)
	local key, elements = {},{}
	local key_part, elements_part = line:match("^%s*(+);(+)")
	if not key_part then return nil end
	for k in key_part:gmatch("(+)") do key = unhex(k) end
	for typ, primary, secondary, tertiary, quartery	in line:gmatch("%?)(+)%.(+)%.(+)%.?(*)") do
		table.insert(elements,{ type = typ, unhex(primary), unhex(secondary), unhex(tertiary), unhex(quartery) })
	end
	return key, elements
end

-- it is necessary to process the key and create a tree
function collation:update_keys(key, elements)
	local keys = self.keys
	local function add_to_tree(tbl, current_pos)
		local tbl = tbl or {}
		local current_key = key
		local el =	tbl or {}
		if current_pos < #key then
			el.children = add_to_tree(el.children, current_pos + 1)
		elseif current_pos == #key then
			el.value = elements
		end
		tbl = el
		return tbl
	end
	keys = add_to_tree(keys, 1)
end

function collation:load_ducet(content)
	for line in content:gmatch("(+)") do
		-- ignore comments
		if line:match("^%s*#") then
		-- ignore version
		elseif line:match("^%s*@version") then
		-- Todo: process implicits
		elseif line:match("@implicitweights") then
		else
			local key, elements = get_elements(line)
			self:update_keys(key, elements)
		end
	end
end

return collation