From: "Nicolas Pouillard" <nicolas.pouillard@gmail.com>
To: "Hendrik Tews" <H.Tews@cs.ru.nl>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] camlp4 3.10 questions
Date: Thu, 29 Mar 2007 11:48:54 +0200 [thread overview]
Message-ID: <cd67f63a0703290248x5fcb3eafxcf83ed3dd5ff7633@mail.gmail.com> (raw)
In-Reply-To: <17930.60913.933794.204656@tandem.cs.ru.nl>
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?
Camlp4Bin.ml
> 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?
Both.
> 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
next prev parent reply other threads:[~2007-03-29 9:48 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-03-28 22:36 Hendrik Tews
2007-03-29 9:48 ` Nicolas Pouillard [this message]
2007-03-29 15:50 ` [Caml-list] " Hendrik Tews
2007-03-29 16:10 ` Nicolas Pouillard
2007-03-29 21:47 ` Hendrik Tews
2007-03-29 21:57 ` Nicolas Pouillard
2007-03-30 11:13 ` Hendrik Tews
2007-03-30 16:13 ` Nicolas Pouillard
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=cd67f63a0703290248x5fcb3eafxcf83ed3dd5ff7633@mail.gmail.com \
--to=nicolas.pouillard@gmail.com \
--cc=H.Tews@cs.ru.nl \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox