diff --git a/ElementNode.lua b/ElementNode.lua index fdeebc4..fa08ad6 100644 --- a/ElementNode.lua +++ b/ElementNode.lua @@ -103,12 +103,22 @@ local function select(self, s) resultset = resultset + init end if part == "*" then goto nextpart end - for t, w in string.gmatch(part, "([%[#%.]?)([^%[%]#%.]+)") do - if t == "" then resultset = resultset * self.deeperelements[w] - elseif t == "[" then resultset = resultset * self.deeperattributes[w] - elseif t == "#" then resultset = resultset * self.deeperids[w] - elseif t == "." then resultset = resultset * self.deeperclasses[w] + local match, filter + for t, w in string.gmatch(part, "([:%[#.]?)([^:%(%[#.%]%)]+)%]?%)?") do + -- TODO tidy up + if t == ":" then filter = w goto nextw end + if t == "" then match = self.deeperelements[w] + elseif t == "[" then match = self.deeperattributes[w] + elseif t == "#" then match = self.deeperids[w] + elseif t == "." then match = self.deeperclasses[w] end + if filter == "not" then + resultset = resultset - match + else + resultset = resultset * match + end + filter = nil + ::nextw:: end subjects = Set:new(resultset) ::nextpart:: diff --git a/test.lua b/test.lua index 0d42f4a..318b34a 100644 --- a/test.lua +++ b/test.lua @@ -113,4 +113,14 @@ local function printscope(node, table, level) end for node,table in pairs(scopes) do printscope(node, table) +end + +local sel = root("[itemscope]:not([itemprop])") +for i,v in ipairs(sel.nodes) do + print(v.name) +end + +local sel = root("[href]:not(a)") +for i,v in ipairs(sel.nodes) do + print(v.name) end \ No newline at end of file