Version française
Home     About     Download     Resources     Contact us    
Browse thread
building executables with camlp4
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jeremy Yallop <jeremy.yallop@e...>
Subject: Re: [Caml-list] building executables with camlp4
Nicolas Pouillard wrote:
> After thinking a little more, I can explain what's happening there is
> two modes to get into Camlp4 pipeline. The first one is through
> registration and the second one is through dyn-linking of cmo files on
> the command line.
> 
> Here your Minimal module is neither on the command line nor registered.
> 
> To register it make a functor around your grammar extension and call
> Camlp4.Register.OCamlSyntaxExtension.

Thanks, Nicolas!  Everything's working now.  In case anyone else wants
to do something similar, here's the fully working example:

minimal.ml:
    open Camlp4.PreCast

    module Id : Camlp4.Sig.Id =
    struct
      let name = "minimal"
      let version = "1.0"
    end

    module Extension (Syntax : Camlp4.Sig.Camlp4Syntax) =
    struct
      include Syntax

      DELETE_RULE Gram str_item: "type"; type_declaration END

        EXTEND Gram
        str_item:
        [[ "type"; types = type_declaration ->
             <:str_item< type $types$ >>
         | "type"; types = type_declaration;
           "premiums" ; "(" ; "squigglier" ; ")" ->
             prerr_endline "squigglier!";
           <:str_item< type $types$ >>
        ]];
      END
    end

    module M = Camlp4.Register.OCamlSyntaxExtension(Id)(Extension)

File input.ml:

     type x = int premiums ( squigglier )

Building:

     $ ocamlc -c -pp camlp4of  -I /usr/local/ocaml/lib/ocaml/camlp4 
minimal.ml
     $ ocamlc -g -linkall -I /usr/local/ocaml/lib/ocaml/camlp4 \
        -o minimal                                             \
        camlp4lib.cma                                          \
        unix.cma                                               \
        Camlp4Parsers/Camlp4OCamlRevisedParser.cmo             \
        Camlp4Parsers/Camlp4OCamlParser.cmo                    \
        Camlp4Printers/Camlp4OCamlPrinter.cmo                  \
        minimal.cmo                                            \
        Camlp4Bin.cmo

Running:

     $ ./minimal input.ml
     squigglier!
     type x = int

Jeremy.