local LexicalHelper = class("LexicalHelper") local slen = string.len local ssub = string.sub local sgsub = string.gsub local sfind = string.find local strim = string.trim local rtrim = string.rtrim local tinsert = table.insert local sgmatch = string.gmatch local _XmlUiNames = { ["dialog"] = true, ["Image"] = true, ["Text"] = true, ["Input"] = true, ["Button"] = true, ["Layout"] = true, ["ScrollView"] = true, ["ListView"] = true, ["RichText"] = true, ["TextAtlas"] = true, ["CircleBar"] = true, ["LoadingBar"] = true, ["CheckBox"] = true } function LexicalHelper:ctor() end function LexicalHelper:tbTransform( tb ) local newtb = {} for i,v in ipairs(tb) do local _,_,key = sfind(v, "(.+)=") local _,_,val = sfind(v, "=(.+)") newtb[key] = strim(val) end return newtb end function LexicalHelper:parseCell(celldata) celldata = celldata.." " local tb = {} for v in sgmatch(celldata, "(.-) (.-)") do tinsert(tb, v) end local js = {} local t = 1 for i,v in ipairs(tb) do local _b, _e = sfind(v, "(%a)=") if _b and _e then js[t] = v t = t + 1 else if js[t-1] then js[t-1] = js[t-1].." "..v end end end return self:tbTransform(js) end function LexicalHelper:GetValidData( type, data ) if not _XmlUiNames[tostring(type)] then SL:Print("Xml Parse ERROR , type: ", tostring(type)) return false end local attrData = sgsub(data, "<(.-) ", "") attrData = sgsub(attrData, "(%s+)=", "=") return self:push_element(type, self:parseCell(attrData)) end function LexicalHelper:ParseDialog(data) data = sgsub(data, "(/%s-)>", ">") data = sgsub(data, "\"", "") data = sgsub(data, "<(%s+)", "<") local node = {} local tWnd = {} local startWnd = false for v in sgmatch(data, "(.-)>") do if v then v = strim(v) local _, _, jType = sfind(v, "<(.-) ") if jType == "dialog" then local _data = self:GetValidData(jType, v) if _data then tinsert(node, 1, _data) end else local _, _, isdialogWnd = sfind(v, " 0) end local xmls = {} local script = "" if source then source = self:ParseNote(source) if root then -- 不带script和dialog的子控件 source = strim(source) return {xmls = self:ParseDialog(source)} end local scriptStr = { sfind(source, "") } local xmlStr = { sfind(source, "") } if _IsNilResult(xmlStr) then local data = xmlStr[3] data = rtrim(data) data = "" xmls = self:ParseDialog(data) if _IsNilResult(scriptStr) then script = scriptStr[3] end else if _IsNilResult(scriptStr) then script = scriptStr[3] else script = source end end end return {script = script, xmls = xmls} end function LexicalHelper:push_element(type, kvmap) return { type = type, attr = kvmap } end return LexicalHelper