Parse :nth-child() using an+b parsing from rust-cssparser.

This commit is contained in:
Simon Sapin 2013-08-09 16:21:28 +01:00
parent 1195759e79
commit bde1fcc7e9

View file

@ -52,10 +52,7 @@ pub enum SimpleSelector {
Empty, Empty,
Root, Root,
Lang(~str), Lang(~str),
// NthChild(u32, u32), NthChild(i32, i32),
// NthLastChild(u32, u32),
// NthOfType(u32, u32),
// NthLastOfType(u32, u32),
Negation(~[SimpleSelector]), Negation(~[SimpleSelector]),
// ... // ...
} }
@ -168,13 +165,13 @@ fn compute_specificity(mut selector: &CompoundSelector,
for simple_selector in simple_selectors.iter() { for simple_selector in simple_selectors.iter() {
match simple_selector { match simple_selector {
&LocalNameSelector{_} => specificity.element_selectors += 1, &LocalNameSelector{_} => specificity.element_selectors += 1,
&IDSelector(_) => specificity.id_selectors += 1, &IDSelector(*) => specificity.id_selectors += 1,
&ClassSelector(_) &ClassSelector(*)
| &AttrExists(_) | &AttrEqual(_, _) | &AttrIncludes(_, _) | &AttrDashMatch(_, _) | &AttrExists(*) | &AttrEqual(*) | &AttrIncludes(*) | &AttrDashMatch(*)
| &AttrPrefixMatch(_, _) | &AttrSubstringMatch(_, _) | &AttrSuffixMatch(_, _) | &AttrPrefixMatch(*) | &AttrSubstringMatch(*) | &AttrSuffixMatch(*)
| &Empty | &Root | &Lang(_) | &Empty | &Root | &Lang(*) | &NthChild(*)
=> specificity.class_like_selectors += 1, => specificity.class_like_selectors += 1,
&NamespaceSelector(_) => (), &NamespaceSelector(*) => (),
&Negation(ref negated) &Negation(ref negated)
=> simple_selectors_specificity(negated.as_slice(), specificity), => simple_selectors_specificity(negated.as_slice(), specificity),
} }
@ -414,6 +411,7 @@ fn parse_functional_pseudo_class(name: ~str, arguments: ~[ComponentValue],
let lower_name: &str = to_ascii_lower(name); let lower_name: &str = to_ascii_lower(name);
match lower_name { match lower_name {
"lang" => parse_lang(arguments), "lang" => parse_lang(arguments),
"nth-child" => parse_nth(arguments).map(|&(a, b)| NthChild(a, b)),
"not" => if inside_negation { None } else { parse_negation(arguments, namespaces) }, "not" => if inside_negation { None } else { parse_negation(arguments, namespaces) },
_ => None _ => None
} }