Version française
Home     About     Download     Resources     Contact us    
Browse thread
compiling camlp4 dynamic_functor_example.ml
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jeff Henrikson <jehenrik@y...>
Subject: compiling camlp4 dynamic_functor_example.ml
The "dynamic_functor_example.ml" from the documentation appears to not 
compile anymore with the latest camlp4 release.  Here's my attempt to 
make it work.

from http://gallium.inria.fr/~pouillar/camlp4-changes.html

dynamic_functor_example.ml

type t1 = A | B
type t2 = Foo of string * t1
open Camlp4

module Id = struct (* Information for dynamic loading *)
  let name = "My_extension"
  let version = "$Id$"
end

(* An extension is just a functor: Syntax -> Syntax *)
module Make (Syntax : Sig.Syntax.S) = struct
  include Syntax
  let foo = Gram.Entry.mk "foo"
  open Camlp4.Sig.Camlp4Token
  EXTEND Gram
    GLOBAL: foo
    foo: [ [ "foo"; i = LIDENT; b = bar -> Foo(i, b) ] ];
    bar: [ [ "?" -> A | "." -> B ] ];
  END;;
  Gram.parse_string foo (Loc.mk "<string>") "foo x?" = Foo("x", A)
  DELETE_RULE Gram foo
end

(* Register it to make it usable via the camlp4 binary. *)

module M = Register.SyntaxExtension(Id)(Make)


The first thing I am reasonably sure needs changing is Sig.Syntax.S 
doesn't seem to exist anymore, and judging by the signature of the 
Register.SyntaxExtension functor, we want a Sig.SyntaxExtension.  If we 
make the parameter Syntax a Sig.Syntax then Make becomes a functor with 
signature Sig.SyntaxExtension.

The next thing I figured out by looking at the translated 
json_static.ml, which is that

    GLOBAL: foo

needs to be

    GLOBAL: foo;


To avert a syntax error. 

Likewise, the DELETE_RULE seems to upset the lexer with syntax errors:

~/src/camlp4-beta jehenrik$ ocamlc -I +camlp4 -I +camlp4/Camlp4Parsers 
-pp camlp4orf camlp4.cma -c dynamic_functor_example3.ml
File "dynamic_functor_example3.ml", line 21, characters 19-22:
Parse error: [name] expected after [qualuid] (in [delete_rule_body])
Preprocessor error


I don't know what to do about this, so I'll temporarily delete the 
DELETE_RULE just so that I can get on to the other errors.

The closest I can see to making it compile, in a possibly defective state:

 (* An extension is just a functor: Syntax -> Syntax *)
-module Make (Syntax : Sig.Syntax.S) = struct
+module Make (Syntax : Camlp4.Sig.Syntax) = struct
   include Syntax
   let foo = Gram.Entry.mk "foo"
   open Camlp4.Sig.Camlp4Token
   EXTEND Gram
-    GLOBAL: foo
+    GLOBAL: foo;
     foo: [ [ "foo"; i = LIDENT; b = bar -> Foo(i, b) ] ];
     bar: [ [ "?" -> A | "." -> B ] ];
   END;;
   Gram.parse_string foo (Loc.mk "<string>") "foo x?" = Foo("x", A)
-  DELETE_RULE Gram foo
 end
 
 (* Register it to make it usable via the camlp4 binary. *)
 module M = Register.SyntaxExtension(Id)(Make)


And yet there is still a symbol not found:

~/src/camlp4-beta jehenrik$ ocamlc -I +camlp4 -I +camlp4/Camlp4Parsers 
-pp camlp4orf camlp4.cma -c dynamic_functor_example3.ml
File "dynamic_functor_example3.ml", line 14, characters 2-29:
Unbound module Camlp4.Sig.Camlp4Token


Which is an unbound because in the current version Camlp4, 
Camlp4.Sig.Camlp4Token is a module type, not a module.  I have no idea 
what is intended here.

BTW, my compilation string is:

ocamlc -I +camlp4 -I +camlp4/Camlp4Parsers -pp camlp4orf camlp4.cma -c 
dynamic_functor_example3.ml

Which I'm not totally sure is right.

So that's the best I can do.  Please help.  The application I want to 
write is not feasible in the old camlp4, but I suspect may be possible 
in the new.  Thanks for all the effort getting the system to the next level.


Jeff Henrikson