From: Saku Laesvuori via Guix-patches via <guix-patches@gnu.org>
To: 67564@debbugs.gnu.org
Cc: Saku Laesvuori <saku@laesvuori.fi>, Lars-Dominik Braun <lars@6xq.net>
Subject: [bug#67564] [PATCH 3/3] guix: import: Parse cabal layout blocks correctly
Date: Fri, 1 Dec 2023 11:29:48 +0200 [thread overview]
Message-ID: <541836669e170dcef15c5e73a5413592d3fbcc25.1701422983.git.saku@laesvuori.fi> (raw)
In-Reply-To: <1e1cc11c9361ab747435c2159355d14f6046d41d.1701422983.git.saku@laesvuori.fi>
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 <parse-context> 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
- ;; <parse-context> 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
next prev parent reply other threads:[~2023-12-01 9:32 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-01 9:24 [bug#67564] [PATCH 0/3] Fixes for haskell importers Saku Laesvuori via Guix-patches via
2023-12-01 9:29 ` [bug#67564] [PATCH 1/3] guix: import: hackage: Fix crash on recursive import Saku Laesvuori via Guix-patches via
2023-12-01 9:29 ` [bug#67564] [PATCH 2/3] guix: import: stackage: " Saku Laesvuori via Guix-patches via
2023-12-01 9:29 ` Saku Laesvuori via Guix-patches via [this message]
2023-12-01 15:06 ` [bug#67564] [PATCH 0/3] Fixes for haskell importers Lars-Dominik Braun
2023-12-02 17:27 ` Saku Laesvuori via Guix-patches via
2023-12-03 8:13 ` bug#67564: " Lars-Dominik Braun
2023-12-02 17:23 ` [bug#67564] [PATCH v2 1/3] guix: import: hackage: Fix crash on recursive import Saku Laesvuori via Guix-patches via
2023-12-02 17:23 ` [bug#67564] [PATCH v2 2/3] guix: import: stackage: " Saku Laesvuori via Guix-patches via
2023-12-02 17:23 ` [bug#67564] [PATCH v2 3/3] guix: import: Parse cabal layout blocks correctly Saku Laesvuori via Guix-patches via
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=541836669e170dcef15c5e73a5413592d3fbcc25.1701422983.git.saku@laesvuori.fi \
--to=guix-patches@gnu.org \
--cc=67564@debbugs.gnu.org \
--cc=lars@6xq.net \
--cc=saku@laesvuori.fi \
/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).