utils: Add read-org-table.

This commit is contained in:
Sergiu Ivanov 2020-02-22 12:18:37 +01:00
parent 7d52533f74
commit fed1f65abd
2 changed files with 9 additions and 2 deletions

View File

@ -45,4 +45,6 @@
(check-equal? (hash-ref mp 'a) "(and a b)")
(check-equal? (hash-ref mp 'b) "(not b)"))
(check-equal? (string->any "(or b (not a))") '(or b (not a)))
(check-equal? (string->any "14") 14))
(check-equal? (string->any "14") 14)
(check-equal? (read-org-table "((\"a\" \"(and a b)\") (\"b\" \"(or b (not a))\"))")
'(("a" "(and a b)") ("b" "(or b (not a))"))))

View File

@ -13,7 +13,8 @@
[extract-symbols (-> any/c list?)]
[any->string (-> any/c string?)]
[stringify-variable-mapping (-> variable-mapping? string-variable-mapping?)]
[string->any (-> string? any/c)])
[string->any (-> string? any/c)]
[read-org-table (-> string? (listof any/c))])
;; Contracts
(contract-out [variable-mapping? contract?]
[string-variable-mapping? contract?])
@ -167,3 +168,7 @@
;;; Reads any value from string.
(define (string->any str)
(with-input-from-string str (λ () (read))))
;;; Reads a table from a string produced by Org-mode for a named
;;; table. See example.org for examples.
(define (read-org-table str) (string->any str))