all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Xinglu Chen <public@yoctocell.xyz>
To: 50588@debbugs.gnu.org
Subject: [bug#50588] [PATCH] import: cabal: Treat identifier names correctly.
Date: Tue, 14 Sep 2021 20:42:18 +0200	[thread overview]
Message-ID: <e59de83e96791b6c861dab2946ffc09ab988927b.1631644779.git.public@yoctocell.xyz> (raw)

* guix/import/cabal.scm (is-id): Accept the location as an argument.  Don’t
check if the identifier name is a reserved keyword unless it is the first word
on the line.
(lex-word): Adjust accordingly.
* tests/hackage ("hackage->guix-package tests flag executable"): Expect it to
pass.

Fixes: <https://issues.guix.gnu.org/25138>
---
‘guix import hackage darcs’ now works correctly, and it fixes a
five year old bug.  :-)

--8<---------------cut here---------------start------------->8---
$ ./pre-inst-env guix import hackage darcs
(package
  (name "ghc-darcs")
  (version "2.16.4")
  (source
    (origin
      (method url-fetch)
      (uri (string-append
             "https://hackage.haskell.org/package/darcs/darcs-"
             version
             ".tar.gz"))
      (sha256
        (base32
          "07dygwh6p4fsrlgxmq6r7yvxmf4n2y04izzd30jzqgs0pi9645p4"))))
  (build-system haskell-build-system)
  (inputs
    `(("ghc-regex-compat-tdfa" ,ghc-regex-compat-tdfa)
      ("ghc-regex-applicative" ,ghc-regex-applicative)
      ("ghc-fgl" ,ghc-fgl)
      ("ghc-html" ,ghc-html)
      ("ghc-memory" ,ghc-memory)
      ("ghc-cryptonite" ,ghc-cryptonite)
      ("ghc-base16-bytestring" ,ghc-base16-bytestring)
      ("ghc-utf8-string" ,ghc-utf8-string)
      ("ghc-vector" ,ghc-vector)
      ("ghc-tar" ,ghc-tar)
      ("ghc-data-ordlist" ,ghc-data-ordlist)
      ("ghc-attoparsec" ,ghc-attoparsec)
      ("ghc-zip-archive" ,ghc-zip-archive)
      ("ghc-async" ,ghc-async)
      ("ghc-constraints" ,ghc-constraints)
      ("ghc-unix-compat" ,ghc-unix-compat)
      ("ghc-old-time" ,ghc-old-time)
      ("ghc-temporary" ,ghc-temporary)
      ("ghc-hashable" ,ghc-hashable)
      ("ghc-mmap" ,ghc-mmap)
      ("ghc-zlib" ,ghc-zlib)
      ("ghc-network-uri" ,ghc-network-uri)
      ("ghc-network" ,ghc-network)
      ("ghc-conduit" ,ghc-conduit)
      ("ghc-http-conduit" ,ghc-http-conduit)
      ("ghc-http-types" ,ghc-http-types)))
  (native-inputs
    `(("ghc-cmdargs" ,ghc-cmdargs)
      ("ghc-findbin" ,ghc-findbin)
      ("ghc-quickcheck" ,ghc-quickcheck)
      ("ghc-leancheck" ,ghc-leancheck)
      ("ghc-hunit" ,ghc-hunit)
      ("ghc-test-framework" ,ghc-test-framework)
      ("ghc-test-framework-hunit"
       ,ghc-test-framework-hunit)
      ("ghc-test-framework-quickcheck2"
       ,ghc-test-framework-quickcheck2)
      ("ghc-test-framework-leancheck"
       ,ghc-test-framework-leancheck)
      ("ghc-exceptions" ,ghc-exceptions)
      ("ghc-monad-control" ,ghc-monad-control)
      ("ghc-system-filepath" ,ghc-system-filepath)
      ("ghc-system-fileio" ,ghc-system-fileio)
      ("ghc-transformers-base" ,ghc-transformers-base)))
  (home-page "http://darcs.net/")
  (synopsis
    "a distributed, interactive, smart revision control system")
  (description
    "Darcs is a free, open source revision control system. It is: . * Distributed: Darcs was one of the first revision control systems in which every user has access to the full command set, removing boundaries between server and client or committer and non-committers. . * Interactive: Darcs is easy to learn and efficient to use because it asks you questions in response to simple commands, giving you choices in your work flow. You can choose to record one change in a file, while ignoring another. As you update from upstream, you can review each patch, picking and choosing which patches are appropriate. . * Smart: Darcs is different from most revision control systems in that it is based on the notion of change (or patch), rather than version. An underlying algebra of patches determines whether changes can be re-ordered. The laws of this algebra guarantee that the result of merging depends only on the final set of patches applied in a repository and not on their order. . * Simple: As a consequence, Darcs offers a conceptually simpler view of the state of a repository: it is given by the set of patches it contains. Pulling and pushing patches merely transfers them from one set to another. So called \"cherry-picking\" is the default mode of operation, and it fully preserves the identity of patches.")
  (license #f))
--8<---------------cut here---------------end--------------->8---
  
 guix/import/cabal.scm | 13 ++++++++++---
 tests/hackage.scm     |  2 --
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/guix/import/cabal.scm b/guix/import/cabal.scm
index e9a0179b3d..16e69b9cdd 100644
--- a/guix/import/cabal.scm
+++ b/guix/import/cabal.scm
@@ -1,6 +1,7 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2015 Federico Beffa <beffa@fbengineering.ch>
 ;;; Copyright © 2018 Ricardo Wurmus <rekado@elephly.net>
+;;; Copyright © 2021 Xinglu Chen <public@yoctocell.xyz>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -399,14 +400,20 @@ matching a string against the created regexp."
 
 (define (is-or s) (string=? s "||"))
 
-(define (is-id s port)
+(define (is-id s port loc)
   (let ((cabal-reserved-words
          '("if" "else" "library" "flag" "executable" "test-suite" "custom-setup"
            "source-repository" "benchmark" "common"))
         (spaces (read-while (cut char-set-contains? char-set:blank <>) port))
         (c (peek-char port)))
     (unread-string spaces port)
-    (and (every (cut string-ci<> s <>) cabal-reserved-words)
+    ;; Sometimes the name of an identifier is the same as one of the reserved
+    ;; words, which would normally lead to an error, see
+    ;; <https://debbugs.gnu.org/cgi/bugreport.cgi?bug=25138>.  Unless the word
+    ;; is at the beginning of a line (excluding whitespace), treat is as just
+    ;; another identifier instead of a reserved word.
+    (and (or (not (= (source-location-column loc) (current-indentation)))
+             (every (cut string-ci<> s <>) cabal-reserved-words))         
          (and (not (char=? (last (string->list s)) #\:))
               (not (char=? #\: c))))))
 
@@ -568,7 +575,7 @@ LOC is the current port location."
           ((is-none w) (lex-none loc))
           ((is-and w) (lex-and loc))
           ((is-or w) (lex-or loc))
-          ((is-id w port) (lex-id w loc))
+          ((is-id w port loc) (lex-id w loc))
           (else (unread-string w port) #f))))
 
 (define (lex-line port loc)
diff --git a/tests/hackage.scm b/tests/hackage.scm
index 53972fc643..aca807027c 100644
--- a/tests/hackage.scm
+++ b/tests/hackage.scm
@@ -318,8 +318,6 @@ executable cabal
     mtl        >= 2.0      && < 3
 ")
 
-;; Fails: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=25138
-(test-expect-fail 1)
 (test-assert "hackage->guix-package test flag executable"
   (eval-test-with-cabal test-cabal-flag-executable match-ghc-foo))
 

base-commit: ec0e05ff306c950142c9ead7c712c749617069e7
-- 
2.33.0







             reply	other threads:[~2021-09-14 18:43 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-14 18:42 Xinglu Chen [this message]
2021-09-15  7:55 ` [bug#50588] [PATCH] import: cabal: Treat identifier names correctly zimoun
2021-09-15 12:32 ` bug#50588: " Lars-Dominik Braun

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e59de83e96791b6c861dab2946ffc09ab988927b.1631644779.git.public@yoctocell.xyz \
    --to=public@yoctocell.xyz \
    --cc=50588@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 external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.