From: "Nicolas Pouillard" <nicolas.pouillard@gmail.com>
To: "Hendrik Tews" <H.Tews@cs.ru.nl>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] camlp4 3.10 questions
Date: Fri, 30 Mar 2007 18:13:57 +0200 [thread overview]
Message-ID: <cd67f63a0703300913g6f4fc43ai367d4f994c2d8148@mail.gmail.com> (raw)
In-Reply-To: <wwuk5wzj86c.fsf@tandem.cs.ru.nl>
On 3/30/07, Hendrik Tews <H.Tews@cs.ru.nl> wrote:
> "Nicolas Pouillard" <nicolas.pouillard@gmail.com> writes:
>
> On 3/29/07, Hendrik Tews <H.Tews@cs.ru.nl> wrote:
> > "Nicolas Pouillard" <nicolas.pouillard@gmail.com> writes:
> >
> > > 2. There are various maps and folds on asts in Sig.Camlp4Ast. How
> > > can I use them?
> >
> > 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
> >
> > That should be AstFilters.register_str_item f ?
>
> Nop, giving the up to date signature of Ast.map_exp:
>
> value map_expr : (expr -> expr) -> map;
>
> Where does this come from? I only found
>
> value map_expr : (expr -> expr) -> expr -> expr;
Yes that's the old one.
> > > 8. How can I process multiple files with the same camlp4 process?
>
> You're right only one file (implem or interf).
> So you can't by command line.
>
> Well, I guessed that. But how about using the API?
I've put an example in camlp4/example/parse_files.ml
I've also improved a little the API by flattening the small modules
Syntax.{Parser,Printer,Warning} into Syntax itself.
The example make a new syntax module (the Caml one), then parse two
files make, then join both ASTs, and then print it.
(*******************************)
open Camlp4.PreCast;;
module CamlGram = MakeGram(Lexer);;
module Caml =
Camlp4.Printers.OCaml.Make
(Camlp4OCamlParser.Make
(Camlp4OCamlRevisedParser.Make
(Camlp4.OCamlInitSyntax.Make(Ast)(Gram)(Quotation))));;
let parse f =
let ic = open_in f in
let strm = Stream.of_channel ic in
let res = Caml.parse_implem (Loc.mk f) strm in
close_in ic; res;;
let ghost = Loc.ghost;;
let main () =
let a = parse "apply_operator_test.ml" in
let b = parse "global_handler_test.ml" in
Caml.print_implem
<:str_item@ghost<
module Apply_operator_test = struct $a$ end;;
module Global_handler_test = struct $b$ end >>
;;
try main ()
with e ->
Format.eprintf "error: %a@." Camlp4.ErrorHandler.print e;
exit 1;;
(*******************************)
Best regards,
--
Nicolas Pouillard
prev parent reply other threads:[~2007-03-30 16:13 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 ` [Caml-list] " Nicolas Pouillard
2007-03-29 15:50 ` 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 [this message]
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=cd67f63a0703300913g6f4fc43ai367d4f994c2d8148@mail.gmail.com \
--to=nicolas.pouillard@gmail.com \
--cc=H.Tews@cs.ru.nl \
--cc=caml-list@yquem.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