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

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



Robby-

Fantastic! Thanks a bunch.

In the meanwhile, I had figured out as a novelty that I could use some
self-referential code to get an ugly approximation of the desired
behavior. 

As a kludge, I just added some lines of Scheme at the top of a file to
act as a "loader" for the rest of the file. That is, when you press the
evaluate button, the Scheme code opens up the file it is at the start of
and evaluates it (skipping the loader code). Of course, I couldn't
figure out a way to halt the code cleanly -- as I didn't want to (exit)
from Scheme -- just stop the evaluation.  Also, the file name has to be
correct, you need to count and set the proper number of header lines to
skip, and you have to save the code first before evaluating, and the
parsing error messages refer to another file. The code called to do the
evaluation was a slightly modified version of the IndentReader code I
posted earlier.

Example loader code put at the top of "C:/pdfscheme/FileViewer.sci":
  
  ; The next lines run this file through the IndentReader.scm
  ; The "eval-indented-file" skips the first eight lines on reading)
  ; Note that Scheme will then error out on the define with:
  ; "reference to undefined identifier:
fail-at-end-of-loader-not-defined"
  ; that is expected. It would be nice to have a better termination
  (load "IndentReader.scm")
  (eval-indented-file "C:/pdfscheme/FileViewer.sci" 8)
  (fail-at-end-of-loader-not-defined)

By the way, the viewer code above is a modification of the
"FileViewer.scm" I previous posted to the list. (Perhaps *.sci for
"Scheme indented"?) This version of the viewer is written in
indentational syntax (thus requiring the loader), and has an extra
button that lets me convert the file viewed into indentational syntax
(no "save" yet for safety!). It calls a modified version of the
IndentWriter.scm code I posted; this one takes a port to write to as an
argument for all printing functions. I think the hardest part was
getting a fixed width font set when I loaded in new text to the edit
widget. I was using that FileViewer to try to understand the syntax
checker tool (in an indented form). 

Eventually I plan to package those improved modules up and put them on
my web site. I don't want to drag the list down in too many big emails.
Sorry about that last one.

Of course, I'd rather use something clean like your approach (through
the tools interface). I'm just slowly beginning to understand how
extensible DrScheme is through that interface, and how to use it. Nice
job on the extensible architecture! 

Now that it is easy to change the parser, I could also experiment with
adding the Python triple quote ("""), so as to easily intermingle
snippets of C within a  Scheme program to generate code for native DLLs
and so on (easily = without the need to escape C quotes). 

Thanks again for the "jump start" to using the tools interface. I'll let
you know how it turns out.

-Paul Fernhout
Kurtz-Fernhout Software 
=========================================================
Developers of custom software and educational simulations
Creators of the Garden with Insight(TM) garden simulator
http://www.kurtz-fernhout.com

Robert Bruce Findler wrote:
> 
> 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