Support backslash in string.

* reader.c (read_string): Handle '\\'.
* tests/read.test: Add it.
This commit is contained in:
Jan Nieuwenhuizen 2016-12-18 15:39:12 +01:00
parent 89f771f18a
commit 6b4bf34ff2
2 changed files with 13 additions and 1 deletions

View file

@ -169,7 +169,8 @@ read_string ()
int c = getchar ();
while (true) {
if (c == '"') break;
if (c == '\\' && peekchar () == '"') p = append_char (p, getchar ());
if (c == '\\' && peekchar () == '\\') p = append_char (p, getchar ());
else if (c == '\\' && peekchar () == '"') p = append_char (p, getchar ());
else if (c == '\\' && peekchar () == 'n') {getchar (); p = append_char (p, '\n');}
else if (c == EOF) assert (!"EOF in string");
else p = append_char (p, c);

View file

@ -23,6 +23,17 @@ cons
(display #x16) (newline)
(display #\A) (newline)
(display #\newline) (newline)
#\alarm
#\backspace
#\tab
#\newline
#\vtab
#\page
#\return
#\space
(display "\"")
(display "\\")
(display "\\\"\"\\")
(display 'foo)(newline)
(display '(foo))(newline)
(display '('foo))(newline)