read/recursive: avoid placeholder wrapper

Although the documentation claimed that `read/recursive` produces
a plaeholder, that seems to be a leftover from a much older
reader (before `make-reader-graph`). Fix the new `read/recursive`
to be like the old one, and update the documentation.

Thanks to Alex Knauth for tracking down the unnecessary change
in reader behavior.

Related to #2099
This commit is contained in:
Matthew Flatt 2018-05-24 14:23:04 -06:00
parent b58938dc89
commit 851ea57ef9
4 changed files with 3294 additions and 3217 deletions

View File

@ -62,17 +62,9 @@ When @racket[graph?] is @racket[#f], graph structure annotations in
the read datum are local to the datum.
When called within the dynamic extent of @racket[read], the
@racket[read/recursive] procedure produces either an opaque
placeholder value, a special-comment value, or an end-of-file. The
result is a special-comment value (see @secref["special-comments"])
when the input stream's first non-whitespace content parses as a
comment. The result is end-of-file when @racket[read/recursive]
encounters an end-of-file. Otherwise, the result is a placeholder that
protects graph references that are not yet resolved. When this
placeholder is returned within an S-expression that is produced by any
reader-extension procedure (see @secref["reader-procs"]) for the
same outermost @racket[read], it will be replaced with the actual read
value before the outermost @racket[read] returns.
@racket[read/recursive] procedure can produce a special-comment value
(see @secref["special-comments"]) when the input stream's first
non-whitespace content parses as a comment.
See @secref["readtables"] for an extended example that uses
@racket[read/recursive].

View File

@ -1125,6 +1125,27 @@
(test #\{ syntax-property (read-syntax 'x (open-input-string "{1 2 3}")) 'paren-shape)
(test #\{ syntax-property (read-syntax 'x (open-input-string "#{1 2}")) 'paren-shape)
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Check `read/recursive`
(let ()
(define in (open-input-string "abc"))
(test 'abc read/recursive in))
(let ()
(define in2 (open-input-string "(#0=(abc) #z(#0#))"))
(parameterize ([current-readtable
(make-readtable (current-readtable)
#\z
'dispatch-macro
(lambda (char in name line col pos)
(define v (read/recursive in))
(log-error ">> ~s" v)
v))])
(define v (read in2))
(test '((abc) ((abc))) values v)
(test #t eq? (car v) (caadr v))))
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Test read error on a character not in any port

View File

@ -103,7 +103,7 @@
(not (eof-object? v))
(not (special-comment? v)))
(get-graph-hash config) ; to trigger placeholder resolution
(make-placeholder v)]
v]
[else v]))
(define (read-language in fail-k

File diff suppressed because it is too large Load Diff