|
|
@ -18,13 +18,13 @@
|
|
|
|
; ... synthesize it
|
|
|
|
; ... synthesize it
|
|
|
|
(let ([files (directory-list START_DIR)])
|
|
|
|
(let ([files (directory-list START_DIR)])
|
|
|
|
(set! files (map remove-ext (filter (λ(x) (has-ext? x POLLEN_SOURCE_EXT)) files)))
|
|
|
|
(set! files (map remove-ext (filter (λ(x) (has-ext? x POLLEN_SOURCE_EXT)) files)))
|
|
|
|
(set! pmap-main (make-tagged-xexpr 'map-main empty (map path->string files)))))
|
|
|
|
(set! pmap-main (make-tagged-xexpr 'pmap-root empty (map path->string files)))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; recursively processes map, converting map locations & their parents into xexprs of this shape:
|
|
|
|
;; recursively processes map, converting map locations & their parents into xexprs of this shape:
|
|
|
|
;; '(location ((parent "parent")))
|
|
|
|
;; '(location ((parent "parent")))
|
|
|
|
(define/contract (add-parents x [parent empty])
|
|
|
|
(define/contract (add-parents x [parent empty])
|
|
|
|
((pmap?) (xexpr-tag?) . ->* . pmap?)
|
|
|
|
((tagged-xexpr?) (xexpr-tag?) . ->* . pmap?)
|
|
|
|
; disallow map-main as parent tag
|
|
|
|
; disallow map-main as parent tag
|
|
|
|
; (when (equal? parent 'map-main) (set! parent empty))
|
|
|
|
; (when (equal? parent 'map-main) (set! parent empty))
|
|
|
|
(match x
|
|
|
|
(match x
|
|
|
@ -57,7 +57,7 @@
|
|
|
|
;; remove parents from map (i.e., just remove attrs)
|
|
|
|
;; remove parents from map (i.e., just remove attrs)
|
|
|
|
;; is not the inverse of add-parents, i.e., you do not get back your original input.
|
|
|
|
;; is not the inverse of add-parents, i.e., you do not get back your original input.
|
|
|
|
(define/contract (remove-parents mt)
|
|
|
|
(define/contract (remove-parents mt)
|
|
|
|
(pmap? . -> . pmap?)
|
|
|
|
(pmap? . -> . tagged-xexpr?)
|
|
|
|
(remove-attrs mt))
|
|
|
|
(remove-attrs mt))
|
|
|
|
|
|
|
|
|
|
|
|
(module+ test
|
|
|
|
(module+ test
|
|
|
@ -68,9 +68,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(module+ test
|
|
|
|
(module+ test
|
|
|
|
(define sample-main `(pmap-root "foo" "bar" (one (two "three"))))
|
|
|
|
(let ([sample-main `(pmap-root "foo" "bar" (one (two "three")))])
|
|
|
|
(check-equal? (main->pmap sample-main)
|
|
|
|
(check-equal? (main->pmap sample-main)
|
|
|
|
'(pmap-root ((parent "")) (foo ((parent "pmap-root"))) (bar ((parent "pmap-root"))) (one ((parent "pmap-root")) (two ((parent "one")) (three ((parent "two"))))))))
|
|
|
|
'(pmap-root ((parent "")) (foo ((parent "pmap-root"))) (bar ((parent "pmap-root"))) (one ((parent "pmap-root")) (two ((parent "one")) (three ((parent "two")))))))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -118,78 +118,77 @@
|
|
|
|
(check-equal? (siblings 'two test-pmap) '("two"))
|
|
|
|
(check-equal? (siblings 'two test-pmap) '("two"))
|
|
|
|
(check-false (siblings 'invalid-key test-pmap)))
|
|
|
|
(check-false (siblings 'invalid-key test-pmap)))
|
|
|
|
|
|
|
|
|
|
|
|
;; helper function
|
|
|
|
|
|
|
|
(define/contract (side-siblings side element [pmap pmap])
|
|
|
|
|
|
|
|
((symbol? pmap-key?) (pmap?) . ->* . (or/c list? boolean?))
|
|
|
|
|
|
|
|
(define result ((if (equal? side 'left) takef takef-right)
|
|
|
|
|
|
|
|
(siblings element pmap)
|
|
|
|
|
|
|
|
(λ(i) (not (equal? (->string element) (->string i))))))
|
|
|
|
|
|
|
|
(and (not (empty? result)) result))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define/contract (pmap-split element elements)
|
|
|
|
(define/contract (siblings-split element [pmap pmap])
|
|
|
|
(pmap-key? (listof pmap-key?) . -> . (values (listof pmap-key?) (listof pmap-key?)))
|
|
|
|
((pmap-key?) (pmap?) . ->* . (values (or/c (listof pmap-key?) boolean?)
|
|
|
|
(define-values (left right) (splitf-at elements
|
|
|
|
(or/c (listof pmap-key?) boolean?)))
|
|
|
|
(λ(e) (not (equal? (->string e) (->string element))))))
|
|
|
|
(let-values ([(left right) (splitf-at (siblings element pmap)
|
|
|
|
(values left (cdr right)))
|
|
|
|
(λ(e) (not (equal? (->string e) (->string element)))))])
|
|
|
|
|
|
|
|
(values (if (empty? left) #f left) (if (empty? (cdr right)) #f (cdr right)))))
|
|
|
|
|
|
|
|
|
|
|
|
(module+ test
|
|
|
|
(module+ test
|
|
|
|
(check-equal? (values->list (pmap-split 'bar (siblings 'bar test-pmap))) (list '("foo") '("one"))))
|
|
|
|
(check-equal? (values->list (siblings-split 'one test-pmap)) '(("foo" "bar") #f))
|
|
|
|
|
|
|
|
(check-equal? (values->list (siblings-split 'bar test-pmap)) (list '("foo") '("one"))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; siblings to the left of target element (i.e., precede in map order)
|
|
|
|
;; siblings to the left of target element (i.e., precede in map order)
|
|
|
|
(define (left-siblings element [pmap pmap])
|
|
|
|
(define (siblings-left element [pmap pmap])
|
|
|
|
(side-siblings 'left element pmap))
|
|
|
|
(let-values ([(left right) (siblings-split element pmap)])
|
|
|
|
|
|
|
|
left))
|
|
|
|
|
|
|
|
|
|
|
|
(module+ test
|
|
|
|
(module+ test
|
|
|
|
(check-equal? (left-siblings 'one test-pmap) '("foo" "bar"))
|
|
|
|
(check-equal? (siblings-left 'one test-pmap) '("foo" "bar"))
|
|
|
|
(check-false (left-siblings 'foo test-pmap)))
|
|
|
|
(check-false (siblings-left 'foo test-pmap)))
|
|
|
|
|
|
|
|
|
|
|
|
;; siblings to the right of target element (i.e., follow in map order)
|
|
|
|
;; siblings to the right of target element (i.e., follow in map order)
|
|
|
|
(define (right-siblings element [pmap pmap])
|
|
|
|
(define (siblings-right element [pmap pmap])
|
|
|
|
(side-siblings 'right element pmap))
|
|
|
|
(let-values ([(left right) (siblings-split element pmap)])
|
|
|
|
|
|
|
|
right))
|
|
|
|
|
|
|
|
|
|
|
|
(module+ test
|
|
|
|
(module+ test
|
|
|
|
(check-false (right-siblings 'one test-pmap))
|
|
|
|
(check-false (siblings-right 'one test-pmap))
|
|
|
|
(check-equal? (right-siblings 'foo test-pmap) '("bar" "one")))
|
|
|
|
(check-equal? (siblings-right 'foo test-pmap) '("bar" "one")))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; get element immediately to the left in map
|
|
|
|
;; get element immediately to the left in map
|
|
|
|
(define/contract (left-sibling element [pmap pmap])
|
|
|
|
(define/contract (sibling-previous element [pmap pmap])
|
|
|
|
((pmap-key?) (pmap?) . ->* . (or/c string? boolean?))
|
|
|
|
((pmap-key?) (pmap?) . ->* . (or/c string? boolean?))
|
|
|
|
(define siblings (left-siblings element pmap))
|
|
|
|
(let ([siblings (siblings-left element pmap)])
|
|
|
|
(and siblings (last siblings)))
|
|
|
|
(and siblings (last siblings))))
|
|
|
|
|
|
|
|
|
|
|
|
(module+ test
|
|
|
|
(module+ test
|
|
|
|
(check-equal? (left-sibling 'bar test-pmap) "foo")
|
|
|
|
(check-equal? (sibling-previous 'bar test-pmap) "foo")
|
|
|
|
(check-false (left-sibling 'foo test-pmap)))
|
|
|
|
(check-false (sibling-previous 'foo test-pmap)))
|
|
|
|
|
|
|
|
|
|
|
|
;; get element immediately to the right in map
|
|
|
|
;; get element immediately to the right in map
|
|
|
|
(define/contract (right-sibling element [pmap pmap])
|
|
|
|
(define/contract (sibling-next element [pmap pmap])
|
|
|
|
((pmap-key?) (pmap?) . ->* . (or/c string? boolean?))
|
|
|
|
((pmap-key?) (pmap?) . ->* . (or/c string? boolean?))
|
|
|
|
(define siblings (right-siblings element pmap))
|
|
|
|
(let ([siblings (siblings-right element pmap)])
|
|
|
|
(and siblings (first siblings)))
|
|
|
|
(and siblings (first siblings))))
|
|
|
|
|
|
|
|
|
|
|
|
(module+ test
|
|
|
|
(module+ test
|
|
|
|
(check-equal? (right-sibling 'foo test-pmap) "bar")
|
|
|
|
(check-equal? (sibling-next 'foo test-pmap) "bar")
|
|
|
|
(check-false (right-sibling 'one test-pmap)))
|
|
|
|
(check-false (sibling-next 'one test-pmap)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; flatten map to sequence
|
|
|
|
;; flatten map to sequence
|
|
|
|
(define/contract (make-page-sequence [pmap pmap])
|
|
|
|
(define/contract (all-pages [pmap pmap])
|
|
|
|
(pmap? . -> . (listof string?))
|
|
|
|
(pmap? . -> . (listof string?))
|
|
|
|
; use cdr to get rid of main-map tag at front
|
|
|
|
; use cdr to get rid of main-map tag at front
|
|
|
|
(map ->string (cdr (flatten (remove-parents pmap)))))
|
|
|
|
(map ->string (cdr (flatten (remove-parents pmap)))))
|
|
|
|
|
|
|
|
|
|
|
|
(module+ test
|
|
|
|
(module+ test
|
|
|
|
(check-equal? (make-page-sequence test-pmap) '("foo" "bar" "one" "two" "three")))
|
|
|
|
(check-equal? (all-pages test-pmap) '("foo" "bar" "one" "two" "three")))
|
|
|
|
|
|
|
|
|
|
|
|
;; helper function for get-previous-pages and get-next-pages
|
|
|
|
;; helper function for get-previous-pages and get-next-pages
|
|
|
|
(define/contract (adjacent-pages side element [pmap pmap])
|
|
|
|
(define/contract (adjacent-pages side element [pmap pmap])
|
|
|
|
((symbol? pmap-key?) (pmap?) . ->* . (or/c list? boolean?))
|
|
|
|
((symbol? pmap-key?) (pmap?) . ->* . (or/c list? boolean?))
|
|
|
|
(define result ((if (equal? side 'left) takef takef-right)
|
|
|
|
(let ([result ((if (equal? side 'left)
|
|
|
|
(make-page-sequence pmap) (λ(y) (not (equal? (->string element) (->string y))))))
|
|
|
|
takef
|
|
|
|
(and (not (empty? result)) result))
|
|
|
|
takef-right) (all-pages pmap)
|
|
|
|
|
|
|
|
(λ(y) (not (equal? (->string element) (->string y)))))])
|
|
|
|
|
|
|
|
(and (not (empty? result)) result)))
|
|
|
|
|
|
|
|
|
|
|
|
(module+ test
|
|
|
|
(module+ test
|
|
|
|
(check-equal? (adjacent-pages 'left 'one test-pmap) '("foo" "bar"))
|
|
|
|
(check-equal? (adjacent-pages 'left 'one test-pmap) '("foo" "bar"))
|
|
|
@ -221,8 +220,8 @@
|
|
|
|
;; get page immediately previous
|
|
|
|
;; get page immediately previous
|
|
|
|
(define/contract (previous-page element [pmap pmap])
|
|
|
|
(define/contract (previous-page element [pmap pmap])
|
|
|
|
((pmap-key?) (pmap?) . ->* . (or/c string? boolean?))
|
|
|
|
((pmap-key?) (pmap?) . ->* . (or/c string? boolean?))
|
|
|
|
(define result (previous-pages element pmap))
|
|
|
|
(let ([result (previous-pages element pmap)])
|
|
|
|
(and result (last result)))
|
|
|
|
(and result (last result))))
|
|
|
|
|
|
|
|
|
|
|
|
(module+ test
|
|
|
|
(module+ test
|
|
|
|
(check-equal? (previous-page 'one test-pmap) "bar")
|
|
|
|
(check-equal? (previous-page 'one test-pmap) "bar")
|
|
|
@ -232,21 +231,14 @@
|
|
|
|
;; get page immediately next
|
|
|
|
;; get page immediately next
|
|
|
|
(define (next-page element [pmap pmap])
|
|
|
|
(define (next-page element [pmap pmap])
|
|
|
|
((pmap-key?) (pmap?) . ->* . (or/c string? boolean?))
|
|
|
|
((pmap-key?) (pmap?) . ->* . (or/c string? boolean?))
|
|
|
|
(define result (next-pages element pmap))
|
|
|
|
(let ([result (next-pages element pmap)])
|
|
|
|
(and result (first result)))
|
|
|
|
(and result (first result))))
|
|
|
|
|
|
|
|
|
|
|
|
(module+ test
|
|
|
|
(module+ test
|
|
|
|
(check-equal? (next-page 'foo test-pmap) "bar")
|
|
|
|
(check-equal? (next-page 'foo test-pmap) "bar")
|
|
|
|
(check-equal? (next-page 'one test-pmap) "two")
|
|
|
|
(check-equal? (next-page 'one test-pmap) "two")
|
|
|
|
(check-false (next-page 'three test-pmap)))
|
|
|
|
(check-false (next-page 'three test-pmap)))
|
|
|
|
|
|
|
|
|
|
|
|
#|(module+ test
|
|
|
|
|
|
|
|
;; need to parameterize current-directory
|
|
|
|
|
|
|
|
;; because pollen main depends on it to find the include functions
|
|
|
|
|
|
|
|
(define pm (parameterize ([current-directory "./tests/"])
|
|
|
|
|
|
|
|
(main->pmap (dynamic-require "test.pmap" 'main))))
|
|
|
|
|
|
|
|
(check-equal? (previous-page (parent 'printers-and-paper pm) pm) "ligatures"))
|
|
|
|
|
|
|
|
|#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define/contract (pmap-decode . elements)
|
|
|
|
(define/contract (pmap-decode . elements)
|
|
|
@ -259,14 +251,14 @@
|
|
|
|
;; they must also be unique
|
|
|
|
;; they must also be unique
|
|
|
|
(flat-named-contract 'unique-pmap-keys
|
|
|
|
(flat-named-contract 'unique-pmap-keys
|
|
|
|
(λ(e) (elements-unique? #:loud #t
|
|
|
|
(λ(e) (elements-unique? #:loud #t
|
|
|
|
(map ->string ; to make keys comparable
|
|
|
|
(map ->string ; to make keys comparable
|
|
|
|
(filter-not whitespace? (flatten e)))))))
|
|
|
|
(filter-not whitespace? (flatten e)))))))
|
|
|
|
. ->* . pmap?)
|
|
|
|
. ->* . pmap?)
|
|
|
|
(main->pmap (decode (cons 'pmap-root elements)
|
|
|
|
(main->pmap (decode (cons 'pmap-root elements)
|
|
|
|
; #:exclude-xexpr-tags 'em
|
|
|
|
; #:exclude-xexpr-tags 'em
|
|
|
|
; #:xexpr-tag-proc [xexpr-tag-proc (λ(x)x)]
|
|
|
|
; #:xexpr-tag-proc [xexpr-tag-proc (λ(x)x)]
|
|
|
|
; #:xexpr-attr-proc [xexpr-attr-proc (λ(x)x)]
|
|
|
|
; #:xexpr-attr-proc [xexpr-attr-proc (λ(x)x)]
|
|
|
|
#:xexpr-elements-proc (λ(xs) (filter-not whitespace? xs))
|
|
|
|
#:xexpr-elements-proc (λ(xs) (filter-not whitespace? xs))
|
|
|
|
; #:block-xexpr-proc block-xexpr-proc
|
|
|
|
; #:block-xexpr-proc block-xexpr-proc
|
|
|
|
; #:inline-xexpr-proc [inline-xexpr-proc (λ(x)x)]
|
|
|
|
; #:inline-xexpr-proc [inline-xexpr-proc (λ(x)x)]
|
|
|
|
)))
|
|
|
|
)))
|
|
|
|