css: implement ~, + and > combinators

This commit is contained in:
Pierre Tachoire
2024-03-25 17:09:11 +01:00
parent 565d612abb
commit dcc7e51556

View File

@@ -264,7 +264,34 @@ pub const Selector = union(enum) {
return false; return false;
}, },
else => return Error.UnknownCombinedCombinator, .child => {
const p = try n.parent();
if (p == null) return false;
return try v.second.match(n) and try v.first.match(p.?);
},
.next_sibling => {
if (!try v.second.match(n)) return false;
var c = try n.prevSibling();
while (c != null) {
if (!c.?.isElement()) { // TODO must check text node or comment node instead.
c = try c.?.prevSibling();
continue;
}
return try v.first.match(c.?);
}
return false;
},
.subsequent_sibling => {
if (!try v.second.match(n)) return false;
var c = try n.prevSibling();
while (c != null) {
if (try v.first.match(c.?)) return true;
c = try c.?.prevSibling();
}
return false;
},
}; };
}, },
.attribute => |v| { .attribute => |v| {