[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
01/08: import: hackage: Add recognition of 'true' and 'false' symbols.
From: |
Federico Beffa |
Subject: |
01/08: import: hackage: Add recognition of 'true' and 'false' symbols. |
Date: |
Thu, 26 Nov 2015 17:18:52 +0000 |
beffa pushed a commit to branch master
in repository guix.
commit 7716f55c8356da945261646b4d04864b6d8636aa
Author: Federico Beffa <address@hidden>
Date: Wed Nov 11 10:39:38 2015 +0100
import: hackage: Add recognition of 'true' and 'false' symbols.
* guix/import/cabal.scm (is-true, is-false, lex-true, lex-false): New
procedures.
(lex-word): Use them.
(make-cabal-parser): Add TRUE and FALSE tokens.
(eval): Add entries for 'true and 'false symbols.
---
guix/import/cabal.scm | 16 +++++++++++++++-
1 files changed, 15 insertions(+), 1 deletions(-)
diff --git a/guix/import/cabal.scm b/guix/import/cabal.scm
index 45d644a..8d84e09 100644
--- a/guix/import/cabal.scm
+++ b/guix/import/cabal.scm
@@ -138,7 +138,7 @@ to the stack."
"Generate a parser for Cabal files."
(lalr-parser
;; --- token definitions
- (CCURLY VCCURLY OPAREN CPAREN TEST ID VERSION RELATION
+ (CCURLY VCCURLY OPAREN CPAREN TEST ID VERSION RELATION TRUE FALSE
(right: IF FLAG EXEC TEST-SUITE SOURCE-REPO BENCHMARK LIB OCURLY)
(left: OR)
(left: PROPERTY AND)
@@ -206,6 +206,8 @@ to the stack."
(if-then (IF tests OCURLY exprs CCURLY) : `(if ,$2 ,$4 ())
(IF tests open exprs close) : `(if ,$2 ,$4 ()))
(tests (TEST OPAREN ID CPAREN) : `(,$1 ,$3)
+ (TRUE) : 'true
+ (FALSE) : 'false
(TEST OPAREN ID RELATION VERSION CPAREN)
: `(,$1 ,(string-append $3 " " $4 " " $5))
(TEST OPAREN ID RELATION VERSION AND RELATION VERSION CPAREN)
@@ -350,6 +352,10 @@ matching a string against the created regexp."
(define (is-if s) (string-ci=? s "if"))
+(define (is-true s) (string-ci=? s "true"))
+
+(define (is-false s) (string-ci=? s "false"))
+
(define (is-and s) (string=? s "&&"))
(define (is-or s) (string=? s "||"))
@@ -424,6 +430,10 @@ string with the read characters."
(define (lex-if loc) (make-lexical-token 'IF loc #f))
+(define (lex-true loc) (make-lexical-token 'TRUE loc #t))
+
+(define (lex-false loc) (make-lexical-token 'FALSE loc #f))
+
(define (lex-and loc) (make-lexical-token 'AND loc #f))
(define (lex-or loc) (make-lexical-token 'OR loc #f))
@@ -489,6 +499,8 @@ LOC is the current port location."
(let* ((w (read-delimited " ()\t\n" port 'peek)))
(cond ((is-if w) (lex-if loc))
((is-test w port) (lex-test w loc))
+ ((is-true w) (lex-true loc))
+ ((is-false w) (lex-false loc))
((is-and w) (lex-and loc))
((is-or w) (lex-or loc))
((is-id w) (lex-id w loc))
@@ -714,6 +726,8 @@ the ordering operation and the version."
(('os name) (os name))
(('arch name) (arch name))
(('impl name) (impl name))
+ ('true #t)
+ ('false #f)
(('not name) (not (eval name)))
;; 'and' and 'or' aren't functions, thus we can't use apply
(('and args ...) (fold (lambda (e s) (and e s)) #t (eval args)))
- branch master updated (b72a441 -> d8c66da), Federico Beffa, 2015/11/26
- 01/08: import: hackage: Add recognition of 'true' and 'false' symbols.,
Federico Beffa <=
- 02/08: import: hackage: Imporve parsing of tests., Federico Beffa, 2015/11/26
- 03/08: import: hackage: Make it resilient to missing final newline., Federico Beffa, 2015/11/26
- 04/08: import: hackage: Make parsing of tests and fields more flexible., Federico Beffa, 2015/11/26
- 08/08: import: hackage: Assume current 'ghc' package version., Federico Beffa, 2015/11/26
- 05/08: utils: Add 'canonical-newline-port'., Federico Beffa, 2015/11/26
- 06/08: import: hackage: Handle CRLF end of line style., Federico Beffa, 2015/11/26
- 07/08: import: hackage: Add new tests., Federico Beffa, 2015/11/26