From 27ef82cd96b420c87268ee2a79fa0a572daeb686 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Sun, 8 May 2022 13:36:06 -0700 Subject: [PATCH] add `convert-path-attr-values` --- quad2/attr.rkt | 18 +++++++++++++++--- quad2/main.rkt | 1 + 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/quad2/attr.rkt b/quad2/attr.rkt index 2280f5b5..112a31f6 100644 --- a/quad2/attr.rkt +++ b/quad2/attr.rkt @@ -123,6 +123,15 @@ (or (string->number av) (raise-argument-error 'convert-numeric-attr-values "numeric string" av))))) +(define-pass (convert-path-attr-values qs) + #:pre (list-of quad?) + #:post (list-of quad?) + (do-attr-iteration qs + #:which-attr attr-path-key? + #:attr-proc (λ (ak av attrs) + (or (string->path av) + (raise-argument-error 'convert-path-attr-values "path string" av))))) + (define-pass (convert-set-attr-values qs) #:pre (list-of quad?) #:post (list-of quad?) @@ -141,12 +150,15 @@ (define-pass (complete-attr-paths qs) #:pre (list-of quad?) #:post (list-of quad?) - ;; convert every pathlike thing to a complete path (well, path string, because it's inside an attr) + ;; convert every path value to a complete path ;; so we don't get tripped up later by relative paths ;; relies on `current-directory` being parameterized to source file's dir (do-attr-iteration qs #:which-attr attr-path-key? - #:attr-proc (λ (ak av attrs) (path->complete-path av)))) + #:attr-proc (λ (ak av attrs) + (unless (path? av) + (raise-argument-error 'complete-attr-paths "path" av)) + (path->complete-path av)))) (define-pass (parse-dimension-strings qs) @@ -170,7 +182,7 @@ (parameterize ([current-attrs debug-attrs]) (define (make-q) (make-quad #:attrs (list :foo "BAR" 'ding "dong" - :ps "file.txt" + :ps (string->path "file.txt") :dim "2in" :boolt "true" :boolf "false" diff --git a/quad2/main.rkt b/quad2/main.rkt index 30aff934..fe8e9e17 100644 --- a/quad2/main.rkt +++ b/quad2/main.rkt @@ -31,6 +31,7 @@ convert-boolean-attr-values convert-numeric-attr-values convert-set-attr-values + convert-path-attr-values ;; pre-linearization resolutions & parsings ============= ;; these need the tree shape