[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
02/03: read-print: 'read-with-comments' reads comments within gexps.
From: |
guix-commits |
Subject: |
02/03: read-print: 'read-with-comments' reads comments within gexps. |
Date: |
Thu, 16 Mar 2023 18:04:28 -0400 (EDT) |
civodul pushed a commit to branch master
in repository guix.
commit 83128f00e9149f3c1bcd4450eb0ed3620a37149c
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Thu Mar 16 22:18:52 2023 +0100
read-print: 'read-with-comments' reads comments within gexps.
Fixes <https://issues.guix.gnu.org/62059>.
Reported by Maxim Cournoyer <maxim.cournoyer@gmail.com>.
* guix/read-print.scm (read-with-comments): Special-case #~, #$, and #+.
* tests/read-print.scm: Add two tests.
---
guix/read-print.scm | 21 +++++++++++++++++++++
tests/read-print.scm | 15 +++++++++++++++
2 files changed, 36 insertions(+)
diff --git a/guix/read-print.scm b/guix/read-print.scm
index fdc85c2693..515eb7669c 100644
--- a/guix/read-print.scm
+++ b/guix/read-print.scm
@@ -219,6 +219,27 @@ BLANK-LINE? is true, assume PORT is at the beginning of a
new line."
(list 'quote (loop #f return)))
((eq? chr #\`)
(list 'quasiquote (loop #f return)))
+ ((eq? chr #\#)
+ (match (read-char port)
+ (#\~ (list 'gexp (loop #f return)))
+ (#\$ (list (match (peek-char port)
+ (#\@
+ (read-char port) ;consume
+ 'ungexp-splicing)
+ (_
+ 'ungexp))
+ (loop #f return)))
+ (#\+ (list (match (peek-char port)
+ (#\@
+ (read-char port) ;consume
+ 'ungexp-native-splicing)
+ (_
+ 'ungexp-native))
+ (loop #f return)))
+ (chr
+ (unread-char chr port)
+ (unread-char #\# port)
+ (read port))))
((eq? chr #\,)
(list (match (peek-char port)
(#\@
diff --git a/tests/read-print.scm b/tests/read-print.scm
index 952b3e6585..f4627e076a 100644
--- a/tests/read-print.scm
+++ b/tests/read-print.scm
@@ -231,6 +231,21 @@ mnopqrstuvwxyz.\")"
;; Regular indentation for 'replace' here.
(replace \"gmp\" gmp))")
+(test-pretty-print "\
+#~(modify-phases phases
+ (add-after 'whatever 'something-else
+ (lambda _
+ ;; This comment appears inside a gexp.
+ 42)))")
+
+(test-pretty-print "\
+#~(list #$@(list coreutils ;yup
+ grep) ;margin comment
+ #+sed
+
+ ;; Line comment.
+ #$grep)")
+
(test-pretty-print "\
(package
;; Here 'sha256', 'base32', and 'arguments' must be