guix-devel
[Top][All Lists]
Advanced

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

utils: Improve docstrings.


From: "Taylan Ulrich Bayırlı/Kammer"
Subject: utils: Improve docstrings.
Date: Tue, 25 Nov 2014 21:52:13 +0100

I just spend half an hour trying to find the bug in the following:

(substitute* "Makefile.in"
  (("^(prefix=[[:blank:]]*)/usr/local$" all prefix)
   (string-append prefix (assoc-ref outputs "out"))))

until I realized the lines of the file are represented as newline
terminated strings and a $ in the regexp won't match a newline by
default.

The behavior could be changed, but it seems like it was explicitly
programmed to work this way, and does make sense in a way, so I
decided to add a warning about this into the docstrings of
`substitute' and `substitute*'.

WDYT?


===File
/home/tub/media/src/guix/0001-utils-Improve-docstrings.patch===
>From 3f472e56c3fd9482e42fe8eecee5a857dbd2b8cc Mon Sep 17 00:00:00 2001
From: Taylan Ulrich B <address@hidden>
Date: Tue, 25 Nov 2014 21:25:16 +0100
Subject: [PATCH] utils: Improve docstrings.

* guix/build/utils.scm (substitute): Clarify first sentence of
  docstring and add warning to the docstring about using '$' to match
  an end of line.
  (substitute*): Add warning to the docstring about using '$' to match
  an end of line.
---
 guix/build/utils.scm | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/guix/build/utils.scm b/guix/build/utils.scm
index cda4fb1..d93366d 100644
--- a/guix/build/utils.scm
+++ b/guix/build/utils.scm
@@ -365,10 +365,11 @@ PROC's result is returned."
         (false-if-exception (delete-file template))))))
 
 (define (substitute file pattern+procs)
-  "PATTERN+PROCS is a list of regexp/two-argument procedure.  For each line
-of FILE, and for each PATTERN that it matches, call the corresponding PROC
-as (PROC LINE MATCHES); PROC must return the line that will be written as a
-substitution of the original line."
+  "PATTERN+PROCS is a list of regexp/two-argument-procedure pairs.  For each
+line of FILE, and for each PATTERN that it matches, call the corresponding
+PROC as (PROC LINE MATCHES); PROC must return the line that will be written as
+a substitution of the original line.  Be careful about using '$' to match the
+end of a line; by itself it won't match the terminating newline of a line."
   (let ((rx+proc  (map (match-lambda
                         (((? regexp? pattern) . proc)
                          (cons pattern proc))
@@ -428,7 +429,10 @@ When one of the MATCH-VAR is `_', no variable is bound to 
the corresponding
 match substring.
 
 Alternatively, FILE may be a list of file names, in which case they are
-all subject to the substitutions."
+all subject to the substitutions.
+
+Be careful about using '$' to match the end of a line; by itself it won't
+match the terminating newline of a line."
     ((substitute* file ((regexp match-var ...) body ...) ...)
      (let ()
        (define (substitute-one-file file-name)
-- 
2.1.2

============================================================



reply via email to

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