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

Specialized input parsing for code/REPL in DrScheme?



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&svcclass=dncurrent&ST=PS&CONTEXT=965870095.884932614&HIT_CONTEXT=965870095.884932614&HIT_NUM=1&recnum=%3c3990E003.6EE78131@kurtz-fernhout.com%3e%234/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