disable nested `#lang'

A `syntax/module-reader' reader disables `#lang' when looping to
read a module body. The HtDP languages require a little additional
treatment.
This commit is contained in:
Matthew Flatt 2012-05-29 10:35:02 -06:00
parent def4da4f9a
commit 248301c9ed
6 changed files with 31 additions and 18 deletions

View File

@ -10,11 +10,12 @@
read)) read))
(define (get-all-exps source-name port) (define (get-all-exps source-name port)
(let loop () (parameterize ([read-accept-lang #f])
(let ([exp (read-syntax source-name port)]) (let loop ()
(cond (let ([exp (read-syntax source-name port)])
[(eof-object? exp) null] (cond
[else (cons exp (loop))])))) [(eof-object? exp) null]
[else (cons exp (loop))])))))
(define (lookup key table) (define (lookup key table)
(let ([ans (assoc key table)]) (let ([ans (assoc key table)])

View File

@ -90,7 +90,8 @@
;; take all of the body expressions from the port ;; take all of the body expressions from the port
(define (suck-all-exps port reader) (define (suck-all-exps port reader)
(define (port-reader p) (reader (object-name port) p)) (define (port-reader p) (parameterize ([read-accept-lang #f])
(reader (object-name port) p)))
(sequence->list (in-port port-reader port))) (sequence->list (in-port port-reader port)))
;; check that the teachpacks exist, return ;; check that the teachpacks exist, return

View File

@ -175,12 +175,13 @@
(let* ([lang (if stx? (datum->syntax #f lang modpath modpath) lang)] (let* ([lang (if stx? (datum->syntax #f lang modpath modpath) lang)]
[body (lambda () [body (lambda ()
(if whole? (if whole?
(read port) (read port)
(let loop ([a null]) (parameterize ([read-accept-lang #f])
(let ([v (read port)]) (let loop ([a null])
(if (eof-object? v) (let ([v (read port)])
(reverse a) (if (eof-object? v)
(loop (cons v a)))))))] (reverse a)
(loop (cons v a))))))))]
[body (cond [(not wrapper) (body)] [body (cond [(not wrapper) (body)]
[(ar? wrapper 2) (wrapper body stx?)] [(ar? wrapper 2) (wrapper body stx?)]
[else (wrapper body)])] [else (wrapper body)])]

View File

@ -94,7 +94,12 @@ identifiers used by the @racket[reader-option]s.
@racket[read-syntax], respectively. Normally, the replacements @racket[read-syntax], respectively. Normally, the replacements
for @racket[read] and @racket[read-syntax] are applied for @racket[read] and @racket[read-syntax] are applied
repeatedly to the module source until @racket[eof] is produced, repeatedly to the module source until @racket[eof] is produced,
but see also @racket[#:whole-body-readers?]. but see also @racket[#:whole-body-readers?].
Unless @racket[#:whole-body-readers?] specifies a true value,
the repeated use of @racket[read] or @racket[read-syntax] is
@racket[parameterize]d to set @racket[read-accept-lang] to
@racket[#f], which disables nested uses of @hash-lang[].
See also @racket[#:wrapper1] and @racket[#:wrapper2], which See also @racket[#:wrapper1] and @racket[#:wrapper2], which
support simple parameterization of readers rather than support simple parameterization of readers rather than

View File

@ -1,6 +1,9 @@
Version 5.3.0.10 Version 5.3.0.10
racket/base: add progress-evt?, thread-cell-values?, prefab-key?, racket/base: add progress-evt?, thread-cell-values?, prefab-key?,
semaphore-peek-evt?, channel-put-evt? semaphore-peek-evt?, channel-put-evt?
Changed #lang for most languages so that it cannot be nested;
this change is within syntax/module-reader and applies to
racket, racket/base, and more
Version 5.3.0.9 Version 5.3.0.9
Changed the format of error messages Changed the format of error messages

View File

@ -2184,14 +2184,19 @@ _internal_read(Scheme_Object *port, Scheme_Object *stxsrc, int crc, int cant_fai
else else
params.table = NULL; params.table = NULL;
} }
params.can_read_compiled = crc; if (crc >= 0)
params.can_read_compiled = crc;
else {
v = scheme_get_param(scheme_current_config(), MZCONFIG_CAN_READ_COMPILED);
params.can_read_compiled = SCHEME_TRUEP(v);
}
v = scheme_get_param(config, MZCONFIG_CAN_READ_PIPE_QUOTE); v = scheme_get_param(config, MZCONFIG_CAN_READ_PIPE_QUOTE);
params.can_read_pipe_quote = SCHEME_TRUEP(v); params.can_read_pipe_quote = SCHEME_TRUEP(v);
v = scheme_get_param(config, MZCONFIG_CAN_READ_BOX); v = scheme_get_param(config, MZCONFIG_CAN_READ_BOX);
params.can_read_box = SCHEME_TRUEP(v); params.can_read_box = SCHEME_TRUEP(v);
v = scheme_get_param(config, MZCONFIG_CAN_READ_GRAPH); v = scheme_get_param(config, MZCONFIG_CAN_READ_GRAPH);
params.can_read_graph = SCHEME_TRUEP(v); params.can_read_graph = SCHEME_TRUEP(v);
if (crc || get_info) { if ((crc > 0) || get_info) {
params.can_read_reader = 1; params.can_read_reader = 1;
params.can_read_lang = 1; params.can_read_lang = 1;
} else { } else {
@ -2329,9 +2334,6 @@ scheme_internal_read(Scheme_Object *port, Scheme_Object *stxsrc, int crc, int ca
{ {
Scheme_Thread *p = scheme_current_thread; Scheme_Thread *p = scheme_current_thread;
if (crc < 0)
crc = SCHEME_TRUEP(scheme_get_param(scheme_current_config(), MZCONFIG_CAN_READ_COMPILED));
if (cantfail) { if (cantfail) {
return _internal_read(port, stxsrc, crc, cantfail, recur, expose_comment, -1, NULL, return _internal_read(port, stxsrc, crc, cantfail, recur, expose_comment, -1, NULL,
magic_sym, magic_val, delay_load_info, 0); magic_sym, magic_val, delay_load_info, 0);