records: `recutils->alist' recognizes lines starting with a `+'.
authorLudovic Courtès <ludo@gnu.org>
Wed, 10 Jul 2013 16:26:46 +0000 (18:26 +0200)
committerLudovic Courtès <ludo@gnu.org>
Wed, 10 Jul 2013 19:53:29 +0000 (21:53 +0200)
* guix/records.scm (%recutils-plus-rx): New variable.
  (recutils->alist): Use it to read + lines.
* tests/records.scm ("recutils->alist with + lines"): New test.

guix/records.scm
tests/records.scm

index 8dc733b..d47bbf8 100644 (file)
@@ -231,6 +231,9 @@ PORT, according to FIELDS.  FIELDS must be a list of field name/getter pairs."
   ;; info "(recutils) Comments"
   (make-regexp "^#"))
 
+(define %recutils-plus-rx
+  (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."
@@ -244,6 +247,15 @@ pairs.  Stop upon an empty line (after consuming it) or EOF."
                (reverse result)))                 ; end-of-record marker
           ((regexp-exec %recutils-comment-rx line)
            (loop (read-line port) result))
+          ((regexp-exec %recutils-plus-rx line)
+           =>
+           (lambda (m)
+             (match result
+               (((field . value) rest ...)
+                (loop (read-line port)
+                      `((,field . ,(string-append value "\n"
+                                                  (match:substring m 1)))
+                        ,@rest))))))
           ((regexp-exec %recutils-field-rx line)
            =>
            (lambda (match)
index 712eb83..851ff7b 100644 (file)
@@ -158,6 +158,16 @@ Version: 1.5
     (list (recutils->alist p)
           (recutils->alist p))))
 
+(test-equal "recutils->alist with + lines"
+  '(("Name" . "foo")
+    ("Description" . "1st line,\n2nd line,\n 3rd line with extra space,\n4th line without space."))
+  (recutils->alist (open-input-string "
+Name: foo
+Description: 1st line,
++ 2nd line,
++  3rd line with extra space,
++4th line without space.")))
+
 (test-equal "alist->record" '((1 2) b c)
   (alist->record '(("a" . 1) ("b" . b) ("c" . c) ("a" . 2))
                  list