From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id wBNLO0ib6WIjdwAAbAwnHQ (envelope-from ) for ; Tue, 02 Aug 2022 23:46:49 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id SNNYO0ib6WKUSAAA9RJhRA (envelope-from ) for ; Tue, 02 Aug 2022 23:46:48 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 8B9013D52B for ; Tue, 2 Aug 2022 23:46:48 +0200 (CEST) Received: from localhost ([::1]:59166 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oIzix-0002Ww-PR for larch@yhetil.org; Tue, 02 Aug 2022 17:46:47 -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 Content-Transfer-Encoding: 8bit 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+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1659476808; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=DQrNEpRA+D4vdxEMPHELwxrZ1zYQ3SRn8KONX4CeXhw=; b=n4BrMvRe6iTzKK0j/4c8oiW2E1fuMD0pi8jHYT40xRmnY1OGFccx7Nndlm/VpyiT8X9Of+ PmVL13IsadeV3TWuKN0t9Ek6hhG5ZsA1tLDpda7wpYhln1iv2eQPUoFr97qWw4LT3NmkL/ HuotP2Bf/qx3raP+Nqm6eTXK0Qjt4T+8xUkjVxkU0ljKQwvoQzCwh9u9kjQJMURjDQ0isz LXrrC1lMVM27b3tpPvJT1vCeuYIdQyE7U81LNgm1Rq4sv1jmmz65cLU4OCMPMlv92rh8et 3ZDyOF9GOWcgumluypjdioHxJb8KPXw9bsL60SmMt7/3IEiWuHvfkb6nm+QFGQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1659476808; a=rsa-sha256; cv=none; b=QpsQ9qo/OXN+StzHMMzpSmLU6Xv6oBEAb0t2xwP/7Is+uQmhz2Bs5zSVyhYe7KyyZcFrF8 3R3V8MU/XmYN7f40wvMlVzjfLT+1UfLXjwHgguXHXqUZdIgzkBZ7THpbEG61Sl/AUryh9A 0Q6wZkTX4AQbHIZQIxGvZ674AfQ7YxdS31BPMIQweIh2jmI9z+19byNKECGnDRIdezusNL 18KthpNT2QR3S+NyLccwn+lBr9LhlA0o8ZRc2dL+LibGsUGNfyM4wg/7nd3pHEgEKs4ga0 JRE9I0c2aITjIuT6vZI3ExG7yz2yoQ1YYbhDARvh85bJepZsmpomN4SmtaOlhg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b="V/tod+9X"; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -2.82 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b="V/tod+9X"; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 8B9013D52B X-Spam-Score: -2.82 X-Migadu-Scanner: scn0.migadu.com X-TUID: AIr0lLKCcl6u * 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 -- 2.37.1