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:
Vadim A. Misbakh-Soloviov 2015-09-03 19:43:21 +06:00
parent 2a876887d2
commit 0938f8424b
No known key found for this signature in database
GPG Key ID: 26503D349B3B334B
2 changed files with 18 additions and 12 deletions

View File

@ -13,7 +13,7 @@ description = {
license = "LGPL+"
}
dependencies = {
"lua >= 5.2"
"lua >= 5.1"
}
build = {
type = "builtin",

View File

@ -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)