utils: Add scm->kdl-string, scm->kdlv1-string, kdl-file and kdlv1-file.

This commit is contained in:
Hilton Chain committed 2026-08-14 05:17:36 +08:00
1 parent ecdb930021
commit 6e28a0825b
2 files changed
+116

No files matched your search

+30
View File
@@ -16,6 +16,8 @@
ini-file
json-file
kdl-file
kdlv1-file
toml-file
yaml-file))
@@ -94,6 +96,34 @@
(cut scm->json '#$exp <> #:pretty #t)))))
#:options '(#:substitutable? #f)))
(define (kdl-file name exp)
(computed-file name
(with-imported-modules '((rosenthal utils kdl))
(if (gexp? exp)
#~(begin
(use-modules (srfi srfi-26) (rosenthal utils kdl))
(call-with-output-file #$output
(cut display (scm->kdl-string #$exp) <>)))
#~(begin
(use-modules (srfi srfi-26) (rosenthal utils kdl))
(call-with-output-file #$output
(cut display (scm->kdl-string '#$exp) <>)))))
#:options '(#:substitutable? #f)))
(define (kdlv1-file name exp)
(computed-file name
(with-imported-modules '((rosenthal utils kdl))
(if (gexp? exp)
#~(begin
(use-modules (srfi srfi-26) (rosenthal utils kdl))
(call-with-output-file #$output
(cut display (scm->kdlv1-string #$exp) <>)))
#~(begin
(use-modules (srfi srfi-26) (rosenthal utils kdl))
(call-with-output-file #$output
(cut display (scm->kdlv1-string '#$exp) <>)))))
#:options '(#:substitutable? #f)))
;; https://github.com/hylophile/guile-toml
;; TODO: TOML writing support is incomplete.
;; See https://github.com/hylophile/guile-toml/blob/main/toml/builder.scm.