get flat
parent
9306946df6
commit
0eb3c5e382
@ -0,0 +1,22 @@
|
||||
#lang quad/dev
|
||||
(require racket/vector)
|
||||
(provide (all-defined-out))
|
||||
|
||||
(define (atomize x)
|
||||
(flatten
|
||||
(let loop ([x x][loop-attrs default-attrs])
|
||||
(cond
|
||||
[(symbol? x) ($shim (attrs #:posn 0) x)]
|
||||
[(string? x)
|
||||
(for/list ([c (in-string x)])
|
||||
(cons ($shim (attrs #:posn 0) 0)
|
||||
(case c
|
||||
[(#\space #\newline #\return) ($white (vector-copy loop-attrs) c)]
|
||||
[else ($black (vector-copy loop-attrs) c)])))]
|
||||
[else
|
||||
(map (λ(xi) (loop xi ((quad-attrs x) . override-with . loop-attrs))) (quad-val x))]))))
|
||||
|
||||
(module+ test
|
||||
(require rackunit)
|
||||
(atomize (quad (attrs #:size 10 #:font "Eq") "ba" (line-break) "r" (quad (attrs #:size 8) "zam") "q\tux"))
|
||||
(atomize (quad #f "Meg is " (line-break) "\nan ally.")))
|
@ -1,19 +0,0 @@
|
||||
#lang quad/dev
|
||||
(require sugar/list)
|
||||
(provide (all-defined-out))
|
||||
|
||||
(struct $doc (xs) #:transparent)
|
||||
(define (doc . xs) ($doc xs))
|
||||
|
||||
(define (multipage . xs) xs)
|
||||
|
||||
(define (multicolumn . xs) xs)
|
||||
|
||||
(define (multiblock . xs) xs)
|
||||
|
||||
(define (multiline . xs)
|
||||
(wrap-lines xs))
|
||||
|
||||
(struct $line $quad () #:transparent)
|
||||
(define (wrap-lines xs)
|
||||
(map (λ(xis) ($line (gather-common-attrs xis) xis)) (slice-at xs 6)))
|
@ -1,17 +1,15 @@
|
||||
#lang racket/base
|
||||
(require "quads.rkt" "doc.rkt" "parse.rkt" "tokenize.rkt" racket/list racket/string)
|
||||
(require "quads.rkt" "typeset.rkt" "atomize.rkt" racket/list racket/string)
|
||||
(provide (except-out (all-from-out racket/base "quads.rkt") #%module-begin)
|
||||
(rename-out [~module-begin #%module-begin]))
|
||||
|
||||
(define-namespace-anchor ns)
|
||||
|
||||
(define-syntax-rule (~module-begin lang-line-config-arg . args)
|
||||
(#%module-begin
|
||||
(define main-quad (quad #f . args))
|
||||
;; branch on config-arg to allow debug / inspection options on #lang line
|
||||
(case (string-trim lang-line-config-arg)
|
||||
[("#:atoms") (tokenize main-quad)]
|
||||
[else (eval (parse (tokenize main-quad)) (namespace-anchor->namespace ns))])))
|
||||
[("#:atoms") (atomize main-quad)]
|
||||
[else (typeset (atomize main-quad))])))
|
||||
|
||||
(module reader syntax/module-reader
|
||||
"main.rkt")
|
@ -0,0 +1,6 @@
|
||||
#lang quad/dev
|
||||
(provide (all-defined-out))
|
||||
|
||||
(define (measure! q)
|
||||
(when (or ($black? q) ($white? q))
|
||||
(quad-posn-set! q 12)))
|
@ -1,11 +0,0 @@
|
||||
#lang brag
|
||||
|
||||
doc : multipage [/PAGE-BREAK multipage]*
|
||||
|
||||
multipage : multicolumn [/COLUMN-BREAK multicolumn]*
|
||||
|
||||
multicolumn : multiblock [/BLOCK-BREAK multiblock]*
|
||||
|
||||
multiblock : multiline [/LINE-BREAK multiline]*
|
||||
|
||||
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.}
|
@ -1,21 +0,0 @@
|
||||
#lang quad/dev
|
||||
(require brag/support)
|
||||
(provide (all-defined-out))
|
||||
|
||||
(define (tokenize x)
|
||||
(flatten
|
||||
(let loop ([x x][attrs default-attrs])
|
||||
(cond
|
||||
[(symbol? x) (token x #f)]
|
||||
[(string? x)
|
||||
(for/list ([c (in-string x)])
|
||||
(case 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))]))))
|
||||
|
||||
(module+ test
|
||||
(require rackunit "parse.rkt")
|
||||
(tokenize (quad (attrs #:size 10 #:font "Eq") "ba" (line-break) "r" (quad (attrs #:size 8) "zam") "q\tux"))
|
||||
(syntax->datum (parse (tokenize (quad #f "Meg is " (line-break) "\nan ally.")))))
|
@ -1,19 +1,22 @@
|
||||
#lang quad/dev
|
||||
(provide (all-defined-out))
|
||||
(require "tokenize.rkt" "parse.rkt")
|
||||
(require "measure.rkt")
|
||||
|
||||
#;(define (typeset x)
|
||||
(pages->doc
|
||||
(append*
|
||||
(for/list ([multipage (in-list (input->nested-blocks x))])
|
||||
(columns->pages
|
||||
(append*
|
||||
(for/list ([multicolumn (in-list multipage)])
|
||||
(lines->columns
|
||||
(append*
|
||||
(for/list ([block-quads (in-list multicolumn)])
|
||||
(block-quads->lines block-quads)))))))))))
|
||||
(define line-start-k #f)
|
||||
|
||||
(define (typeset qs)
|
||||
(for-each measure! qs)
|
||||
(for/fold ([line-pos 0])
|
||||
([q (in-list qs)])
|
||||
(unless line-start-k
|
||||
(let/cc here-k (set! line-start-k here-k)))
|
||||
(define next-line-pos (+ line-pos (quad-posn q)))
|
||||
(if (and (> next-line-pos 84) ($white? q))
|
||||
(begin (quad-posn-set! q 'break-line) 0)
|
||||
next-line-pos))
|
||||
qs)
|
||||
|
||||
(define input (quad #f "Meg is an ally." (quad #f 'page-break) "Meg is an ally."))
|
||||
(syntax->datum (parse (tokenize input)))
|
||||
(module+ test
|
||||
(require "atomize.rkt")
|
||||
(define qs (atomize (quad #f "Meg is an ally.")))
|
||||
(typeset qs))
|
Loading…
Reference in New Issue