English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
camlp4 3.10 questions
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-03-29 (09:48)
From: Nicolas Pouillard <nicolas.pouillard@g...>
Subject: Re: [Caml-list] camlp4 3.10 questions
On 3/29/07, Hendrik Tews <H.Tews@cs.ru.nl> wrote:
> Hi,
> while doing my little camlp4 printer exercise I had the following
> questions:
> 1. What is the difference between Register.Printer and
>    Register.OCamlPrinter? I guess it boils down to the difference
>    between Sig.Syntax and Sig.Camlp4Syntax?

Yes it's mainly a difference about what your printer really needs. If
you use the camlp4 AST then you need a Sig.Camlp4Syntax as argument,
if it's not needed then you can use Sig.Syntax.

The main point is about make thing re-usable.

> 2. There are various maps and folds on asts in Sig.Camlp4Ast. How
>    can I use them?

There two things:

1/ The generic classes map and fold for the camlp4 AST.
You have to subclass it and override some cases to use it.

Here is a filter that reduces 0 + x to x and x + 0 to x.

open Camlp4.PreCast
let f =
  object (self)
     inherit Ast.map as super
     method expr = function
     | <:expr< $x$ + 0 >> | <:expr< 0 + $x$ >> -> self#expr x
     | e -> super#expr e
  end in
AstFilters.register_str_item f#str_item

2/ There is a lot of shortcuts to made the use of them easier when one
just want to hook up only one thing (expressions for instance).

The same example.

open Camlp4.PreCast
let f = Ast.map_expr begin function
     | <:expr< $x$ + 0 >> | <:expr< 0 + $x$ >> -> x
     | e -> e
end in
AstFilters.register_str_item f#str_item

There is some interesting examples in camlp4/examples

> 3. Register.declare_dyn_module puts all modules in a queue
>    together with a function that contains some delayed side
>    effects. Where are these function called?


> 4. I have the impression that the users Make functors (such as in
>    the printer HOWTO) are always applied to the same argument,
>    namely PreCast.Syntax. Why do I have to give a functor then?

To make it re-usable. Imagine that you want a camlp4 with a different
lexer, token type, or locations... By making some new modules binding
them in a new MyCamlp4PreCast and then use  printers, parsers syntax
extensions, that just require a Sig.Syntax...

> 5. I saw Camlp4OCamlOriginalQuotationExpander, presumably this is
>    a quotation expander for quotations in original syntax. Is
>    this already complete?

Complete, not really but usable yes.

> 6. There are various camlp4's: camlp4 camlp4o camlp4of camlp4oof
>    camlp4orf camlp4r camlp4rf camlp4boot camlp4prof. Could
>    somebody explain the nameing convention?

f is for full, this means that many camlp4 extensions are already
loaded (grammars, quotations, parsers, list comprehension...).

>    camlp4boot is the one used for bootstrapping or compiling the
>    camlp4 sources?


>    What is camlp4prof?

A profiling toy.

> 7. Is there an equivalent to the old pa_o_fast.cmx?

Nop :(

> 8. How can I process multiple files with the same camlp4 process?

As always ?

Nicolas Pouillard