Arc Forumnew | comments | leaders | submitlogin
How to add new syntax?
5 points by byronsalty 6154 days ago | 2 comments
Ok I'm too tired to figure out how readtables work but I believe I'll need to do that in order to get what I want. (aka special meaning for chars inside symbols won't cut it).

What I want to do is define $(...) to mean something. Nevermind for now what I'm actually doing with it because I'd rather play with it a bit before I suggest a syntax change. But the question is more general.

If I want to essentially do a find/replace in the source code for "$(" -> "(new-macro" how would I do that? I suppose soon I'll give up on brevity and do it the easy way and just stick with Arc syntax but first I'd like to see how this is done and how the code looks.



8 points by absz 6154 days ago | link

You are correct that it's readtables you want, but they are an mzscheme feature; unfortunately, there is no way (yet?) to use them in Arc. Using readtables, you can customize certain things, but I don't know that there's an easy way to do $(...) because of how they work (though I am by no means an expert). If you want to hack on ac.scm or brackets.scm to extend the readtables, the best resources I can recommend are the PLT Scheme language manual (the relevant chapter is here: http://download.plt-scheme.org/doc/mzscheme/mzscheme-Z-H-11....) and just Googling for it. (I didn't have very much luck when I tried, but go for it all the same!)

Also, note that intra-symbol syntax (a:b, a.b, a!b, ~a) is implemented separately in ac.scm, in the functions expand-ssyntax and expand-compose (though you also have to modify some predicates if you add things, e.g. ssyntax?). Again, this is not (yet?) available in Arc.

I do hope that ways to extend syntax will be available in Arc soon, but they aren't yet, and I couldn't figure out readtables well enough to generate a workable solution. Hopefully arc2.tar will include this. Good luck!

-----

5 points by kennytilton 6154 days ago | link

FWIW, in common lisp I have:

  (defun mx2$-macro (stream char)
    (declare (ignore char))
    `(mx2$ ,(read stream t nil t))))

  (set-macro-character #\® #'mx2$-macro)
And that changes ®foo to (mx2$ foo)

So you might be looking for something similar in Scheme, but I have no clue what. The next question then is whether Arc in fact works that way, ie, if you do get something similar defined in Scheme, will $(foo) get expanded before Arc gets to it, or will Arc get in the way.

Apologies for such useless info. btw, if you do end up wanting to Just Try It with the Scheme equivalent I think you will find comp.lang.scheme an excellent resource.

-----