From 5de6ff2ada89c94e0f854dfd44e95471b6df0dc5 Mon Sep 17 00:00:00 2001 From: Robby Findler Date: Tue, 24 Aug 2010 13:45:53 -0500 Subject: [PATCH] Adjusts the prompt handling so that it submits expressions that signal arbitrary read errors, but does not submit those that raise eof errors. closes PR 11126 --- collects/framework/main.rkt | 7 +++++-- collects/framework/private/scheme.rkt | 15 +++++++++------ collects/tests/framework/scheme.rkt | 7 ++++--- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/collects/framework/main.rkt b/collects/framework/main.rkt index 7568e710ff..c4e3fe8bbc 100644 --- a/collects/framework/main.rkt +++ b/collects/framework/main.rkt @@ -1327,10 +1327,13 @@ @scheme[end] in @scheme[text] has at least one complete s-expression and there are no incomplete s-expressions. If @scheme[end] is @scheme[#f], it defaults to the last position of the - @scheme[text]. + @scheme[text]. The designation ``complete'' is defined to be something that does not + cause @racket[read] to raise a @racket[exn:fail:read:eof?] exception, + so there may be all kinds of strange read-level (not to speak of parse level) + errors in the expressions. The implementation of this function creates a port with - @scheme[open-input-text-editor] and then uses `read' to parse the + @scheme[open-input-text-editor] and then uses @racket[read] to parse the range of the buffer.}) (proc-doc/names diff --git a/collects/framework/private/scheme.rkt b/collects/framework/private/scheme.rkt index 836d1e8e97..07e72d9232 100644 --- a/collects/framework/private/scheme.rkt +++ b/collects/framework/private/scheme.rkt @@ -44,13 +44,16 @@ (let* ([end (or in-end (send text last-position))] [port (open-input-text-editor text start end)]) (with-handlers ([exn:fail:read:eof? (λ (x) #f)] - [exn:fail:read? (λ (x) #f)]) + [exn:fail:read? (λ (x) #t)]) (let ([first (read port)]) - (and (not (eof-object? first)) - (let loop () - (let ([s (read port)]) - (or (eof-object? s) - (loop)))))))))) + (cond + [(eof-object? first) #f] + [else + (let loop () + (let ([s (read port)]) + (cond + [(eof-object? s) #t] + [else (loop)])))])))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; diff --git a/collects/tests/framework/scheme.rkt b/collects/tests/framework/scheme.rkt index c31c5cc6ab..6f5129a63b 100644 --- a/collects/tests/framework/scheme.rkt +++ b/collects/tests/framework/scheme.rkt @@ -21,10 +21,11 @@ (test-text-balanced? 0 "" 0 #f #f) (test-text-balanced? 1 " \n " 0 #f #f) -(test-text-balanced? 2 "foo)" 0 #f #f) +(test-text-balanced? 2 "foo)" 0 #f #t) (test-text-balanced? 3 "(foo" 0 #f #f) (test-text-balanced? 4 "(foo)" 0 #f #t) -(test-text-balanced? 5 "(foo 'bar))" 0 #f #f) +(test-text-balanced? 5 "(foo 'bar))" 0 #f #t) (test-text-balanced? 6 "(foo) bar ([buz])" 0 #f #t) -(test-text-balanced? 7 "(foo]" 0 #f #f) +(test-text-balanced? 7 "(foo]" 0 #f #t) (test-text-balanced? 8 "{foo} ((bar) [5.9])" 0 #f #t) +(test-text-balanced? 9 "#(1 2 . 3)" 0 #f #t)