summary refs log tree commit diff
path: root/guix/records.scm
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2013-07-10 17:01:47 +0200
committerLudovic Courtès <ludo@gnu.org>2013-07-10 18:01:12 +0200
commitb7b88288011aa41791b6634ae229f426bacc55ce (patch)
tree44e694859112482d9978e588293b741426460e60 /guix/records.scm
parentfdc1bf659d9834fce6c78d31680b580eab3f4235 (diff)
downloadguix-b7b88288011aa41791b6634ae229f426bacc55ce.tar.gz
records: `recutils->alist' recognizes comments.
* guix/records.scm (%recutils-comment-rx): New variable.
  (recutils->alist): Match comments.
* tests/records.scm ("recutils->alist"): Add comments.
Diffstat (limited to 'guix/records.scm')
-rw-r--r--guix/records.scm12
1 files changed, 11 insertions, 1 deletions
diff --git a/guix/records.scm b/guix/records.scm
index 64581f1be2..57664df5a6 100644
--- a/guix/records.scm
+++ b/guix/records.scm
@@ -217,13 +217,23 @@ PORT, according to FIELDS.  FIELDS must be a list of field name/getter pairs."
 (define %recutils-field-rx
   (make-regexp "^([[:graph:]]+): (.*)$"))
 
+(define %recutils-comment-rx
+  ;; info "(recutils) Comments"
+  (make-regexp "^#"))
+
 (define (recutils->alist port)
   "Read a recutils-style record from PORT and return it as a list of key/value
 pairs.  Stop upon an empty line (after consuming it) or EOF."
   (let loop ((line   (read-line port))
              (result '()))
-    (cond ((or (eof-object? line) (string-null? line))
+    (cond ((eof-object? line)
            (reverse result))
+          ((string-null? line)
+           (if (null? result)
+               (loop (read-line port) result)     ; leading space: ignore it
+               (reverse result)))                 ; end-of-record marker
+          ((regexp-exec %recutils-comment-rx line)
+           (loop (read-line port) result))
           ((regexp-exec %recutils-field-rx line)
            =>
            (lambda (match)