implicit-element is a better name than root
unify.lisp
Sat Dec 5 07:18:05 UTC 2009 pix@kepibu.org
* implicit-element is a better name than root
Also add a bit of support for sibling combinators when dealing with the
implicit element, and note a problem that crops up when dealing with
selections on a non-root element (should a simple-selector select the
element, or is there an implicit descendant combinator?).
--- old-Oh, Ducks!/unify.lisp 2013-07-07 01:12:16.000000000 +0000
+++ new-Oh, Ducks!/unify.lisp 2013-07-07 01:12:16.000000000 +0000
@@ -18,8 +18,29 @@
(css-selector-template
(unify template document env))
(t
- (let* ((*effective-root* document)
- (val (find-matching-elements css-specifier document)))
+ (let* ((*implicit-element* document)
+ ;; FIXME: this is UGLY!
+ (val (cond
+ ((terminating-implicit-sibling-combinator-p css-specifier)
+ ;; search remaining siblings
+ (find-matching-elements-in-list
+ css-specifier
+ (rest
+ (member document
+ (when-let* ((parent (element-parent document)))
+ (element-children parent))
+ :test #'eq))))
+ ;; search subelements
+;;; FIXME: this assumes if someone passes us a node they want to find
+;;; subelements of that node. In the case of nested matches, that's probably
+;;; true, but it hardly seems fair to assume it. Really we want some sort of
+;;; descendant combinator to be sure, but the general one (#\Space) doesn't
+;;; exactly show up all that well. Somebody might assume " b" was the same as
+;;; "b" and get confused.
+ ((element-parent document)
+ (find-matching-elements-in-list css-specifier (element-children document)))
+ ;; root element includes itself
+ (t (find-matching-elements css-specifier document)))))
(cond
((null val)
(error 'unification-failure