add $quad-white and `gather-common-attrs`

main
Matthew Butterick 9 years ago
parent f0de2a1e84
commit 9306946df6

@ -12,8 +12,8 @@
(define (multiblock . xs) xs)
(define (multiline . xs)
(break-lines xs))
(wrap-lines xs))
(struct $line (xs) #:transparent)
(define (break-lines xs)
(map (λ(xis) ($line xis)) (slice-at xs 6)))
(struct $line $quad () #:transparent)
(define (wrap-lines xs)
(map (λ(xis) ($line (gather-common-attrs xis) xis)) (slice-at xs 6)))

@ -8,4 +8,4 @@ multicolumn : multiblock [/BLOCK-BREAK multiblock]*
multiblock : multiline [/LINE-BREAK multiline]*
multiline : /WHITESPACE* (QUAD [WHITESPACE+ QUAD]*)* /WHITESPACE*
multiline : /QUAD-WHITE* (QUAD [QUAD-WHITE+ QUAD]*)* /QUAD-WHITE*

@ -1,3 +1,3 @@
#lang quad/text
Meg is an ally. @(line-break) Meg is an ally.
Meg is an ally. ;; @(line-break) Meg is an ally.

@ -3,6 +3,7 @@
(require (for-syntax racket/string racket/base racket/syntax))
(struct $quad (attrs list) #:transparent)
(struct $quad-white $quad () #:transparent)
(define quad? $quad?)
@ -32,6 +33,14 @@ measure (line width)
#:posn [posn #f])
(vector size font posn))
(define (gather-common-attrs xs)
(define reference-attrs (quad-attrs (car xs)))
(for/vector ([idx (in-range (vector-length default-attrs))])
(if (for/and ([x (in-list (cdr xs))])
(equal? (vector-ref reference-attrs idx) (vector-ref (quad-attrs x) idx)))
(vector-ref reference-attrs idx)
#f)))
(define (attr-size a) (vector-ref a 0))
(define (attr-font a) (vector-ref a 1))
@ -41,8 +50,8 @@ measure (line width)
(define (override-with dest source)
;; replace missing values in dest with values from source
(for ([i (in-range (vector-length source))])
(unless (vector-ref dest i)
(vector-set! dest i (vector-ref source i))))
(unless (vector-ref dest i)
(vector-set! dest i (vector-ref source i))))
dest)
(require (for-syntax sugar/debug))

@ -10,7 +10,7 @@
[(string? x)
(for/list ([c (in-string x)])
(case c
[(#\space #\newline #\return) (token 'WHITESPACE (quad attrs c))]
[(#\space #\newline #\return) (token 'QUAD-WHITE ($quad-white attrs c))]
[else (token 'QUAD (quad attrs c))]))]
[else
(map (λ(xi) (loop xi ((quad-attrs x) . override-with . attrs))) (quad-list x))]))))

Loading…
Cancel
Save