caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* camlp4 question: Mixing a printer and Ast.fold
@ 2008-03-21 15:06 Richard Jones
  2008-03-21 15:36 ` [Caml-list] " Jeremy Yallop
  2008-03-21 15:46 ` Nicolas Pouillard
  0 siblings, 2 replies; 12+ messages in thread
From: Richard Jones @ 2008-03-21 15:06 UTC (permalink / raw)
  To: caml-list

I'm trying to translate Sylvain Le Gall's gettext module to use camlp4
from ocaml 3.10.0.  The module is a printer which folds over the AST
looking for certain types of function call by name.  A simplified
version is shown below.

This program is supposed to look for all instances of a function named
f applied to a string.

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.

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

module Make (Syntax : Camlp4.Sig.Syntax)
  : Camlp4.Sig.Printer(Syntax.Ast).S =
struct
  module Loc = Syntax.Loc
  module Ast = Syntax.Ast

  class visitor = object
    inherit Ast.fold as super

    val t = []
    method t = t

    method expr = function
    | <:expr@loc< f $str:singular$ >> ->
      let t = str :: 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.Printer(Id)(Make) 
----------------------------------------------------------------------

ocamlc -I +camlp4 -I /usr/lib64/ocaml/camlp4/Camlp4Parsers -pp camlp4of.opt camlp4lib.cma test.ml -o test.cmo
File "test.ml", line 19, characters 19-19:
Unbound constructor Ast.ExApp

Please let me know how to compile this before I go mad...

Rich.

-- 
Richard Jones
Red Hat


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2008-03-26  9:30 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-03-21 15:06 camlp4 question: Mixing a printer and Ast.fold Richard Jones
2008-03-21 15:36 ` [Caml-list] " Jeremy Yallop
2008-03-21 15:51   ` Richard Jones
2008-03-21 15:46 ` Nicolas Pouillard
2008-03-21 15:58   ` Richard Jones
2008-03-26  9:29     ` Sylvain Le Gall
2008-03-21 16:44   ` [Caml-list] " Richard Jones
2008-03-21 16:50     ` Nicolas Pouillard
2008-03-21 16:56       ` Richard Jones
2008-03-21 17:03         ` Nicolas Pouillard
2008-03-21 17:21           ` Richard Jones
2008-03-21 20:19             ` Richard Jones

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).