Skip to content

Commit

Permalink
Merge pull request #5 from agrostis/master
Browse files Browse the repository at this point in the history
documentation (+ tests and fix)
  • Loading branch information
hanshuebner authored Aug 25, 2016
2 parents 5e7a730 + 0dd6e3b commit 063af2f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
34 changes: 29 additions & 5 deletions doc/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,10 @@ <h2>CL-INTERPOL - String interpolation for Common Lisp</h2>
is intended to be usable with <a
href="http://weitz.de/cl-ppcre/">CL-PPCRE</a>.

<h4><a name="backslash" class=none>Backslashes</a></h4>
Here's a short summary of what might occur after a backslash, copied
verbatim from <code>man&nbsp;perlop</code>. Details below - you can
click on the entries in this table to go to the corresponding
paragraph.
<h4><a name="backslash" class=none>Backslashes</a></h4> Here's a short
summary of what might occur after a backslash, originally copied
from <code>man&nbsp;perlop</code>. Details below - you can
click on the entries in this table to go to the corresponding paragraph.

<pre class=none>
<a class=none href="#tab">\t tab (HT, TAB)
Expand All @@ -243,6 +242,8 @@ <h4><a name="backslash" class=none>Backslashes</a></h4>
\U uppercase till \E
\E end case modification</a>
<a class=none href="#quote">\Q quote non-word characters till \E</a>

<a class=none href="#ignl">\<span style="border:1px solid #a0a0a0">&#x2424;</span> ignore the newline and following whitespaces</a>
</pre>
<p>
<a class=none name="tab">If</a> a backslash is followed by
Expand Down Expand Up @@ -417,6 +418,29 @@ <h4><a name="backslash" class=none>Backslashes</a></h4>
</pre>

Quoting characters with <code class=yellow>\Q</code> is especially helpful if you want to <a href="#interpolation">interpolate</a> a string verbatim into a <a href="#regular">regular expression</a>.

<p>
<a class=none name="ignl">If</a> a backslash is placed at the end of a line, it works as the <a href="http://www.lispworks.com/documentation/HyperSpec/Body/22_cic.htm">tilde newline</a> directive to Common Lisp's <code>FORMAT</code> 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.
<pre>
* #?&quot;@@ -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&quot;
&quot;@@ -1,11 +1,12 @@
Th
-e
+at
quick b
@@ -22,18 +22,17 @@
jump
-s
+ed
over
-the
+a
laz
&quot;
</pre>

<p>
All other characters following a backslash are left as is and inserted into the string. This is also true for the backslash itself, for <code class=yellow>$</code>, <code class=yellow>@</code>, and - as mentioned above - for the <a href="#outer">outer closing delimiter</a>.
<pre>
Expand Down
5 changes: 4 additions & 1 deletion read.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions test/simple
Original file line number Diff line number Diff line change
Expand Up @@ -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<foo>" "\\k<foo>")
Expand Down

0 comments on commit 063af2f

Please sign in to comment.