Taddeus Kroes 10 年之前
父节点
当前提交
b54ca4478e
共有 2 个文件被更改,包括 5 次插入9 次删除
  1. 1 3
      lexer.mll
  2. 4 6
      selector.ml

+ 1 - 3
lexer.mll

@@ -120,9 +120,7 @@ rule token = parse
     let a = if a = "" then 1 else int_of_string a in
     let b = match b with None -> 0 | Some n -> int_of_string n in
     let apply_sign n = function Some '-' -> -n | _ -> n in
-    let a = apply_sign a a_sign in
-    let b = apply_sign b b_sign in
-    FORMULA (a, b)
+    FORMULA (apply_sign a a_sign, apply_sign b b_sign)
   }
 
   | O N L Y             { ONLY }

+ 4 - 6
selector.ml

@@ -29,10 +29,9 @@ let rec specificity =
 
 let precedes (a, b, c, d) (e, f, g, h) =
   let rec loop = function
-    | []                -> true
-    | 0 :: tl           -> loop tl
-    | n :: _ when n > 0 -> true
-    | _                 -> false
+    | 0 :: tl                -> loop tl
+    | [] | n :: _ when n > 0 -> true
+    | _                      -> false
   in
   loop [a - e; b - f; c - g; d - h]
 
@@ -64,8 +63,7 @@ let can_match_same selector1 selector2 =
   in
   let rec intersect l = function
     | [] -> false
-    | hd :: _ when List.mem hd l -> true
-    | _ :: tl -> intersect l tl
+    | hd :: tl -> List.mem hd l || intersect l tl
   in
   let elem1, classes1, ids1, pseudos1, attrs1 = unfold selector1 in
   let elem2, classes2, ids2, pseudos2, attrs2 = unfold selector2 in