[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Specialized input parsing for code/REPL in DrScheme?



Okay, I went ahead and wrote the tool that lets you substitute in 
your own reader for DrScheme's. It turns out that the tool is awkward 
with the current tools interface. So, I extended the tools interface 
with two new parameter procedures:

   drscheme:basis:raw-reader

and

   drscheme:basis:zodiac-reader

DrScheme (the version released to CVS) now uses the values of these 
parameters as the readers. You can set them to your own reader. I am 
including two files with this post, good-unit.ss that uses the new 
DrScheme interface and sets the reader and bad-unit.ss that uses the 
old DrScheme interface to set the reader (probably works with 102). 
The documentation has been rebuilt, too. See 
http://www.cs.utah.edu/plt/anoncvs/ for instructions on downloading 
it.

Hope that helps,
Robby
(unit/sig ()
   (import mred^
           mzlib:core^
           framework^
           [print-convert : mzlib:print-convert^]
           [drscheme : drscheme:export^]
           [zodiac : zodiac:system^])

   (define (my-reader port)
     (message-box "my reader!" "my reader!")
     (read port))

   (drscheme:get/extend:extend-interactions-text
    (lambda (%)
      (class % args
        (inherit run-in-evaluation-thread)
        (rename [super-reset-console reset-console])
        (override
          [reset-console
	  (lambda ()
             (super-reset-console)
             (run-in-evaluation-thread
              (lambda ()
                (drscheme:basis:raw-reader my-reader)

                ;; this just sets all source locations to 0,0
                ;; so the debugging information is all useless
                ;; it would be better to develop a reader that
                ;; returns the zodiac structures directly,
                ;; instead of using zodiac:structurize-syntax
                (drscheme:basis:zodiac-reader
                 (opt-lambda ([port (current-input-port)]
                              [loc (zodiac:make-zodiac 1 1 #f)]
                              [script? #t]
                              [first-column 1])
                   ;; we ignore the script? field for now
                   (zodiac:structurize-syntax
                    (read port)
                    (zodiac:make-zodiac (zodiac:make-origin 'source 'source)
                                        loc loc)))))))])
        (sequence (apply super-init args))))))
(unit/sig ()
   (import mred^
           mzlib:core^
           framework^
           [print-convert : mzlib:print-convert^]
           [drscheme : drscheme:export^]
           [zodiac : zodiac:system^])

   (define (my-reader port)
     (message-box "my reader!" "my reader!")
     (read port))

   (define (process-text/no-zodiac/my-reader text f start end)
     (let* ([buffer-thunk (gui-utils:read-snips/chars-from-text text start end)]
	   [snip-string (string->list " 'non-string-snip ")]
	   [port-thunk (let ([from-snip null])
			 (rec port-thunk
                            (lambda ()
                              (if (null? from-snip)
                                  (let ([next (buffer-thunk)])
                                    (if (or (char? next) (eof-object? next))
                                        next
                                        (begin (set! from-snip snip-string)
                                               (port-thunk))))
                                  (begin0 (car from-snip)
                                          (set! from-snip (cdr from-snip)))))))]
	   [port (make-input-port port-thunk (lambda () #t) void)])
       (drscheme:basis:process/no-zodiac (lambda () (my-reader port)) f)))

   (drscheme:get/extend:extend-interactions-text
    (lambda (%)
      (class % args
        (inherit do-many-evals display-results)
        (rename [super-do-many-text-evals do-many-text-evals])
        (private
          [process-text
           (lambda (text fn start end annotate? text-is-file?)
             (if (drscheme:basis:zodiac-vocabulary? 
(drscheme:basis:current-setting))
                 (drscheme:load-handler:process-text/zodiac text fn 
start end annotate? text-is-file?)
                 (process-text/no-zodiac/my-reader text fn start end)))])
        (override
          [do-many-text-evals
	  (lambda (text start end)
             (do-many-evals
              (lambda (single-loop-eval)
                (process-text
                 text
                 (lambda (expr recur) ; =User=, =Handler=, =No-Breaks=
                   (cond
                     [(drscheme:basis:process-finish? expr)
                      (void)]
                     [else
                      (single-loop-eval
                       (lambda ()
                         (call-with-values
                          (lambda ()
                            (if (drscheme:basis:zodiac-vocabulary? 
(drscheme:basis:current-setting))
 
(drscheme:basis:syntax-checking-primitive-eval expr)
                                (drscheme:basis:primitive-eval expr)))
                          (lambda x (display-results x)))))
                      (recur)]))
                 start
                 end
                 #t
                 #t))))])
        (sequence (apply super-init args))))))