Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Installing parsers and printers
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 1994-03-22 (14:56)
From: John Harrison <John.Harrison@c...>
Subject: Installing parsers and printers

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,