guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

branch master updated: import: cabal: Treat identifier names correctly.


From: guix-commits
Subject: branch master updated: import: cabal: Treat identifier names correctly.
Date: Wed, 15 Sep 2021 08:30:47 -0400

This is an automated email from the git hooks/post-receive script.

lbraun pushed a commit to branch master
in repository guix.

The following commit(s) were added to refs/heads/master by this push:
     new a840cac  import: cabal: Treat identifier names correctly.
a840cac is described below

commit a840caccaee8c9492f4cc8a7ba802ef54391f199
Author: Xinglu Chen <public@yoctocell.xyz>
AuthorDate: Tue Sep 14 20:42:18 2021 +0200

    import: cabal: Treat identifier names correctly.
    
    * 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>
    Signed-off-by: Lars-Dominik Braun <lars@6xq.net>
---
 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 e9a0179..98d7234 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 53972fc..aca8070 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))
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]