blob: 921f971eb2eed45f42a2c1c532e3a9c1d8bbe649 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
module(...,package.seeall)
function makeTag(s)
return "<"..s.."[^>]*>"
end
function matchTag(tg)
return makeTag(tg)
end
function matchDescendand(a,b)
return makeTag(a)..makeTag(b)
end
function matchChild(a,b)
return makeTag(a)..".*"..makeTag(b)
end
function matchSibling(a,b)
return makeTag(a .. "[^>]*".."@%("..b.."[^>]*%)")
end
function matchClass(tg,class)
return makeTag(tg.."[^>]*class=[|]*[^>]*|"..class.."[^>]*|")
end
matcher = {}
function matcher.new()
local self = {}
local selectors={}
function self:addSelector(sel,val)
selectors[sel.."$"] = val
end
function self:testPath(path,fn)
for k, v in pairs(selectors) do
if path:match(k) then
fn(v)
end
end
end
return self
end
|