From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms8.migadu.com with LMTPS id qOSxDC2oaWV5HAAAG6o9tA:P1 (envelope-from ) for ; Fri, 01 Dec 2023 10:32:29 +0100 Received: from aspmx1.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id qOSxDC2oaWV5HAAAG6o9tA (envelope-from ) for ; Fri, 01 Dec 2023 10:32:29 +0100 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 B9FBA38B2B for ; Fri, 1 Dec 2023 10:32:28 +0100 (CET) Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=laesvuori.fi header.s=mail header.b=T2QsP9pM; 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" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1701423149; h=from:from:sender:sender:reply-to: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=Y+mj2RbYmGSJjdRnrivqH77b27kXSnh5loDtNLyd/sY=; b=OjHyGUiy6U5wNbqx+8A6aoTo7SYU/np61poskYnia/rr+mwt/TO9z3JTeO1iNr/jEUqrKw +Q2UZyBWNLT5SBUgcQE1wVgf3SBdEj+a5S8rwdMNn1kiRMPifBMFmWMnwW2TbsQcfUXOqz zQQxvFkNiH2guIrVAG2yzD61Dw7qfuLaelHYaUEYG03U74cnJn4UI3CZrl4w7NX72ckBNb YDEmaV0G1wtdHmP4xBqT6XhUToEQ5197zYp6+tw0tNxn84vym1rNMucnbwnQS1fGUy/wZj WZfhX4ISruf7UriiIq+owHn3L3cCr0LKpm8q99gCdpFL/Oja3gPBHPiR6pLW8A== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1701423149; a=rsa-sha256; cv=none; b=ENi22FE9VHLQa7IozR+7uHXGAVLft4244OxsaLSUtTR1fk4qTYWiXSksMW+0vzTTPoUAnm s/CA7SMoAKVn3jf/lcTfNLIz+BzeeSGChcweV59J0sGHDlf51vADorgkhO90DcQy57UF7c 3BopFlhEG+nf0LFX98Z7S8cCI8JRalO5EAJFiqbC01WsuZyNm0E7w02YGUkduOvqkEFTxO K9mBBQ4h33lTTnmI38CQpWBGp9tUO32uojHa9HM7FvwhiDCajCDtu3T51yCDXHu0fLzw7c Qk5C1P1c37mYFpPcEJ3Gl71IVM6XloP146vBHc8HHDbAVl503Drf+Jgs75O7vw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=laesvuori.fi header.s=mail header.b=T2QsP9pM; 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" Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r8zsN-0002M1-1o; Fri, 01 Dec 2023 04:31:59 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r8zsJ-0002Jt-3K for guix-patches@gnu.org; Fri, 01 Dec 2023 04:31:55 -0500 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r8zsI-0007Yl-ES for guix-patches@gnu.org; Fri, 01 Dec 2023 04:31:54 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1r8zsR-0008Ls-0K; Fri, 01 Dec 2023 04:32:03 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#67564] [PATCH 3/3] guix: import: Parse cabal layout blocks correctly Resent-From: Saku Laesvuori Original-Sender: "Debbugs-submit" Resent-CC: lars@6xq.net, guix-patches@gnu.org Resent-Date: Fri, 01 Dec 2023 09:32:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 67564 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 67564@debbugs.gnu.org Cc: Saku Laesvuori , Lars-Dominik Braun X-Debbugs-Original-Xcc: Lars-Dominik Braun Received: via spool by 67564-submit@debbugs.gnu.org id=B67564.170142308632046 (code B ref 67564); Fri, 01 Dec 2023 09:32:02 +0000 Received: (at 67564) by debbugs.gnu.org; 1 Dec 2023 09:31:26 +0000 Received: from localhost ([127.0.0.1]:55090 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r8zrp-0008Kn-Vo for submit@debbugs.gnu.org; Fri, 01 Dec 2023 04:31:26 -0500 Received: from vmi571514.contaboserver.net ([75.119.130.101]:45130 helo=mail.laesvuori.fi) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r8zro-0008Kf-Bl for 67564@debbugs.gnu.org; Fri, 01 Dec 2023 04:31:24 -0500 Received: from X-kone.org.aalto.fi (unknown [130.233.144.61]) by mail.laesvuori.fi (Postfix) with ESMTPSA id 38BAA340103; Fri, 1 Dec 2023 10:31:16 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=laesvuori.fi; s=mail; t=1701423076; bh=3hcxiB02MU/TpYxdH8n+9sIJfpDv6n3meccA95np8RA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=T2QsP9pMoI5B2G67bBoY20iIyKJJRrMjqGfJ5eEVUsoZgLNwdc8SD0wyNpsB9wOhz KrX+dr2ebq+Jhxrb7pRpJYO7A8SITwNOvXqKmvdPyNkcCECqgpzimkKZwaFahSZQtA KVAGP1DQn4T2F4ygcAeDuoJBYFpOyJhBdXLXCqhw= Date: Fri, 1 Dec 2023 11:29:48 +0200 Message-ID: <541836669e170dcef15c5e73a5413592d3fbcc25.1701422983.git.saku@laesvuori.fi> X-Mailer: git-send-email 2.41.0 In-Reply-To: <1e1cc11c9361ab747435c2159355d14f6046d41d.1701422983.git.saku@laesvuori.fi> References: <1e1cc11c9361ab747435c2159355d14f6046d41d.1701422983.git.saku@laesvuori.fi> 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: , Reply-to: Saku Laesvuori X-ACL-Warn: , Saku Laesvuori via Guix-patches From: Saku Laesvuori via Guix-patches via Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN X-Migadu-Scanner: mx11.migadu.com X-Migadu-Spam-Score: -6.14 X-Spam-Score: -6.14 X-Migadu-Queue-Id: B9FBA38B2B X-TUID: VTvieGHNft+5 Cabal consideres lines to be part of a layout block if they are indented at least one space more than the field line the block belongs to. Previously Guix considered lines to be a part of the block if they were indented at least as much as the first line in it. This also makes a workaround that enabled if statements to have multiple elses redundant and removes it. Fixes: https://issues.guix.gnu.org/35743 * guix/import/cabal.scm (current-indentation*): Renamed from current-indentation. (previous-indentation, current-indentation): New variables. (make-cabal-parser): Remove outdated comment. [open]: Use previous-indentation + 1 instead of current-indentation. [elif-else]: Split to elif and else to allow only one ELSE in an if statement. (read-cabal)[parameterize]: Use current-indentation* and previous-indentation. Change-Id: I3a1495b1588a022fabbfe8dad9f3231e578af4f3 --- Fixed packages include conduit and warp, for example. guix/import/cabal.scm | 42 +++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/guix/import/cabal.scm b/guix/import/cabal.scm index fe03c30254..b969197455 100644 --- a/guix/import/cabal.scm +++ b/guix/import/cabal.scm @@ -130,8 +130,17 @@ (define (context-stack-pop!) ((context-stack) 'pop!)) (define (context-stack-clear!) ((context-stack) 'clear!)) -;; Indentation of the line being parsed. -(define current-indentation (make-parameter 0)) +;; Indentation of the line being parsed and that of the previous line. +(define current-indentation* (make-parameter 0)) + +(define previous-indentation (make-parameter 0)) + +(define* (current-indentation #:optional value) + (if value + (begin + (previous-indentation (current-indentation*)) + (current-indentation* value)) + (current-indentation*))) ;; Signal to reprocess the beginning of line, in case we need to close more ;; than one indentation level. @@ -196,27 +205,13 @@ (define (make-cabal-parser) (exprs elif-else) : (append $1 (list ($2 '(())))) (elif-else) : (list ($1 '(())))) ;; LALR(1) parsers prefer to be left-recursive, which make if-statements slightly involved. - ;; XXX: This technically allows multiple else statements. - (elif-else (elif-else ELIF tests OCURLY exprs CCURLY) : (lambda (y) ($1 (list (append (list 'if $3 $5) y)))) - (elif-else ELIF tests open exprs close) : (lambda (y) ($1 (list (append (list 'if $3 $5) y)))) - (elif-else ELSE OCURLY exprs CCURLY) : (lambda (y) ($1 (list $4))) - ;; The 'open' token after 'tests' is shifted after an 'exprs' - ;; is found. This is because, instead of 'exprs' a 'OCURLY' - ;; token is a valid alternative. For this reason, 'open' - ;; pushes a with a line indentation equal to - ;; the indentation of 'exprs'. - ;; - ;; Differently from this, without the rule above this - ;; comment, when an 'ELSE' token is found, the 'open' token - ;; following the 'ELSE' would be shifted immediately, before - ;; the 'exprs' is found (because there are no other valid - ;; tokens). The 'open' would therefore create a - ;; with the indentation of 'ELSE' and not - ;; 'exprs', creating an inconsistency. We therefore allow - ;; mixed style conditionals. - (elif-else ELSE open exprs close) : (lambda (y) ($1 (list $4))) + (elif (elif ELIF tests OCURLY exprs CCURLY) : (lambda (y) ($1 (list (append (list 'if $3 $5) y)))) + (elif ELIF tests open exprs close) : (lambda (y) ($1 (list (append (list 'if $3 $5) y)))) ;; Terminating rule. (if-then) : (lambda (y) (append $1 y))) + (elif-else (elif ELSE OCURLY exprs CCURLY) : (lambda (y) ($1 (list $4))) + (elif ELSE open exprs close) : (lambda (y) ($1 (list $4))) + (elif) : $1) (if-then (IF tests OCURLY exprs CCURLY) : (list 'if $2 $4) (IF tests open exprs close) : (list 'if $2 $4)) (tests (TEST OPAREN ID CPAREN) : `(,$1 ,$3) @@ -237,7 +232,7 @@ (define (make-cabal-parser) (OPAREN tests CPAREN) : $2) (open () : (context-stack-push! (make-parse-context (context layout) - (current-indentation)))) + (+ 1 (previous-indentation))))) (close (VCCURLY)))) (define (peek-next-line-indent port) @@ -655,7 +650,8 @@ (define* (read-cabal #:optional (port (current-input-port)) (let ((cabal-parser (make-cabal-parser))) (parameterize ((cabal-file-name (or file-name (port-filename port) "standard input")) - (current-indentation 0) + (current-indentation* 0) + (previous-indentation 0) (check-bol? #f) (context-stack (make-stack))) (cabal-parser (make-lexer port) (errorp))))) -- 2.41.0