I posted this message on google groups before learning that it's (likely) no longer used, so I'm cross-posting it here:
I've had an idea to implement a #lang that would provide some syntactic extensions akin to those provided by the Kawa Scheme, particularly with regard to the usage of a colon.
In particular, in Kawa:
-
the sequence
x:
will be read as a keyword equivalent to#:x
-
the sequence
a:b
will be read as($lookup$ a (unquote b))
-
likewise, the sequence
a:b:c
will be read as($lookup$ ($lookup$ a (unquote b)) (unquote c))
and so on -
if two colons appear in a row, as in, say
a::b
, they will be treated as a separate token, i.e.
(call-with-input-string "a::b" read)
will return the symbol a
and
(call-with-input-string "(a::b)" read)
will return the list of three tokens, (a :: b)
Kawa treats each pair of colons as a separate token, so
(call-with-input-string "(:::::::)" read)
returns the list (:: :: :: :)
but I would actually prefer to treat a sequence of two or more colons as a single token.
In either case, I wonder if someone could guide me how to do this, preferably using Racket's internal machinery that's already out there.
I found that atoms in Racket are being read by the read-symbol-or-number?
procedure from expander/read/symbol-or-number.rkt
, but I don't think it is sufficiently tweakable - in particular because if I read a colon, I might have to unread it if I can peek another colon.
Is there any simple way out of this situation, or do I have to actually implement a Lisp reader from scratch? (I'd be OK with that, because I already wrote a reader in Kawa that I think I could adapt, but then I'd probably have some questions about dealing with syntax objects. The alternative would be to modify Racket's sources to make the reader API more flexible, e.g. allowing to parameterize expander's read
with the read-symbol-or-number
function, which I think would be more in the spirit of Racket, but it would probably also take more time to downstream)
Thanks in advance,
Panicz