Fix selectors for new compiler structure.

This commit is contained in:
Shinmera 2018-07-29 14:09:45 +02:00
parent 4baf969f7c
commit 85e7539995
No known key found for this signature in database
GPG Key ID: E12B14478BE4C922
3 changed files with 18 additions and 6 deletions

View File

@ -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))

View File

@ -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)

View File

@ -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)