diff --git a/doc/index.html b/doc/index.html index 6f76c42..9b8f68f 100644 --- a/doc/index.html +++ b/doc/index.html @@ -217,11 +217,10 @@

CL-INTERPOL - String interpolation for Common Lisp

is intended to be usable with CL-PPCRE. -

Backslashes

-Here's a short summary of what might occur after a backslash, copied -verbatim from man perlop. Details below - you can -click on the entries in this table to go to the corresponding -paragraph. +

Backslashes

Here's a short +summary of what might occur after a backslash, originally copied +from man perlop. Details below - you can +click on the entries in this table to go to the corresponding paragraph.
   \t          tab             (HT, TAB)
@@ -243,6 +242,8 @@ 

Backslashes

\U uppercase till \E \E end case modification \Q quote non-word characters till \E + + \ ignore the newline and following whitespaces

If a backslash is followed by @@ -417,6 +418,29 @@

Backslashes

Quoting characters with \Q is especially helpful if you want to interpolate a string verbatim into a regular expression. + +

+ If a backslash is placed at the end of a line, it works as the tilde newline directive to Common Lisp's FORMAT function. That is, the newline immediately following the backslash and any non-newline whitespace characters after the newline are ignored. This escape sequence allows to break long string literals into several lines of code, so as to maintain convenient line width and indentation of code. +

+* #?"@@ -1,11 +1,12 @@\n Th\n-e\n+at\n  quick b\n\
+     @@ -22,18 +22,17 @@\n jump\n-s\n+ed\n  over \n\
+     -the\n+a\n  laz\n"
+"@@ -1,11 +1,12 @@
+ Th
+-e
++at
+  quick b
+@@ -22,18 +22,17 @@
+ jump
+-s
++ed
+  over 
+-the
++a
+  laz
+"
+
+

All other characters following a backslash are left as is and inserted into the string. This is also true for the backslash itself, for $, @, and - as mentioned above - for the outer closing delimiter.

diff --git a/read.lisp b/read.lisp
index ce1a9ad..c749e20 100644
--- a/read.lisp
+++ b/read.lisp
@@ -138,7 +138,10 @@ backslash has already been consumed."
                         ;; code, three digits or less
                         (make-char-from-code (get-number :radix 8 :max 3)))))
               ((#\Newline)
-                (peek-char t *stream* nil)
+                (read-while
+                  (lambda (c)
+                    (or (char= c #\Space)
+                        (not (or (graphic-char-p c) (char= c #\Newline))))))
                 "")
               ;; the following five character names are
               ;; 'semi-standard' according to the CLHS but I'm not
diff --git a/test/simple b/test/simple
index 02e62dd..0ebcae3 100644
--- a/test/simple
+++ b/test/simple
@@ -78,6 +78,10 @@
 
 (char= (char #?"\N{Newline}" 0) #\Newline)
 
+;; ignored newline
+(string= #?"abc\
+   def" "abcdef")
+
 (string= #?/\1/ "\\1")
 (string= #?r"\1" "\\1")
 (string= #?r"\k" "\\k")