Add sibling and adjacent combinators
Thu Dec 3 00:12:02 UTC 2009 pix@kepibu.org
* Add sibling and adjacent combinators
hunk ./selectors.lisp 54
- #+TODO (#T(regexp$ "[ ]*[~][ ]*" ()) (list (make-instance 'sibling-combinator :matcher (parse-selector &rest))))
- #+TODO (#T(regexp$ "[ ]*[+][ ]*" ()) (list (make-instance 'adjacent-combinator :matcher (parse-selector &rest))))
+ (#T(regexp$ "[ ]*[~][ ]*" ())
+ (list (make-instance 'sibling-combinator :matcher (parse-selector &rest))))
+ (#T(regexp$ "[ ]*[+][ ]*" ())
+ (list (make-instance 'adjacent-combinator :matcher (parse-selector &rest))))
hunk ./selectors.lisp 148
-#+TODO
hunk ./selectors.lisp 149
- ...)
+ (let* ((parent (element-parent element))
+ (siblings (element-children parent))
+ (ourpos (position element siblings :test #'eq)))
+ (and ourpos
+ (> ourpos 0)
+ (element-matches-p (elt siblings (1- ourpos)) (matcher selector)))))
hunk ./selectors.lisp 156
-#+TODO
hunk ./selectors.lisp 157
- ...)
+ (let* ((parent (element-parent element))
+ (siblings (element-children parent))
+ (ourpos (position element siblings :test #'eq)))
+ (and ourpos
+ (> ourpos 0)
+ (find-if (rcurry #'element-matches-p (matcher selector)) siblings :end ourpos))))
hunk ./tests.lisp 62
+(match (#T(html (:model dom)
+ ("b + i" . ?i))
+ "<div>I <b>really</b> <i>like</i> cheese. Do you not <i>dislike</i> cheese?</div>")
+ (values i))
+
+(match (#T(html (:model dom)
+ ("b ~ i" . ?i))
+ "<div>I <i>really</i> <b>like</b> cheese. Do you not <i>dislike</i> cheese?</div>")
+ (values i))
+
+