Installing parsers and printers

John Harrison (John.Harrison@cl.cam.ac.uk)
Tue, 22 Mar 94 14:55:52 +0000

To: caml-list@pauillac.inria.fr
Subject: Installing parsers and printers
Date: Tue, 22 Mar 94 14:55:52 +0000
From: John Harrison <John.Harrison@cl.cam.ac.uk>
Message-Id: <"swan.cl.cam.:265930:940322145613"@cl.cam.ac.uk>

My interest in CAML is as a metalanguage for an embedded logic (which was of
course ML's original application, hence the name). An important part of this is
the provision of a nice interface to the user who still uses the toplevel loop,
so I have two wishes:

o I'd like to be able to install a custom printer to display objects of a
nominated type (in the toplevel loop). I have a logic encoded as a
recursive type. Of course this is unreadable in its raw form, and it's
very tedious to have to call a prettyprinter explicitly. Ideally I'd
like to be able to do something like:

#install_printer "term" "term_printer";;

(where `term_printer' is an ML function I have defined), and then have all
objects of type `term' displayed using that printer. If something this clean
is not possible I'm willing to dive into C if somebody can advise me on how
to interface to the system.

o I'd like to be able to set up some special quotation syntax to parse
down to a nominated type automatically. I envisage something like:

#install_parser "<<" ">>" "term_parser";;

(where `term_parser' is an ML function I have defined). Thereafter if I
type <<....>>, the system would call the parser on the string "...." and
that would be the result of evaluation.

If this is not possible, then I can survive by invoking a parser explicitly
on a string. However I would really like to suppress recognition of escapes
like "\n" in this string. Is there a clean way of forcing this, or does
it necessitate patching the lexer?

It is interesting to note that SML/NJ originally had no such facilities, but
they have been added by Konrad Slind -- see his paper in the Second ML
Workshop: "Object Language Embedding in Standard ML of New Jersey".

I'd be grateful for any help,

John.