all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / Atom feed
* [bug#50588] [PATCH] import: cabal: Treat identifier names correctly.
@ 2021-09-14 18:42 Xinglu Chen
  2021-09-15  7:55 ` zimoun
  2021-09-15 12:32 ` bug#50588: " Lars-Dominik Braun
  0 siblings, 2 replies; 3+ messages in thread
From: Xinglu Chen @ 2021-09-14 18:42 UTC (permalink / raw)
  To: 50588

* 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







^ permalink raw reply	[flat|nested] 3+ messages in thread

* [bug#50588] [PATCH] import: cabal: Treat identifier names correctly.
  2021-09-14 18:42 [bug#50588] [PATCH] import: cabal: Treat identifier names correctly Xinglu Chen
@ 2021-09-15  7:55 ` zimoun
  2021-09-15 12:32 ` bug#50588: " Lars-Dominik Braun
  1 sibling, 0 replies; 3+ messages in thread
From: zimoun @ 2021-09-15  7:55 UTC (permalink / raw)
  To: Xinglu Chen; +Cc: 50588

Hi,

On Tue, 14 Sept 2021 at 20:43, Xinglu Chen <public@yoctocell.xyz> wrote:

> * 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>

Oh awesome!  Thanks!  Yesterday, I was reviewing old bugs and dig the
cabal parser was too intimidating. :-)

Cheers,
simon




^ permalink raw reply	[flat|nested] 3+ messages in thread

* bug#50588: [PATCH] import: cabal: Treat identifier names correctly.
  2021-09-14 18:42 [bug#50588] [PATCH] import: cabal: Treat identifier names correctly Xinglu Chen
  2021-09-15  7:55 ` zimoun
@ 2021-09-15 12:32 ` Lars-Dominik Braun
  1 sibling, 0 replies; 3+ messages in thread
From: Lars-Dominik Braun @ 2021-09-15 12:32 UTC (permalink / raw)
  To: Xinglu Chen; +Cc: 50588-done

Hi,

looks good, pushed as a840caccaee8c9492f4cc8a7ba802ef54391f199 with some
trailing whitespace removed.

Cheers,
Lars





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-09-15 13:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-14 18:42 [bug#50588] [PATCH] import: cabal: Treat identifier names correctly Xinglu Chen
2021-09-15  7:55 ` zimoun
2021-09-15 12:32 ` bug#50588: " Lars-Dominik Braun

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.