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 question: Mixing a printer and Ast.fold
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ 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 

    * 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".


module Id = struct
   let name = "pr_gettext"
   let version = "$Id$"

module Make (Syntax : Camlp4.Sig.Camlp4Syntax)
   : Camlp4.Sig.Printer(Syntax.Ast).S =
   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

   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

(* Register the new printer. *)
module M = Camlp4.Register.OCamlPrinter(Id)(Make)