utils: Handle Booleans when reading Org-mode tables.
This commit is contained in:
parent
cdca40eb40
commit
43a2f1aff0
2 changed files with 16 additions and 1 deletions
|
@ -45,6 +45,8 @@
|
||||||
(check-equal? (string->any "14") 14)
|
(check-equal? (string->any "14") 14)
|
||||||
(check-equal? (read-org-sexp "((\"a\" \"(and a b)\") (\"b\" \"(or b (not a))\"))")
|
(check-equal? (read-org-sexp "((\"a\" \"(and a b)\") (\"b\" \"(or b (not a))\"))")
|
||||||
'(("a" "(and a b)") ("b" "(or b (not a))")))
|
'(("a" "(and a b)") ("b" "(or b (not a))")))
|
||||||
|
(check-equal? (read-org-sexp "(#t \"#t\" \"#t \" '(1 2 \"#f\"))")
|
||||||
|
'(#t #t "#t " '(1 2 #f)))
|
||||||
(check-equal? (unstringify-pairs '(("a" . "1") ("b" . "(and a (not b))")))
|
(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? (unstringify-pairs '(("a" . 1) ("b" . "(and a (not b))")))
|
(check-equal? (unstringify-pairs '(("a" . 1) ("b" . "(and a (not b))")))
|
||||||
|
|
15
utils.rkt
15
utils.rkt
|
@ -197,9 +197,22 @@
|
||||||
(define (string->any str)
|
(define (string->any str)
|
||||||
(with-input-from-string str (λ () (read))))
|
(with-input-from-string str (λ () (read))))
|
||||||
|
|
||||||
|
;;; Given a sexp, converts all "#f" to #f and "#t" to #t.
|
||||||
|
;;;
|
||||||
|
;;; When I read Org-mode tables, I pump them through a call to the
|
||||||
|
;;; prin1 because the elisp sexp seems incompatible with Racket. On
|
||||||
|
;;; the other hand, Racket Booleans seem to upset elisp a little, so
|
||||||
|
;;; prin1 wraps them in additional double quotes. This function
|
||||||
|
;;; removes those quotes.
|
||||||
|
(define/match (handle-org-booleans datum)
|
||||||
|
[("#t") #t]
|
||||||
|
[("#f") #f]
|
||||||
|
[((? list?)) (map handle-org-booleans datum)]
|
||||||
|
[ (_) datum])
|
||||||
|
|
||||||
;;; Reads a sexp from a string produced by Org-mode for a named table.
|
;;; Reads a sexp from a string produced by Org-mode for a named table.
|
||||||
;;; See example.org for examples.
|
;;; See example.org for examples.
|
||||||
(define (read-org-sexp str) (string->any str))
|
(define read-org-sexp (compose handle-org-booleans string->any))
|
||||||
|
|
||||||
;;; A shortcut for read-org-sexp.
|
;;; A shortcut for read-org-sexp.
|
||||||
(define unorg read-org-sexp)
|
(define unorg read-org-sexp)
|
||||||
|
|
Loading…
Reference in a new issue