utils.rkt: Copy read-org-sexp and unorg.
This commit is contained in:
parent
f80dc7f28e
commit
5943e2f6c7
3 changed files with 30 additions and 3 deletions
|
@ -169,6 +169,19 @@ violation for func will be generated.
|
|||
@examples[#:eval utils-evaluator
|
||||
(map-sexp (λ (x) (add1 (cast x Number))) '(1 2 (4 10) 3))
|
||||
]}
|
||||
|
||||
@defproc*[([(read-org-sexp [str String]) Any]
|
||||
[(unorg [str String]) Any])]{
|
||||
|
||||
Reads a @racket[sexp] from a string produced by Org-mode for a named table.
|
||||
|
||||
@racket[unorg] is a shortcut for @racket[read-org-sexp].
|
||||
|
||||
@examples[#:eval utils-evaluator
|
||||
(unorg "(#t \"#t\" \"#t \" '(1 2 \"#f\"))")
|
||||
]}
|
||||
|
||||
|
||||
@section{Additional graph utilities}
|
||||
|
||||
@section{Pretty printing}
|
||||
|
|
|
@ -10,9 +10,7 @@
|
|||
|
||||
(provide
|
||||
;; Functions
|
||||
(contract-out [read-org-sexp (-> string? (listof any/c))]
|
||||
[unorg (-> string? (listof any/c))]
|
||||
[unstringify-pairs (-> (listof (general-pair/c string? any/c))
|
||||
(contract-out [unstringify-pairs (-> (listof (general-pair/c string? any/c))
|
||||
(listof (general-pair/c symbol? any/c)))]
|
||||
[read-org-variable-mapping (-> string? variable-mapping?)]
|
||||
[unorgv (-> string? variable-mapping?)]
|
||||
|
|
16
utils.rkt
16
utils.rkt
|
@ -6,6 +6,7 @@
|
|||
eval-with eval1-with
|
||||
extract-symbols
|
||||
any->string stringify-variable-mapping string->any map-sexp
|
||||
read-org-sexp unorg
|
||||
;; Syntax
|
||||
auto-hash-ref/explicit auto-hash-ref/:)
|
||||
|
||||
|
@ -185,3 +186,18 @@
|
|||
(test-case "map-sexp"
|
||||
(check-equal? (map-sexp (λ (x) (add1 (cast x Number))) '(1 2 (4 10) 3))
|
||||
'(2 3 (5 11) 4))))
|
||||
|
||||
(: read-org-sexp (-> String Any))
|
||||
(define read-org-sexp
|
||||
(compose ((curry map-sexp) (match-lambda
|
||||
[(and (? string?) str) (string->any str)]
|
||||
[x x]))
|
||||
string->any))
|
||||
(define unorg read-org-sexp)
|
||||
|
||||
(module+ test
|
||||
(test-case "read-org-sexp"
|
||||
(check-equal? (read-org-sexp "((\"a\" \"(and a b)\") (\"b\" \"(or b (not a))\"))")
|
||||
'((a (and a b)) (b (or b (not a)))))
|
||||
(check-equal? (unorg "(#t \"#t\" \"#t \" '(1 2 \"#f\"))")
|
||||
'(#t #t #t '(1 2 #f)))))
|
||||
|
|
Loading…
Reference in a new issue