Mon Nov 30 04:48:22 UTC 2009 pix@kepibu.org
* Combine nth-child variants
diff -rN -u old-Oh, Ducks!/selectors.lisp new-Oh, Ducks!/selectors.lisp
--- old-Oh, Ducks!/selectors.lisp 2015-11-27 13:25:21.000000000 +0000
+++ new-Oh, Ducks!/selectors.lisp 2015-11-27 13:25:21.000000000 +0000
@@ -44,6 +44,10 @@
(let ((selector (template-spec template)))
(setf (slot-value template 'matcher) (parse-selector (string-trim " " selector))))))
+(warn "parse-selector currently relies on a patch which has not only ~
+ not been submitted to cl-unification-devel, it has not yet ~
+ been copied to penguin.")
+
(defun parse-selector (selector)
(match-case (selector)
;; combinators
@@ -54,23 +58,20 @@
(#T(regexp$ "[ ]+" ())
(list (make-instance 'descendant-combinator :matcher (parse-selector &rest))))
;; simple selectors
- ;; FIXME: fix cl-unification so it can handle non-matching groups,
- ;; so we can merge all these nth-child-selector variants
- ;; into one or two
- (#T(regexp$ ":nth-child\\([ ]*([+-]?[0-9]+)n[ ]*([+-]?[0-9]+)[ ]*\\)" (?a ?b))
- (cons (make-instance 'nth-child-selector :arg (cons (parse-integer a) (parse-integer b))) (parse-selector &rest)))
- (#T(regexp$ ":nth-child\\([ ]*([+-]?[0-9]+)n[ ]*\\)" (?a))
- (cons (make-instance 'nth-child-selector :arg (cons (parse-integer a) 0)) (parse-selector &rest)))
- (#T(regexp$ ":nth-child\\([ ]*n[ ]*([+-]?[0-9]+)[ ]*\\)" (?b))
- (cons (make-instance 'nth-child-selector :arg (cons 1 (parse-integer b))) (parse-selector &rest)))
- (#T(regexp$ ":nth-child\\([ ]*-n[ ]*([+-]?[0-9]+)[ ]*\\)" (?b))
- (cons (make-instance 'nth-child-selector :arg (cons -1 (parse-integer b))) (parse-selector &rest)))
+ ;; cyclic (An+B, n+B)
+ (#T(regexp$ ":nth-child\\([ ]*([+-]?)([0-9]+)?n[ ]*([+-]?[0-9]+)?[ ]*\\)" (?asign ?a ?b))
+ (cons (make-instance 'nth-child-selector
+ :arg (cons (funcall (if (string= "-" asign) #'- #'+)
+ (if (stringp a) (parse-integer a) 1))
+ (if (stringp b) (parse-integer b) 0)))
+ (parse-selector &rest)))
+ ;; absolute (B)
(#T(regexp$ ":nth-child\\([ ]*([+-]?[0-9]+)[ ]*\\)" (?b))
(cons (make-instance 'nth-child-selector :arg (cons 0 (parse-integer b))) (parse-selector &rest)))
- (#T(regexp$ ":nth-child\\([ ]*odd[ ]*\\)" ())
- (cons (make-instance 'nth-child-selector :arg (cons 2 1)) (parse-selector &rest)))
- (#T(regexp$ ":nth-child\\([ ]*even[ ]*\\)" ())
- (cons (make-instance 'nth-child-selector :arg (cons 2 0)) (parse-selector &rest)))
+ ;; named (odd, even)
+ (#T(regexp$ ":nth-child\\([ ]*(odd|even)[ ]*\\)" (?which))
+ (cons (make-instance 'nth-child-selector :arg (cons 2 (if (string-equal "odd" which) 1 0)))
+ (parse-selector &rest)))
(#T(regexp$ ":first-child" ())
(cons (make-instance 'nth-child-selector :arg (cons 0 1)) (parse-selector &rest)))
(#T(regexp$ "[#](\\w+)" (?id))