utils: Add read-org-variable-mapping.
This commit is contained in:
parent
eacd2a07a0
commit
286a75c8ba
2 changed files with 12 additions and 2 deletions
|
@ -49,4 +49,8 @@
|
|||
(check-equal? (read-org-table "((\"a\" \"(and a b)\") (\"b\" \"(or b (not a))\"))")
|
||||
'(("a" "(and a b)") ("b" "(or b (not a))")))
|
||||
(check-equal? (unstringify-pairs '(("a" . "1") ("b" . "(and a (not b))")))
|
||||
'((a . 1) (b . (and a (not b))))))
|
||||
'((a . 1) (b . (and a (not b)))))
|
||||
(check-equal? (read-org-variable-mapping "((\"a\" \"(and a b)\") (\"b\" \"(or b (not a))\"))")
|
||||
'((a and a b) (b or b (not a))))
|
||||
(check-equal? (read-org-variable-mapping "((\"a\" . \"(and a b)\") (\"b\" . \"(or b (not a))\"))")
|
||||
'((a and a b) (b or b (not a)))))
|
||||
|
|
|
@ -16,7 +16,8 @@
|
|||
[string->any (-> string? any/c)]
|
||||
[read-org-table (-> string? (listof any/c))]
|
||||
[unstringify-pairs (-> (listof (general-pair/c string? string?))
|
||||
(listof (general-pair/c symbol? any/c)))])
|
||||
(listof (general-pair/c symbol? any/c)))]
|
||||
[read-org-variable-mapping (-> string? variable-mapping?)])
|
||||
;; Contracts
|
||||
(contract-out [variable-mapping? contract?]
|
||||
[string-variable-mapping? contract?]
|
||||
|
@ -191,3 +192,8 @@
|
|||
(cons (string->symbol key) (string->any val))]
|
||||
[(cons key val) ; also handle improper pairs
|
||||
(cons (string->symbol key) (string->any val))])))
|
||||
|
||||
;;; Reads a variable mapping from a string, such as the one which
|
||||
;;; Org-mode produces from tables.
|
||||
(define (read-org-variable-mapping str)
|
||||
(unstringify-pairs (read-org-table str)))
|
||||
|
|
Loading…
Reference in a new issue