Browse thread
camlp4 question: Mixing a printer and Ast.fold
[
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: | 2008-03-21 (15:43) |
From: | Jeremy Yallop <jeremy.yallop@e...> |
Subject: | Re: [Caml-list] camlp4 question: Mixing a printer and Ast.fold |
Richard Jones wrote: > I cannot for the life of me work out how to get this to compile. I've > tried about a dozen different variations of the module names, 'open', > 'include' etc. and got a dozen different errors. Here's another variation that compiles and seems to work. I changed the following: * the argument type to Make from "Syntax" to "Camlp4Syntax" * the register functor from "Printer" to "OCamlPrinter" * the accumulated value in "expr" from "str" to "singular". Jeremy. module Id = struct let name = "pr_gettext" let version = "$Id$" end module Make (Syntax : Camlp4.Sig.Camlp4Syntax) : Camlp4.Sig.Printer(Syntax.Ast).S = struct open Syntax class visitor = object inherit Ast.fold as super val t = [] method t = t method expr = function | <:expr@loc< f $str:singular$ >> -> let t = singular :: t in {< t = t >} | e -> super#expr e end let print_interf ?input_file ?output_file _ = () let print_implem ?input_file ?output_file ast = let visitor = (new visitor)#str_item in let t = (visitor ast)#t in List.iter prerr_endline t end (* Register the new printer. *) module M = Camlp4.Register.OCamlPrinter(Id)(Make)