diff options
author | Ludovic Courtès <ludo@gnu.org> | 2021-07-18 16:05:21 +0200 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2021-07-18 19:50:01 +0200 |
commit | 0e47fcced442d8e7c1b05184fdc1c14f10ed04ec (patch) | |
tree | 4ae844bc0ec3c670f8697bdc24362c122fa718ad /guix/gexp.scm | |
parent | e4b70bc55a538569465bcedee19d1f2607308e65 (diff) | |
parent | 8b1bde7bb3936a64244824500ffe60f123704437 (diff) |
Merge branch 'master' into core-updates
Diffstat (limited to 'guix/gexp.scm')
-rw-r--r-- | guix/gexp.scm | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/guix/gexp.scm b/guix/gexp.scm index 3d8c2b9341..ff5ede2857 100644 --- a/guix/gexp.scm +++ b/guix/gexp.scm @@ -4,6 +4,7 @@ ;;; Copyright © 2018 Jan Nieuwenhuizen <janneke@gnu.org> ;;; Copyright © 2019, 2020 Mathieu Othacehe <m.othacehe@gmail.com> ;;; Copyright © 2020 Maxim Cournoyer <maxim.cournoyer@gmail.com> +;;; Copyright © 2021 Maxime Devos <maximedevos@telenet.be> ;;; ;;; This file is part of GNU Guix. ;;; @@ -43,6 +44,7 @@ with-imported-modules with-extensions let-system + gexp->approximate-sexp gexp-input gexp-input? @@ -163,6 +165,23 @@ "Return the source code location of GEXP." (and=> (%gexp-location gexp) source-properties->location)) +(define* (gexp->approximate-sexp gexp) + "Return the S-expression corresponding to GEXP, but do not lower anything. +As a result, the S-expression will be approximate if GEXP has references." + (define (gexp-like? thing) + (or (gexp? thing) (gexp-input? thing))) + (apply (gexp-proc gexp) + (map (lambda (reference) + (match reference + (($ <gexp-input> thing output native) + (if (gexp-like? thing) + (gexp->approximate-sexp thing) + ;; Simply returning 'thing' won't work in some + ;; situations; see 'write-gexp' below. + '(*approximate*))) + (_ '(*approximate*)))) + (gexp-references gexp)))) + (define (write-gexp gexp port) "Write GEXP on PORT." (display "#<gexp " port) @@ -2065,6 +2084,7 @@ This is the declarative counterpart of 'text-file*'." (define build (gexp (call-with-output-file (ungexp output "out") (lambda (port) + (set-port-encoding! port "UTF-8") (display (string-append (ungexp-splicing text)) port))))) (computed-file name build)) |