From 0938f8424bf2a08f4381cc1fc244ca5e5be770cf Mon Sep 17 00:00:00 2001 From: "Vadim A. Misbakh-Soloviov" Date: Thu, 3 Sep 2015 19:43:21 +0600 Subject: [PATCH] Making parser to work with Lua5.1 (goto calls replaced with repeat-until-true loop) Signed-off-by: Vadim A. Misbakh-Soloviov --- htmlparser-scm-0.rockspec | 2 +- src/htmlparser/ElementNode.lua | 28 +++++++++++++++++----------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/htmlparser-scm-0.rockspec b/htmlparser-scm-0.rockspec index 2718288..8815b05 100644 --- a/htmlparser-scm-0.rockspec +++ b/htmlparser-scm-0.rockspec @@ -13,7 +13,7 @@ description = { license = "LGPL+" } dependencies = { - "lua >= 5.2" + "lua >= 5.1" } build = { type = "builtin", diff --git a/src/htmlparser/ElementNode.lua b/src/htmlparser/ElementNode.lua index 5235a4c..de21937 100644 --- a/src/htmlparser/ElementNode.lua +++ b/src/htmlparser/ElementNode.lua @@ -212,7 +212,8 @@ local function select(self, s) local subjects, resultset, childrenonly = Set:new({self}) for part in string.gmatch(s, "%S+") do - if part == ">" then childrenonly = true goto nextpart end + repeat + if part == ">" then childrenonly = true --[[goto nextpart]] break end resultset = Set:new() for subject in pairs(subjects) do local star = subject.deepernodes @@ -220,43 +221,48 @@ local function select(self, s) resultset = resultset + star end childrenonly = false - if part == "*" then goto nextpart end + if part == "*" then --[[goto nextpart]] break end local excludes, filter = Set:new() local start, pos = 0, 0 while true do - local switch, type, name, eq, quote - start, pos, switch, type, name, eq, quote = string.find(part, + local switch, stype, name, eq, quote + start, pos, switch, stype, name, eq, quote = string.find(part, "(%(?%)?)" .. -- switch = a possible ( or ) switching the filter on or off - "([:%[#.]?)" .. -- type = a possible :, [, #, or . + "([:%[#.]?)" .. -- stype = a possible :, [, #, or . "([%w-_\\]+)" .. -- name = 1 or more alfanumeric chars (+ hyphen, reverse slash and uderscore) "([|%*~%$!%^]?=?)" .. -- eq = a possible |=, *=, ~=, $=, !=, ^=, or = "(['\"]?)", -- quote = a ' or " delimiting a possible attribute value pos + 1 ) if not name then break end - if ":" == type then + repeat + if ":" == stype then filter = name - goto nextname + --[[goto nextname]] break end if ")" == switch then filter = nil end - if "[" == type and "" ~= quote then + if "[" == stype and "" ~= quote then local value start, pos, value = string.find(part, "(%b" .. quote .. quote .. ")]", pos) name = name .. eq .. value end - local matched = match(type, name) + local matched = match(stype, name) if filter == "not" then excludes = excludes + matched else resultset = resultset * matched end - ::nextname:: + --::nextname:: + break + until true end resultset = resultset - excludes subjects = Set:new(resultset) - ::nextpart:: + --::nextpart:: +break +until true end resultset = resultset:tolist() table.sort(resultset, function (a, b) return a.index < b.index end)