Combine nth-child variants
Mon Nov 30 04:48:22 UTC 2009 pix@kepibu.org
* Combine nth-child variants
hunk ./selectors.lisp 47
+(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.")
+
hunk ./selectors.lisp 61
- ;; 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)
hunk ./selectors.lisp 71
- (#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)))