local function process_line(line, language) -- Skip empty lines and comments if string.find(line, "^%s*$") or string.find(line, "^%s*%-%-") then return end -- Process line with meta information local _, _, languages = string.find(line, "^Language%s*%(([^%)]+)%)") if languages then local lang_names = {} for name in string.gmatch(languages, "\"(%a+)\"") do lang_names[#lang_names + 1] = name end if #lang_names > 0 then language.lang_names = lang_names end return end local _, _, inherit = string.find(line, "^Inherit%s*%(\"(%a+)\"%s*%)") if inherit then language.inherit = inherit return end -- Process normal strings local _, _, str_name, text = string.find(line, "^([^=]+)=%s*\"(.*)\"%s*$") if str_name then local _, last, name = string.find(str_name, "^%s*([a-z_]+)") if not last then return nil end local names = {name} local start = last + 1 while true do _, last, name = string.find(str_name, "%.([a-z_]+)", start) if not name then _, last, name = string.find(str_name, "%[(%d+)%]", start) end if name then names[#names + 1] = name start = last + 1 else break end end if string.find(str_name, "%s*$", start) then language.strings[#language.strings + 1] = {name = names, text = text} return end end end function loadLanguage(fname) language = {strings = {}} for line in io.lines(fname) do process_line(line, language) end return language end