caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Erick Tryzelaar <erickt@dslextreme.com>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] ocamlbuild and bootstrapping projects
Date: Mon, 06 Aug 2007 03:11:16 -0700	[thread overview]
Message-ID: <46B6F3C4.7050408@dslextreme.com> (raw)
In-Reply-To: <6b94a12183a2ab7a191d6a.20070804031527.revpxg@www.dslextreme.com>

erickt@dslextreme.com wrote:
> I was trying to adapt the parser dypgen (http://dypgen.free.fr/)'s build
> system to use ocamlbuild, but I ran into a problem. The final dypgen
> grammar is generated by an internal intermediary generator called pgen.
> The problem I'm having is that I don't know how to get ocamlbuild to
> automatically build pgen before we can process a %.dyp file. I suppose I
> could do this in two separate calls to ocamlbuild, but I feel like this
> can be done using a plugin. Is this possible?

For those that are interested, here's the solution I came up with. We 
use the "build" function we get in the rule to dynamically dispatch the 
building of the parser if we haven't generated it yet:

myocamlbuild.ml:
dispatch begin function
  | After_rules ->
      rule "dypgen: .dyp -> .ml & .mli"
        ~deps:["%.dyp"]
        ~prods:["%.ml"; "%.mli"]
        begin fun env build ->
          let dyp = env "%.dyp" in
          let tags = tags_of_pathname dyp++"ocaml"++"parser" in
         
          (* Since pgen and dypgen programs use the same extension, we need
           * to be able to switch between the two. Do this by tagging 
the pgen
           * files with "use_pgen".
           * I'm not sure how we should do byte/native, so we'll just 
use the
           * native. *)
          let dypgen, tags =
            if Tags.mem "use_pgen" tags
            then "dyp/generators/pgen/pgen.native", tags++"pgen"
            else "dyp/generators/dypgen/dypgen.native", tags++"dypgen"
          in
           
          (* try to build the parser if it doesn't exist yet *)
          List.iter begin function
            | Outcome.Good o -> ()
            | Outcome.Bad exn -> raise exn
          end (build [[dypgen]]);
           
          Cmd(S[A dypgen; T tags; Px dyp])
        end;
  | _ -> ()
end;;


  reply	other threads:[~2007-08-06 10:11 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-04 10:15 erickt
2007-08-06 10:11 ` Erick Tryzelaar [this message]
2007-08-09 18:34   ` [Caml-list] " Nicolas Pouillard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=46B6F3C4.7050408@dslextreme.com \
    --to=erickt@dslextreme.com \
    --cc=caml-list@yquem.inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).