Add attribute-present selector
Wed Feb 10 08:28:34 UTC 2010 pix@kepibu.org
* Add attribute-present selector
diff -rN -u old-Oh, Ducks!/notes new-Oh, Ducks!/notes
--- old-Oh, Ducks!/notes 2013-07-24 10:35:24.000000000 +0000
+++ new-Oh, Ducks!/notes 2013-07-24 10:35:24.000000000 +0000
@@ -155,8 +155,8 @@
* [X] :only-child
* [X] :only-of-type
* [X] :empty
-*** attribute selectors [0/7]
- * [ ] attribute-present [att]
+*** attribute selectors [1/7]
+ * [X] attribute-present [att]
* [ ] attribute-equal [att=val]
* [ ] attribute-member [att~=val]
* [ ] attribute-lang [att|=val]
diff -rN -u old-Oh, Ducks!/selectors.lisp new-Oh, Ducks!/selectors.lisp
--- old-Oh, Ducks!/selectors.lisp 2013-07-24 10:35:24.000000000 +0000
+++ new-Oh, Ducks!/selectors.lisp 2013-07-24 10:35:24.000000000 +0000
@@ -42,6 +42,9 @@
(defclass nth-last-of-type-selector (nth-of-type-selector) ())
(defclass empty-selector (simple-selector) ())
+(defclass attribute-selector (simple-selector) ())
+(defclass attribute-present-selector (attribute-selector) ())
+
(defmethod initialize-instance :after ((selector nth-child-selector)
&key (asign "+") a
(bsign "+") b
@@ -103,6 +106,10 @@
(#T(regexp$ (\s+) ())
(list (make-instance 'descendant-combinator :matcher (or (parse-selector &rest) %implicit-element-selector))))
;; simple selectors
+ ;; attribute selectors
+ (#T(regexp$ ("[" $name "]") (?attribute))
+ (cons (make-instance 'attribute-present-selector :arg attribute)
+ (parse-selector &rest)))
;; cyclic (An+B, n+B)
(#T(regexp$ (":nth-child(" \s* an+b \s* ")")
(?asign ?a ?bsign ?b))
@@ -261,6 +268,9 @@
(declare (ignore element selector))
t)
+(defmethod subject-p ((selector attribute-present-selector) element)
+ (element-attribute (selector-arg selector) element))
+
(defmethod subject-p ((selector %implicit-element-selector) element)
(eq element *implicit-element*))
diff -rN -u old-Oh, Ducks!/tests.lisp new-Oh, Ducks!/tests.lisp
--- old-Oh, Ducks!/tests.lisp 2013-07-24 10:35:24.000000000 +0000
+++ new-Oh, Ducks!/tests.lisp 2013-07-24 10:35:24.000000000 +0000
@@ -151,6 +151,11 @@
(first q))
i)))
+(serialize-values
+ (match (#T(html (:model dom)
+ ("[id]" . ?ids))
+ "<div><i id=''>blank id</i>foo<b>no id</b>bar<i id='id'>id id</i></div>")
+ ids))
#+LATER?
(match (#t(html ("div::content" . #t(regexp+ "^f(o+)" (?o))))