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

@ -213,6 +213,9 @@
(err/rt-test (readstr "\"\\uD800\\uDD\"") exn:fail:read?) (err/rt-test (readstr "\"\\uD800\\uDD\"") exn:fail:read?)
(err/rt-test (readstr "\"\\uD800\\uDD1\"") exn:fail:read?) (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\n ")
(test "abc" readstr "#<<EOS\nabc\nEOS") (test "abc" readstr "#<<EOS\nabc\nEOS")
(test "ok\r\nmore\r" readstr "#<<EOS\r\nok\r\nmore\r\nEOS\r") (test "ok\r\nmore\r" readstr "#<<EOS\r\nok\r\nmore\r\nEOS\r")

View File

@ -172,7 +172,7 @@
;; Parse terminator ;; Parse terminator
(define full-terminator (define full-terminator
(cons (cons
#\newline #\newline ;; assumption below that this character is first
(let loop () (let loop ()
(define c (read-char/special in config source)) (define c (read-char/special in config source))
(cond (cond
@ -193,7 +193,7 @@
(unless (null? terminator) (unless (null? terminator)
(reader-error in config #:due-to c (reader-error in config #:due-to c
"found end-of-file before terminating `~a`" "found end-of-file before terminating `~a`"
(list->string full-terminator)))] (list->string (cdr full-terminator))))]
[(not (char? c)) [(not (char? c))
(reader-error in config #:due-to c (reader-error in config #:due-to c
"found non-character while reading `#<<`")] "found non-character while reading `#<<`")]
@ -207,8 +207,13 @@
(unless (null? terminator-accum) (unless (null? terminator-accum)
(for ([c (in-list (reverse terminator-accum))]) (for ([c (in-list (reverse terminator-accum))])
(accum-string-add! accum-str c))) (accum-string-add! accum-str c)))
(cond
[(char=? c #\newline)
;; assume `full-terminator` starts with #\newline
(loop (cdr full-terminator) (list #\newline))]
[else
(accum-string-add! accum-str c) (accum-string-add! accum-str c)
(loop full-terminator null)])) (loop full-terminator null)])]))
;; Done ;; Done
(define str (accum-string-get! accum-str config)) (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)" "(let-values(((c102_0) c_88)"
"((temp103_2)" "((temp103_2)"
" \"found end-of-file before terminating `~a`\")" " \"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" "(reader-error10.1"
" #f" " #f"
" #f" " #f"
@ -52149,8 +52150,15 @@ static const char *startup_source =
" for-loop_6)" " for-loop_6)"
" lst_96)))" " lst_96)))"
"(void))))" "(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)" "(accum-string-add! accum-str_5 c_88)"
"(loop_113 full-terminator_0 null))))))))))))" "(loop_113 full-terminator_0 null)))))))))))))))"
" loop_113)" " loop_113)"
" full-terminator_0" " full-terminator_0"
" null)" " null)"