From 85e753999519730f95e4429bf1a468056dae7e9c Mon Sep 17 00:00:00 2001 From: Shinmera Date: Sun, 29 Jul 2018 14:09:45 +0200 Subject: [PATCH] Fix selectors for new compiler structure. --- compiler.lisp | 4 ++-- special.lisp | 4 ++-- writer.lisp | 16 ++++++++++++++-- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/compiler.lisp b/compiler.lisp index 7e7488c..0517ae3 100644 --- a/compiler.lisp +++ b/compiler.lisp @@ -128,7 +128,7 @@ See DEFINE-SPECIAL-SELECTOR.") (loop with result = () for func in cfunc do (loop for arg in cargs - do (push (list :constraint :child func arg) result)) + do (push (list :constraint :combine " " func arg) result)) finally (return (compile-constraint (nreverse result) (cdr args)))))) (:method ((func null) (args null)) NIL) @@ -146,7 +146,7 @@ See DEFINE-SPECIAL-SELECTOR.") (loop with result = () for func in cfunc do (loop for arg in cargs - do (push (list :constraint :concat func arg) result)) + do (push (list :constraint :combine "" func arg) result)) finally (return (compile-constraint :and (cons (cons :OR (nreverse result)) (cddr args)))))) (if (and (listp (first args)) (eql (first (first args)) :OR)) (rest (first args)) diff --git a/special.lisp b/special.lisp index 643362f..ffb6ab5 100644 --- a/special.lisp +++ b/special.lisp @@ -108,7 +108,7 @@ with values = (compile-selector value) for attr in (compile-selector attr) do (loop for value in values - do (push (format NIL ,"[~a~a\"~a\"]" attr ,(string outcomp) value) out)) + do (push (list :constraint :attribute attr ,(string outcomp) value) out)) finally (return (nreverse out))))) (define-attr-comparator =) @@ -122,7 +122,7 @@ "Helper macro to define a single-argument pseudo-selector like NOT or NTH-CHILD." `(define-special-selector ,name (arg) (loop for arg in (compile-selector arg) - collect (format NIL ":~a(~a)" ,(string-downcase name) arg)))) + collect (list :constraint :selector ,(string-downcase name) arg)))) (define-single-arg-selector dir) (define-single-arg-selector lang) diff --git a/writer.lisp b/writer.lisp index 052b9ec..4cdf261 100644 --- a/writer.lisp +++ b/writer.lisp @@ -68,11 +68,23 @@ if *PRETTY* is non-NIL.") (:method ((type (eql :constraint)) constraint stream) (ecase (first constraint) ((NIL)) - (:child (format stream "~{~/lass::write-sheet-part/~^ ~}" (rest constraint))) - (:concat (format stream "~{~/lass::write-sheet-part/~}" (rest constraint))) + (:combine + (destructuring-bind (combiner &rest parts) (rest constraint) + (write-sheet-object (car (first parts)) (cdr (first parts)) stream) + (dolist (part (rest parts)) + (format stream combiner) + (write-sheet-object (car part) (cdr part) stream)))) + (:attribute + (destructuring-bind (attr comp val) (rest constraint) + (format stream "[") + (write-sheet-object (car attr) (rest attr) stream) + (format stream "~a" comp) + (format stream "~s]" (with-output-to-string (out) + (write-sheet-object (car val) (rest val) out))))) (:property (format stream "(~a:~@[~* ~]~a)" (second constraint) *pretty* (third constraint))) (:and (format stream "~{~/lass::write-sheet-part/~^ and ~}" (rest constraint))) (:func (format stream "~a(~{~a~^,~})" (second constraint) (cddr constraint))) + (:selector (format stream ":~a(~{~/lass::write-sheet-part/~^,~})" (second constraint) (cddr constraint))) (:literal (format stream "~a" (second constraint))))) (:method ((type (eql :text)) block stream)