From: "Ludovic Courtès" <ludo@gnu.org>
To: 56898@debbugs.gnu.org
Cc: "Ludovic Courtès" <ludo@gnu.org>
Subject: [bug#56898] [PATCH 04/13] read-print: Introduce <blank> parent class of <comment>.
Date: Tue, 2 Aug 2022 23:44:10 +0200 [thread overview]
Message-ID: <20220802214419.19013-4-ludo@gnu.org> (raw)
In-Reply-To: <20220802214419.19013-1-ludo@gnu.org>
* guix/read-print.scm (<blank>, blank?): New record type.
(<comment>): Redefine using the record interface.
(read-with-comments, pretty-print-with-comments): Change some uses of
'comment?' to 'blank?'.
* guix/scripts/style.scm (simplify-inputs)[simplify-expressions]: Use
'blank?' instead of 'comment?'.
---
guix/read-print.scm | 37 ++++++++++++++++++++++++++-----------
guix/scripts/style.scm | 2 +-
2 files changed, 27 insertions(+), 12 deletions(-)
diff --git a/guix/read-print.scm b/guix/read-print.scm
index 5281878504..732d0dc1f8 100644
--- a/guix/read-print.scm
+++ b/guix/read-print.scm
@@ -22,13 +22,14 @@ (define-module (guix read-print)
#:use-module (ice-9 rdelim)
#:use-module (ice-9 vlist)
#:use-module (srfi srfi-1)
- #:use-module (srfi srfi-9)
#:use-module (srfi srfi-34)
#:use-module (srfi srfi-35)
#:export (pretty-print-with-comments
read-with-comments
object->string*
+ blank?
+
comment
comment?
comment->string
@@ -47,12 +48,26 @@ (define-module (guix read-print)
;;; Comment-preserving reader.
;;;
-;; A comment.
-(define-record-type <comment>
- (string->comment str margin?)
- comment?
- (str comment->string)
- (margin? comment-margin?))
+(define <blank>
+ ;; The parent class for "blanks".
+ (make-record-type '<blank> '()
+ (lambda (obj port)
+ (format port "#<blank ~a>"
+ (number->string (object-address obj) 16)))
+ #:extensible? #t))
+
+(define blank? (record-predicate <blank>))
+
+(define <comment>
+ ;; Comments.
+ (make-record-type '<comment> '(str margin?)
+ #:parent <blank>
+ #:extensible? #f))
+
+(define comment? (record-predicate <comment>))
+(define string->comment (record-type-constructor <comment>))
+(define comment->string (record-accessor <comment> 'str))
+(define comment-margin? (record-accessor <comment> 'margin?))
(define* (comment str #:optional margin?)
"Return a new comment made from STR. When MARGIN? is true, return a margin
@@ -66,7 +81,7 @@ (define* (comment str #:optional margin?)
(string->comment str margin?))
(define (read-with-comments port)
- "Like 'read', but include <comment> objects when they're encountered."
+ "Like 'read', but include <blank> objects when they're encountered."
;; Note: Instead of implementing this functionality in 'read' proper, which
;; is the best approach long-term, this code is a layer on top of 'read',
;; such that we don't have to rely on a specific Guile version.
@@ -99,7 +114,7 @@ (define (reverse/dot lst)
(let/ec return
(let liip ((lst '()))
(liip (cons (loop (match lst
- (((? comment?) . _) #t)
+ (((? blank?) . _) #t)
(_ #f))
(lambda ()
(return (reverse/dot lst))))
@@ -327,7 +342,7 @@ (define newline?
(and (keyword? item)
(not (eq? item #:allow-other-keys))))
(not first?) (not delimited?)
- (not (comment? item))))
+ (not (blank? item))))
(when newline?
(newline port)
@@ -335,7 +350,7 @@ (define newline?
(let ((column (if newline? indent column)))
(print tail
(keyword? item) ;keep #:key value next to one another
- (comment? item)
+ (blank? item)
(loop indent column
(or newline? delimited?)
context
diff --git a/guix/scripts/style.scm b/guix/scripts/style.scm
index e2530e80c0..5c0ecc0896 100644
--- a/guix/scripts/style.scm
+++ b/guix/scripts/style.scm
@@ -108,7 +108,7 @@ (define (simplify-expressions exp inputs return)
(exp exp)
(inputs inputs))
(match exp
- (((? comment? head) . rest)
+ (((? blank? head) . rest)
(loop (cons head result) rest inputs))
((head . rest)
(match inputs
--
2.37.1
next prev parent reply other threads:[~2022-08-02 21:45 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-02 21:42 [bug#56898] [PATCH 00/13] Put the pretty printer to good use Ludovic Courtès
2022-08-02 21:44 ` [bug#56898] [PATCH 01/13] style: Move reader and printer to (guix read-print) Ludovic Courtès
2022-08-02 21:44 ` [bug#56898] [PATCH 02/13] read-print: Add System and Home special forms Ludovic Courtès
2022-08-02 21:44 ` [bug#56898] [PATCH 03/13] read-print: Expose comment constructor Ludovic Courtès
2022-08-02 21:44 ` Ludovic Courtès [this message]
2022-08-02 21:44 ` [bug#56898] [PATCH 05/13] style: Adjust test to not emit blank lines Ludovic Courtès
2022-08-02 21:44 ` [bug#56898] [PATCH 06/13] read-print: Read and render vertical space Ludovic Courtès
2022-08-02 21:44 ` [bug#56898] [PATCH 07/13] read-print: Recognize page breaks Ludovic Courtès
2022-08-02 21:44 ` [bug#56898] [PATCH 08/13] read-print: Add code to read and write sequences of expressions/blanks Ludovic Courtès
2022-08-02 21:44 ` [bug#56898] [PATCH 09/13] read-print: 'canonicalize-comment' leaves top-level comments unchanged Ludovic Courtès
2022-08-02 21:44 ` [bug#56898] [PATCH 10/13] style: Add '--whole-file' option Ludovic Courtès
2022-08-02 21:44 ` [bug#56898] [PATCH 11/13] read-print: Support printing multi-line comments Ludovic Courtès
2022-08-02 21:44 ` [bug#56898] [PATCH 12/13] installer: Render the final configuration with (guix read-print) Ludovic Courtès
2022-08-02 21:44 ` [bug#56898] [PATCH 13/13] installer: Add comments and vertical space to the generated config Ludovic Courtès
2022-08-07 10:50 ` [bug#56898] [PATCH 00/13] Put the pretty printer to good use Mathieu Othacehe
2022-08-07 20:18 ` Ludovic Courtès
2022-08-09 9:42 ` bug#56898: " Ludovic Courtès
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220802214419.19013-4-ludo@gnu.org \
--to=ludo@gnu.org \
--cc=56898@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/guix.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).