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

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



The best way to implement something like this is to write your own 
reader (ie a procedure that accepts a port and returns an sexp). 
Then, you can use that reader instead of the one supplied with 
DrScheme and just hook into the usual parsers.

The tricky part will be getting DrScheme itself to use your reader. 
The environment is designed to be "open" (via the tools mechanism), 
but so far the exposed procedures have been added on an as needed 
basis. I suspect that this kind of change is either difficult or 
impossible (I guess that it is merely the former :). Check out the 
tools manual for more information. Don't hesitate to contact me if 
you get stuck or need some more infrastructure exposed.

>From the forewarned is forarmed department, there are two readers in 
DrScheme currently: one tracks source location information and the 
other doesn't. So, your reader will need to do both if it is to 
actually make it into DrScheme someday.

Good Luck! Hope that helps!

Robby

>I'm interested in being able to flip between alternate textual
>representations in DrScheme. I'm trying to determine how hard this would
>be to implement in DrScheme.
>
>Specifically, I'd like to flip back and forth in the DrScheme editor
>between conventional Scheme syntax and a syntax where indentation is
>significant (like in Python or Occam) and thus parentheses at the edges
>of lines can be removed as redundant.
>
>For example:
>
>(define (square x)
>   (* x x))
>
>would become:
>
>define (square x)
>   * x x
>
>and vice versa. I posted a thread on this to comp.lang.lisp if anyone
>wants the specifics.
>http://x66.deja.com/viewthread.xp?AN=656209628.4&search=thread&svccla 
>ss=dncurrent&ST=PS&CONTEXT=965870095.884932614&HIT_CONTEXT=965870095.8 
>84932614&HIT_NUM=1&recnum=%3c3990E003.6EE78131@kurtz-fernhout.com%3e%2 
>34/4&group=comp.lang.lisp&frpage=viewthread.xp&back=clarinet
>
>So my question is, in DrScheme, how should I best go about doing this
>(in terms of interfacing with DrScheme, not specifically the parsing)?
>Is there a way to do this completely in Scheme (I hope) or will I have
>to recompile DrScheme and make changes to the C code?
>
>Note this is something very different from defining a macro as far as I
>can tell -- since I am fundamentally changing the interpretation of the
>text before it is made into nested lists.
>
>I see there are some hooks and code for printing in DrScheme,
>specifically
>   Converted Printing: pconver.ss
>   Pretty Printing: pretty.ss
>so I have something to start with.
>
>The part that looks harder is transparently taking the code entered into
>DrScheme, perhaps checking the first line or so for a flag
>(indent-mode-on?) and then using an alternate parser (hopefully
>writeable in Scheme). I'm not sure where to begin.
>
>Can anyone rough out the big picture of what I need to do to accomplish
>this in DrScheme?  The easier and more in Scheme the approach, the
>better. I looked at the docs, but didn't see anything obvious on hooking
>the REPL handler. Is it in there somewhere? I'd also like to hook saving
>the file, so I could transparently save the alternative syntax as
>standard Scheme syntax.
>
>Naturally people on comp.lang.lisp suggest I do this as emacs Lisp
>macros, but a DrScheme implementation would probably be more useful for
>me (and hopefully might interest people on this list as well). Of
>course, what they mostly suggest is that this is just a bad idea, but
>I'm curious enough to at least want to see how difficult it would be to
>implement it.
>
>I guess this is the "second system" effect Fred Brooks warns about.
>   http://www.best.com/~rgm/notebook/second-system.html
>One tiny success with a simple plug-in (still in need of error handling
>no less!) and I think I can rewrite Scheme parsing rules... :-)
>
>Note: Educational motivations for this (if any are needed) are:
>* an easy way to switch between syntaxes might allow students to
>experiment with their own mini-languages and parsers more easily using
>the DrScheme system (by hooking the REPL with their own handler)
>* this alternative syntax might be easier to understand or perhaps learn
>for some Scheme novices -- especially those coming from Python (I don't
>say this is necessarily true, but I can hope).
>
>-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