append-boq-and-eoq

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

@ -13,11 +13,11 @@
#:post (list-of simple-quad?)
(append*
(for/list ([q (in-list qs)])
(match q
[(quad _ _ (list (? string? str)) _)
(for/list ([c (in-string str)])
(struct-copy quad q [elems (list (string c))]))]
[_ (list q)]))))
(match q
[(quad _ _ (list (? string? str)) _)
(for/list ([c (in-string str)])
(struct-copy quad q [elems (list (string c))]))]
[_ (list q)]))))
(define-pass (linearize qs)
;; convert a single quad into a list of quads, with the attributes propagated downward
@ -101,4 +101,13 @@
qs)
(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-features
parse-page-sizes
resolve-font-paths
complete-attr-paths
;; linearization =============
;; we postpone this step until we're certain any
@ -45,11 +47,10 @@
;; has been absorbed into the attrs
;; (e.g., cascading font sizes)
;; because once we linearize, that information is gone.
(print-pass linearize)
linearize
(print-pass append-boq-and-eoq)
;; post-linearization resolutions & parsings =============
resolve-font-paths
complete-attr-paths
mark-text-runs
merge-adjacent-strings
@ -59,7 +60,7 @@
remove-font-without-char
insert-fallback-font
layout
make-drawing-insts
(print-pass make-drawing-insts)
stackify))
(module+ main

@ -25,7 +25,7 @@
(? quad-attrs?)
(? quad-elems?)) #true]
[_ #false])
(error 'no-dice))
(raise-user-error 'quad-constructor (format "failed: ~v" (list tag attrs elems posn))))
(values tag attrs elems posn)))
(define (quad-tag? x) (match x
@ -108,4 +108,11 @@
[(? string? str) (loop (make-quad #:elems (list str)))])))
(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