mirror of
https://github.com/msva/lua-htmlparser.git
synced 2024-11-27 12:44:22 +00:00
Making parser to work with Lua5.1 (goto calls replaced with repeat-until-true loop)
Signed-off-by: Vadim A. Misbakh-Soloviov <git@mva.name>
This commit is contained in:
parent
2a876887d2
commit
0938f8424b
@ -13,7 +13,7 @@ description = {
|
|||||||
license = "LGPL+"
|
license = "LGPL+"
|
||||||
}
|
}
|
||||||
dependencies = {
|
dependencies = {
|
||||||
"lua >= 5.2"
|
"lua >= 5.1"
|
||||||
}
|
}
|
||||||
build = {
|
build = {
|
||||||
type = "builtin",
|
type = "builtin",
|
||||||
|
@ -212,7 +212,8 @@ local function select(self, s)
|
|||||||
|
|
||||||
local subjects, resultset, childrenonly = Set:new({self})
|
local subjects, resultset, childrenonly = Set:new({self})
|
||||||
for part in string.gmatch(s, "%S+") do
|
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()
|
resultset = Set:new()
|
||||||
for subject in pairs(subjects) do
|
for subject in pairs(subjects) do
|
||||||
local star = subject.deepernodes
|
local star = subject.deepernodes
|
||||||
@ -220,43 +221,48 @@ local function select(self, s)
|
|||||||
resultset = resultset + star
|
resultset = resultset + star
|
||||||
end
|
end
|
||||||
childrenonly = false
|
childrenonly = false
|
||||||
if part == "*" then goto nextpart end
|
if part == "*" then --[[goto nextpart]] break end
|
||||||
local excludes, filter = Set:new()
|
local excludes, filter = Set:new()
|
||||||
local start, pos = 0, 0
|
local start, pos = 0, 0
|
||||||
while true do
|
while true do
|
||||||
local switch, type, name, eq, quote
|
local switch, stype, name, eq, quote
|
||||||
start, pos, switch, type, name, eq, quote = string.find(part,
|
start, pos, switch, stype, name, eq, quote = string.find(part,
|
||||||
"(%(?%)?)" .. -- switch = a possible ( or ) switching the filter on or off
|
"(%(?%)?)" .. -- 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)
|
"([%w-_\\]+)" .. -- name = 1 or more alfanumeric chars (+ hyphen, reverse slash and uderscore)
|
||||||
"([|%*~%$!%^]?=?)" .. -- eq = a possible |=, *=, ~=, $=, !=, ^=, or =
|
"([|%*~%$!%^]?=?)" .. -- eq = a possible |=, *=, ~=, $=, !=, ^=, or =
|
||||||
"(['\"]?)", -- quote = a ' or " delimiting a possible attribute value
|
"(['\"]?)", -- quote = a ' or " delimiting a possible attribute value
|
||||||
pos + 1
|
pos + 1
|
||||||
)
|
)
|
||||||
if not name then break end
|
if not name then break end
|
||||||
if ":" == type then
|
repeat
|
||||||
|
if ":" == stype then
|
||||||
filter = name
|
filter = name
|
||||||
goto nextname
|
--[[goto nextname]] break
|
||||||
end
|
end
|
||||||
if ")" == switch then
|
if ")" == switch then
|
||||||
filter = nil
|
filter = nil
|
||||||
end
|
end
|
||||||
if "[" == type and "" ~= quote then
|
if "[" == stype and "" ~= quote then
|
||||||
local value
|
local value
|
||||||
start, pos, value = string.find(part, "(%b" .. quote .. quote .. ")]", pos)
|
start, pos, value = string.find(part, "(%b" .. quote .. quote .. ")]", pos)
|
||||||
name = name .. eq .. value
|
name = name .. eq .. value
|
||||||
end
|
end
|
||||||
local matched = match(type, name)
|
local matched = match(stype, name)
|
||||||
if filter == "not" then
|
if filter == "not" then
|
||||||
excludes = excludes + matched
|
excludes = excludes + matched
|
||||||
else
|
else
|
||||||
resultset = resultset * matched
|
resultset = resultset * matched
|
||||||
end
|
end
|
||||||
::nextname::
|
--::nextname::
|
||||||
|
break
|
||||||
|
until true
|
||||||
end
|
end
|
||||||
resultset = resultset - excludes
|
resultset = resultset - excludes
|
||||||
subjects = Set:new(resultset)
|
subjects = Set:new(resultset)
|
||||||
::nextpart::
|
--::nextpart::
|
||||||
|
break
|
||||||
|
until true
|
||||||
end
|
end
|
||||||
resultset = resultset:tolist()
|
resultset = resultset:tolist()
|
||||||
table.sort(resultset, function (a, b) return a.index < b.index end)
|
table.sort(resultset, function (a, b) return a.index < b.index end)
|
||||||
|
Loading…
Reference in New Issue
Block a user