From patchwork Tue Aug 2 21:44:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Ludovic_Court=C3=A8s?= X-Patchwork-Id: 41105 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 8D0BA27BBEA; Tue, 2 Aug 2022 23:45:44 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 2C73227BBE9 for ; Tue, 2 Aug 2022 23:45:44 +0100 (BST) Received: from localhost ([::1]:59166 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oIziv-0002Ww-5Q for patchwork@mira.cbaines.net; Tue, 02 Aug 2022 17:46:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44430) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oIzhG-0001uZ-Vr for guix-patches@gnu.org; Tue, 02 Aug 2022 17:45:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:55555) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oIzhG-0006FP-Ls for guix-patches@gnu.org; Tue, 02 Aug 2022 17:45:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oIzhG-00039P-Hd for guix-patches@gnu.org; Tue, 02 Aug 2022 17:45:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#56898] [PATCH 03/13] read-print: Expose comment constructor. Resent-From: Ludovic =?utf-8?q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 02 Aug 2022 21:45:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 56898 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 56898@debbugs.gnu.org Cc: Ludovic =?utf-8?q?Court=C3=A8s?= Received: via spool by 56898-submit@debbugs.gnu.org id=B56898.165947667611921 (code B ref 56898); Tue, 02 Aug 2022 21:45:02 +0000 Received: (at 56898) by debbugs.gnu.org; 2 Aug 2022 21:44:36 +0000 Received: from localhost ([127.0.0.1]:45263 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oIzgq-00036A-5i for submit@debbugs.gnu.org; Tue, 02 Aug 2022 17:44:36 -0400 Received: from eggs.gnu.org ([209.51.188.92]:59540) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oIzgo-00035P-Ff for 56898@debbugs.gnu.org; Tue, 02 Aug 2022 17:44:34 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:55154) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oIzgj-00069K-8r; Tue, 02 Aug 2022 17:44:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:References:In-Reply-To:Date:Subject:To: From; bh=DQrNEpRA+D4vdxEMPHELwxrZ1zYQ3SRn8KONX4CeXhw=; b=V/tod+9XzrH/46tDdYfu BQYauYJRTu0gFrtVvtNkRi9L3SlyNLL/0jmebT1em7DCx+D0j8KvFVXtEwOWQbvhYGRWIsdvBILJP Zg3I8Ry6ey22h15L+Eb5xM8lhK9IEonNqERQzBEuCnn11OeOxOjrxVZ0toiCpMPlYCVEFeQ8xsgIR uOCZa2jxRqVXmK44BNPpG5hDrELHJeb7Y0VMlKijY9ITK6cK0c50xDBFKwrjpaQahDnXElj+qZHVl nb17YfnM9pxAyAAclnz/anrNOoXscAuunsucpPZnxgT2vljop7fpjUi0fHFpzt0811npCpLtZyVK1 9HqjbqvC1svWDQ==; Received: from 91-160-117-201.subs.proxad.net ([91.160.117.201]:52235 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oIzgi-0006W4-Sx; Tue, 02 Aug 2022 17:44:29 -0400 From: Ludovic =?utf-8?q?Court=C3=A8s?= Date: Tue, 2 Aug 2022 23:44:09 +0200 Message-Id: <20220802214419.19013-3-ludo@gnu.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220802214419.19013-1-ludo@gnu.org> References: <20220802214419.19013-1-ludo@gnu.org> MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * guix/read-print.scm (): Rename constructor to 'string->comment'. (comment): New procedure. (read-with-comments, canonicalize-comment): Use 'string->comment' instead of 'comment'. --- guix/read-print.scm | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/guix/read-print.scm b/guix/read-print.scm index 949a713ca2..5281878504 100644 --- a/guix/read-print.scm +++ b/guix/read-print.scm @@ -23,10 +23,13 @@ (define-module (guix read-print) #: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* + comment comment? comment->string comment-margin? @@ -46,11 +49,22 @@ (define-module (guix read-print) ;; A comment. (define-record-type - (comment str margin?) + (string->comment str margin?) comment? (str comment->string) (margin? comment-margin?)) +(define* (comment str #:optional margin?) + "Return a new comment made from STR. When MARGIN? is true, return a margin +comment; otherwise return a line comment. STR must start with a semicolon and +end with newline, otherwise an error is raised." + (when (or (string-null? str) + (not (eqv? #\; (string-ref str 0))) + (not (string-suffix? "\n" str))) + (raise (condition + (&message (message "invalid comment string"))))) + (string->comment str margin?)) + (define (read-with-comments port) "Like 'read', but include objects when they're encountered." ;; Note: Instead of implementing this functionality in 'read' proper, which @@ -106,8 +120,8 @@ (define (reverse/dot lst) (loop #f return))) ((eqv? chr #\;) (unread-char chr port) - (comment (read-line port 'concat) - (not blank-line?))) + (string->comment (read-line port 'concat) + (not blank-line?))) (else (unread-char chr port) (match (read port) @@ -256,14 +270,14 @@ (define (canonicalize-comment c) semicolons." (let ((line (string-trim-both (string-trim (comment->string c) (char-set #\;))))) - (comment (string-append - (if (comment-margin? c) - ";" - (if (string-null? line) - ";;" ;no trailing space - ";; ")) - line "\n") - (comment-margin? c)))) + (string->comment (string-append + (if (comment-margin? c) + ";" + (if (string-null? line) + ";;" ;no trailing space + ";; ")) + line "\n") + (comment-margin? c)))) (define* (pretty-print-with-comments port obj #:key