Browse thread
camlp4 3.10 questions
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2007-03-30 (16:13) |
From: | Nicolas Pouillard <nicolas.pouillard@g...> |
Subject: | Re: [Caml-list] camlp4 3.10 questions |
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