(define-module (here-strings-with-escapes)
#:use-module (ice-9 match))
(define (read-here-string c port)
(unless (and (char=? #\" (read-char port))
(char=? #\" (read-char port)))
(error "Invalid here-string syntax"))
(let loop ((chars '()))
(match chars
((#\" #\" #\" . chars)
(list->string (reverse! chars)))
((#\n #\\ . chars)
(loop (cons #\newline chars)))
((#\r #\\ . chars)
(loop (cons #\cr chars)))
((#\t #\\ . chars)
(loop (cons #\tab chars)))
((#\0 #\\ . chars)
(loop (cons #\null chars)))
(_ (let ((c (read-char port)))
(if (eof-object? c)
(error "EOF within here-string")
(loop (cons c chars))))))))
(read-hash-extend #\" read-here-string)