append-boq-and-eoq

signals beginning & end of a list of quads
main
Matthew Butterick 2 years ago
parent b5f794014e
commit bc78ac9824

@ -13,11 +13,11 @@
#:post (list-of simple-quad?) #:post (list-of simple-quad?)
(append* (append*
(for/list ([q (in-list qs)]) (for/list ([q (in-list qs)])
(match q (match q
[(quad _ _ (list (? string? str)) _) [(quad _ _ (list (? string? str)) _)
(for/list ([c (in-string str)]) (for/list ([c (in-string str)])
(struct-copy quad q [elems (list (string c))]))] (struct-copy quad q [elems (list (string c))]))]
[_ (list q)])))) [_ (list q)]))))
(define-pass (linearize qs) (define-pass (linearize qs)
;; convert a single quad into a list of quads, with the attributes propagated downward ;; convert a single quad into a list of quads, with the attributes propagated downward
@ -101,4 +101,13 @@
qs) qs)
(module+ test (module+ test
(mark-text-runs smlqs)) (mark-text-runs smlqs))
(define-pass (append-boq-and-eoq qs)
#:pre (list-of simple-quad?)
#:post (λ (qs) (match qs
[(list (? boq-quad?) (? simple-quad?) ... (? eoq-quad?)) #true]
[_ #false]))
(set-quad-attrs! boq (quad-attrs (first qs)))
(set-quad-attrs! eoq (quad-attrs (last qs)))
(append (list boq) qs (list eoq)))

@ -38,6 +38,8 @@
resolve-font-sizes resolve-font-sizes
resolve-font-features resolve-font-features
parse-page-sizes parse-page-sizes
resolve-font-paths
complete-attr-paths
;; linearization ============= ;; linearization =============
;; we postpone this step until we're certain any ;; we postpone this step until we're certain any
@ -45,11 +47,10 @@
;; has been absorbed into the attrs ;; has been absorbed into the attrs
;; (e.g., cascading font sizes) ;; (e.g., cascading font sizes)
;; because once we linearize, that information is gone. ;; because once we linearize, that information is gone.
(print-pass linearize) linearize
(print-pass append-boq-and-eoq)
;; post-linearization resolutions & parsings ============= ;; post-linearization resolutions & parsings =============
resolve-font-paths
complete-attr-paths
mark-text-runs mark-text-runs
merge-adjacent-strings merge-adjacent-strings
@ -59,7 +60,7 @@
remove-font-without-char remove-font-without-char
insert-fallback-font insert-fallback-font
layout layout
make-drawing-insts (print-pass make-drawing-insts)
stackify)) stackify))
(module+ main (module+ main

@ -25,7 +25,7 @@
(? quad-attrs?) (? quad-attrs?)
(? quad-elems?)) #true] (? quad-elems?)) #true]
[_ #false]) [_ #false])
(error 'no-dice)) (raise-user-error 'quad-constructor (format "failed: ~v" (list tag attrs elems posn))))
(values tag attrs elems posn))) (values tag attrs elems posn)))
(define (quad-tag? x) (match x (define (quad-tag? x) (match x
@ -108,4 +108,11 @@
[(? string? str) (loop (make-quad #:elems (list str)))]))) [(? string? str) (loop (make-quad #:elems (list str)))])))
(module+ test (module+ test
(define q (make-quad #:tag 'div #:attrs (make-hasheq '((hello . "world"))) #:elems (list "fine")))) (define q (make-quad #:tag 'div #:attrs (make-hasheq '((hello . "world"))) #:elems (list "fine"))))
(struct boq-quad quad ())
(define boq (boq-quad #f (make-hasheq) null #f))
(struct eoq-quad quad ())
(define eoq (eoq-quad #f (make-hasheq) null #f))
Loading…
Cancel
Save