reader: fix/unbreak reading of here strings

The repair in 55a27e01a6 wasn't right.
This commit is contained in:
Matthew Flatt 2018-02-26 17:34:44 -07:00
parent 55a27e01a6
commit 6757a202d5
3 changed files with 22 additions and 6 deletions

View File

@ -214,6 +214,9 @@
(err/rt-test (readstr "\"\\uD800\\uDD1\"") exn:fail:read?)
(test "abc" readstr "#<<EOS\nabc\nEOS\n")
(test "abc\ndef" readstr "#<<EOS\nabc\ndef\nEOS\n")
(test "\n" readstr "#<<EOS\n\n\nEOS\n")
(test "abc" readstr "#<<EOS\nabc\nEOS\n ")
(test "abc" readstr "#<<EOS\nabc\nEOS")
(test "ok\r\nmore\r" readstr "#<<EOS\r\nok\r\nmore\r\nEOS\r")
(err/rt-test (readstr "#<<EOS\nabc\nEO") exn:fail:read?)

View File

@ -172,7 +172,7 @@
;; Parse terminator
(define full-terminator
(cons
#\newline
#\newline ;; assumption below that this character is first
(let loop ()
(define c (read-char/special in config source))
(cond
@ -193,7 +193,7 @@
(unless (null? terminator)
(reader-error in config #:due-to c
"found end-of-file before terminating `~a`"
(list->string full-terminator)))]
(list->string (cdr full-terminator))))]
[(not (char? c))
(reader-error in config #:due-to c
"found non-character while reading `#<<`")]
@ -207,8 +207,13 @@
(unless (null? terminator-accum)
(for ([c (in-list (reverse terminator-accum))])
(accum-string-add! accum-str c)))
(accum-string-add! accum-str c)
(loop full-terminator null)]))
(cond
[(char=? c #\newline)
;; assume `full-terminator` starts with #\newline
(loop (cdr full-terminator) (list #\newline))]
[else
(accum-string-add! accum-str c)
(loop full-terminator null)])]))
;; Done
(define str (accum-string-get! accum-str config))

View File

@ -52069,7 +52069,8 @@ static const char *startup_source =
"(let-values(((c102_0) c_88)"
"((temp103_2)"
" \"found end-of-file before terminating `~a`\")"
"((temp104_2)(list->string full-terminator_0)))"
"((temp104_2)"
"(list->string(cdr full-terminator_0))))"
"(reader-error10.1"
" #f"
" #f"
@ -52149,8 +52150,15 @@ static const char *startup_source =
" for-loop_6)"
" lst_96)))"
"(void))))"
"(if(char=? c_88 '#\\newline)"
"(let-values()"
"(loop_113"
"(cdr full-terminator_0)"
"(list '#\\newline)))"
"(let-values()"
"(begin"
"(accum-string-add! accum-str_5 c_88)"
"(loop_113 full-terminator_0 null))))))))))))"
"(loop_113 full-terminator_0 null)))))))))))))))"
" loop_113)"
" full-terminator_0"
" null)"