Mon Nov 23 11:33:15 UTC 2009 pix@kepibu.org
* :first-child and :nth-child(n) selectors
hunk ./notes 8
-*** positional selectors
- * [ ] :nth-child
+*** positional selectors [2/12]
+ * [X] :nth-child(n)
+ * [ ] :nth-child(xn+y)
hunk ./notes 12
- * [ ] :first-child
+ * [X] :first-child
hunk ./notes 21
-*** attribute selectors
+*** attribute selectors [0/7]
hunk ./selectors.lisp 36
+(defclass nth-child-selector (simple-selector) ())
+
+(defmethod print-object ((selector universal-selector) stream)
+ (format stream "#<universal-selector>"))
hunk ./selectors.lisp 51
- (#T(regexp$ "[ ]*[>][ ]*" ()) (list (make-instance 'child-combinator :matcher (parse-selector &rest))))
- (#T(regexp$ "[ ]+" ()) (list (make-instance 'descendant-combinator :matcher (parse-selector &rest))))
- ;; simple selector
- (#T(regexp$ "[#](\\w+)" (?id)) (cons (make-instance 'id-selector :arg id) (parse-selector &rest)))
- (#T(regexp$ "[\\.](\\w+)" (?class)) (cons (make-instance 'class-selector :arg class) (parse-selector &rest)))
- (#T(regexp$ "(\\w+)" (?type)) (cons (make-instance 'type-selector :arg type) (parse-selector &rest)))
- (#T(regexp$ "\\*" ()) (cons (make-instance 'universal-selector) (parse-selector &rest)))))
+ (#T(regexp$ "[ ]*[>][ ]*" ())
+ (list (make-instance 'child-combinator :matcher (parse-selector &rest))))
+ (#T(regexp$ "[ ]+" ())
+ (list (make-instance 'descendant-combinator :matcher (parse-selector &rest))))
+ ;; simple selectors
+ (#T(regexp$ ":nth-child\\([ ]*([0-9]+)[ ]*\\)" (?n))
+ (cons (make-instance 'nth-child-selector :arg (parse-integer n)) (parse-selector &rest)))
+ (#T(regexp$ ":first-child" ())
+ (cons (make-instance 'nth-child-selector :arg 1) (parse-selector &rest)))
+ (#T(regexp$ "[#](\\w+)" (?id))
+ (cons (make-instance 'id-selector :arg id) (parse-selector &rest)))
+ (#T(regexp$ "[\\.](\\w+)" (?class))
+ (cons (make-instance 'class-selector :arg class) (parse-selector &rest)))
+ (#T(regexp$ "(\\w+)" (?type))
+ (cons (make-instance 'type-selector :arg type) (parse-selector &rest)))
+ (#T(regexp$ "\\*" ())
+ (cons (make-instance 'universal-selector) (parse-selector &rest)))))
hunk ./selectors.lisp 87
+(defmethod element-matches-p (element (selector nth-child-selector))
+ (alexandria:when-let* ((parent (element-parent element))
+ (pos (position element (element-children parent) :test #'eq)))
+ (= (selector-arg selector) (1+ pos))))
+
hunk ./tests.lisp 50
+(match (#T(html (:model dom)
+ ("div:first-child" . ?div)
+ ("i:nth-child(1)" . ?i))
+ "<div>I do <i>not</i> <i>like</i> cheese.</div><div><span>I like <i>cheese</i>.</span></div>")
+ (values div i))
+