Sat Nov 21 18:31:09 UTC 2009 pix@kepibu.org
* Tired, probably doing stupid things
diff -rN -u old-Oh, Ducks!/tests.lisp new-Oh, Ducks!/tests.lisp
--- old-Oh, Ducks!/tests.lisp 2013-11-10 20:25:31.000000000 +0000
+++ new-Oh, Ducks!/tests.lisp 2013-11-10 20:25:31.000000000 +0000
@@ -35,12 +35,19 @@
(equalp '((:i () "not"))
(match (#T(html (:model dom)
- ("div" ("i" . ?i)
- ("span" . ?span)))
+ ("div" (">i" . ?i)
+ ;("i" . #t(list ?j ?i))
+ ("span>i" . ?span)))
"<div>I do <i>not</i> like cheese.</div><div><span>I like <i>cheese</i>.</span></div>")
(values i span)))
+(match (#T(html (:model dom)
+ ("i" . ?i);#t(list ?j ?i))
+ ("span>i" . ?span))
+ "<div>I do <i>not</i> like cheese.</div><div><span>I like <i>cheese</i>.</span></div>")
+ (values i span))
+
#+LATER
-(match (#t(lhtml ("div::content" . #t(regexp+ "^f(o+)" (?o))))
+(match (#t(html ("div::content" . #t(regexp+ "^f(o+)" (?o))))
"<div>barbaz</div><div>fooooooobar</div>")
(values o &rest))
diff -rN -u old-Oh, Ducks!/unify.lisp new-Oh, Ducks!/unify.lisp
--- old-Oh, Ducks!/unify.lisp 2013-11-10 20:25:31.000000000 +0000
+++ new-Oh, Ducks!/unify.lisp 2013-11-10 20:25:31.000000000 +0000
@@ -8,28 +8,58 @@
:format-control "Do not know how to unify the two css-selector-templates ~S and ~S."
:format-arguments (list a b)))
+(defun merge-environments (env1 env2)
+ (assert (or (unify::empty-environment-p env1)
+ (equal (unify::environment-variables env1)
+ (unify::environment-variables env2))))
+ (format t "ev1: ~s, ev2: ~s~%" (unify::environment-values env1) (unify::environment-values env2))
+ (format t "q: ~s~%" (unify::find-variable-value '?i env1))
+ (unify::fill-environment (unify::environment-variables env1)
+ (mapcar (lambda (a b) (format t "a: ~s, b: ~s~%" a b) (append a b))
+ (unify::environment-values env1)
+ (unify::environment-values env2))
+ (make-empty-environment)))
+
(defmethod unify ((template css-selector-template) document
&optional (env (make-empty-environment))
&key &allow-other-keys)
+ (declare (optimize debug))
(loop :for (css-specifier . template) :in (specifiers template)
:do
- (setf
- env
(let ((val (find-matching-elements css-specifier document)))
- #+(or) (if (null val) (cerror "continue" "null!"))
- (format t "mel: ~s, css: ~s, tpl: ~s~%" val css-specifier template)
(cond
+ ;; FIXME: make possible to say things like ("div" . #t(list ?first-div &rest))
+ #+(or)
+ ((typep template 'css-selector-template)
+ (format t "hey! ~s~%" template)
+ (let ((menv (reduce #'merge-environments
+ (mapcar (curry #'unify template)
+ val))))
+ (unify::fill-environment (unify::environment-variables menv)
+ (unify::environment-values menv)
+ env)))
((unify::template-p template)
- #+(or) (format t "template-p~%")
+ (let ((menv (reduce #'merge-environments
+ (mapcar (curry #'unify template)
+ val))))
+ (unify::fill-environment (unify::environment-variables menv)
+ (unify::environment-values menv)
+ env))
+ #+(or)
(unify template val env)
- #+(or) ;; FIXME: in the case of multiple items in val, this will only return one.
+ #+(or)
(loop :for element :in val
- :do (setf env (unify template element env))
- :finally (return env)))
+ :do (unify template element env)))
((unify::variablep template)
- #+(or) (format t "variable-p~%")
- (unify::extend-environment template val env))
- (t (error "whoops: ~s, ~s" css-specifier template))))))
+ ;; *ahem* FIXME: this makes ("a" ("b" . ?b)) possible,
+ ;; but will cause the wrong thing to happen for
+ ;; ("a" ("b" . ?b) ("#b" . ?b))
+ ;(alexandria:if-let ((varval (find-variable-value template env)))
+ ; (nconc varval val)
+ (unify::var-unify template val env)
+ #+(or)
+ (unify::extend-environment template val env));)
+ (t (error "whoops: ~s, ~s" css-specifier template)))))
env)
(defmethod unify (document (template css-selector-template)