|
|
@ -1,9 +1,11 @@
|
|
|
|
#lang racket/base
|
|
|
|
#lang racket/base
|
|
|
|
(require xml xml/path racket/list racket/string racket/contract)
|
|
|
|
(require xml xml/path racket/list racket/string racket/contract racket/match)
|
|
|
|
(require (except-in web-server/templates in))
|
|
|
|
(require (except-in web-server/templates in))
|
|
|
|
(require "tools.rkt" "world.rkt")
|
|
|
|
(require "tools.rkt" "world.rkt")
|
|
|
|
|
|
|
|
|
|
|
|
(module+ test (require rackunit)
|
|
|
|
(module+ test (require rackunit))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(module+ test
|
|
|
|
(define tt (main->tree (dynamic-require "tests/test.pmap" POLLEN_ROOT))))
|
|
|
|
(define tt (main->tree (dynamic-require "tests/test.pmap" POLLEN_ROOT))))
|
|
|
|
|
|
|
|
|
|
|
|
; get the values out of the file, or make them up
|
|
|
|
; get the values out of the file, or make them up
|
|
|
@ -17,7 +19,7 @@
|
|
|
|
; ... 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! map-main `(map-main ,@(map path->string files)))))
|
|
|
|
(set! map-main (make-tagged-xexpr 'map-main empty (map path->string files)))))
|
|
|
|
|
|
|
|
|
|
|
|
;; todo: restrict this test
|
|
|
|
;; todo: restrict this test
|
|
|
|
(define/contract (pmap-tree? x)
|
|
|
|
(define/contract (pmap-tree? x)
|
|
|
@ -25,23 +27,23 @@
|
|
|
|
(tagged-xexpr? x))
|
|
|
|
(tagged-xexpr? x))
|
|
|
|
|
|
|
|
|
|
|
|
;; insert parents into pmap tree as attrs
|
|
|
|
;; insert parents into pmap tree as attrs
|
|
|
|
(define/contract (add-parents x [parent null] [previous null])
|
|
|
|
(define/contract (add-parents x [parent empty])
|
|
|
|
((pmap-tree?) (xexpr-tag? xexpr-tag?) . ->* . pmap-tree?)
|
|
|
|
((pmap-tree?) (xexpr-tag?) . ->* . pmap-tree?)
|
|
|
|
; disallow main as parent tag
|
|
|
|
; disallow main as parent tag
|
|
|
|
(when (equal? parent 'map-main) (set! parent empty))
|
|
|
|
(when (equal? parent 'map-main) (set! parent empty))
|
|
|
|
(cond
|
|
|
|
(match x
|
|
|
|
[(list? x)
|
|
|
|
[(list (? xexpr-tag? tag) elements ...) ; next level in hierarchy
|
|
|
|
(let ([new-parent (car x)])
|
|
|
|
(let-values ([(tag attr _) (break-tagged-xexpr (add-parents tag parent))])
|
|
|
|
; xexpr with topic as name, parent as attr, children as elements
|
|
|
|
;; xexpr with tag as name, parent as attr, children as elements with tag as next parent
|
|
|
|
`(,@(add-parents new-parent parent) ,@(map (λ(i) (add-parents i new-parent)) (cdr x))))]
|
|
|
|
(make-tagged-xexpr tag attr (map (λ(e) (add-parents e tag)) elements)))]
|
|
|
|
[else `(,(->symbol x) ((parent ,(->string parent))))]))
|
|
|
|
;; single map entry: convert to xexpr with parent
|
|
|
|
|
|
|
|
[else (make-tagged-xexpr (->symbol x) (make-xexpr-attr 'parent (->string parent)))]))
|
|
|
|
|
|
|
|
|
|
|
|
(module+ test
|
|
|
|
(module+ test
|
|
|
|
(define stt `(map-main "foo" ,(map-topic "one" "two")))
|
|
|
|
(define stt `(map-main "foo" ,(map-topic "one" (map-topic "two" "three"))))
|
|
|
|
(check-equal? (add-parents stt) '(map-main
|
|
|
|
(check-equal? (add-parents stt)
|
|
|
|
((parent ""))
|
|
|
|
'(map-main ((parent "")) (foo ((parent ""))) (one ((parent ""))
|
|
|
|
(foo ((parent "")))
|
|
|
|
(two ((parent "one")) (three ((parent "two"))))))))
|
|
|
|
(one ((parent "")) (two ((parent "one")))))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define (remove-parents x)
|
|
|
|
(define (remove-parents x)
|
|
|
|
(cond
|
|
|
|
(cond
|
|
|
|