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
_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs
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)
Brilliant, that works, thanks!
> | <:expr@loc< f $str:singular$ >> ->
> let t = singular :: t in
The above was just a typo when I was simplifying the program ...
Rich.
--
Richard Jones
Red Hat
_______________________________________________
BTW, I think the ability to be able to map & fold over the AST is an
extraordinarily powerful feature, and deserves many more examples and
tutorials. I know that strictly speaking it was possible before (with
Le Gall's ast-analyze extension) but the way it is done in the new
camlp4 makes the code much shorter.
ocamlc -I +camlp4 camlp4lib.cma Camlp4Bin.cmo pr_gettext.cmo \
-o ocaml-xgettext
but my binary always prints out:
Failure: "No implementation printer"
Apparently I need to somehow register the printer as well? I can't
work out how to do that though.
As an aside, is mkcamlp4 supposed to do anything? For me it always
prints this error:
Cannot find file Camlp4.cma
What version of pr_gettext are you using?
> As an aside, is mkcamlp4 supposed to do anything? For me it always
> prints this error:
>
> Cannot find file Camlp4.cma
Hum mkcamlp4 seems br0ken :(
--
Nicolas Pouillard aka Ertai
Well, no version -- I'm trying to make Sylvain Le Gall's pr_gettext
work with camlp4 3.10. It has to be linked into a standalone binary
called ocaml-xgettext, but I can't work out how to do that.
Previously Sylvain was using mkcamlp4, but that is broken.
I mean between different proposals for pr_gettext.ml, in this thread.
I was using Jeremy Yallop's simple version (same as your first
version). I got it to work by linking it as follows:
$(OCAMLC) \
-I +camlp4 camlp4lib.cma \
unix.cma \
`$(OCAMLFIND) query -r -predicates byte gettext.extract -i-format` \
`$(OCAMLFIND) query -r -predicates byte gettext.extract -a-format` \
`$(OCAMLFIND) query -r -predicates byte gettext.extract -o-format` \
Camlp4Bin.cmo \
-o $@
http://www.annexia.org/tmp/ocaml-gettext-0.2.0-20080321.patch
And it gives me one reason to drop ast-analyze... This new camlp4
feature, seems indeed very powerful.
Regards,
Sylvain Le Gall