* ocamlbuild and bootstrapping projects
@ 2007-08-04 10:15 erickt
2007-08-06 10:11 ` [Caml-list] " Erick Tryzelaar
0 siblings, 1 reply; 3+ messages in thread
From: erickt @ 2007-08-04 10:15 UTC (permalink / raw)
To: caml-list
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?
If this helps, here are all the files:
all the files shared between the two generators:
dyplib/automaton.ml
dyplib/dyp.ml
dyplib/dyp.mli
dyplib/dyplib.mllib
dyplib/gs.ml
dyplib/priority_by_relation.ml
the intermediary generator. This isn't supposed to be an external tool:
generators/pgen/pgen.ml
generators/pgen/pgen_lexer.mll
generators/pgen/pgen_parser_param.ml
the external parser:
generators/dypgen/argument.ml
generators/dypgen/dypgen.ml
generators/dypgen/dypgen_lexer.mll
generators/dypgen/dypgen_parser.dyp <- the file that needs to be parsed
with pgen
generators/dypgen/insert_linenum.mll
generators/dypgen/parse_tree.mli
Thanks for any help!
-e
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Caml-list] ocamlbuild and bootstrapping projects
2007-08-04 10:15 ocamlbuild and bootstrapping projects erickt
@ 2007-08-06 10:11 ` Erick Tryzelaar
2007-08-09 18:34 ` Nicolas Pouillard
0 siblings, 1 reply; 3+ messages in thread
From: Erick Tryzelaar @ 2007-08-06 10:11 UTC (permalink / raw)
To: caml-list
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;;
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Caml-list] ocamlbuild and bootstrapping projects
2007-08-06 10:11 ` [Caml-list] " Erick Tryzelaar
@ 2007-08-09 18:34 ` Nicolas Pouillard
0 siblings, 0 replies; 3+ messages in thread
From: Nicolas Pouillard @ 2007-08-09 18:34 UTC (permalink / raw)
To: Erick Tryzelaar; +Cc: O'Caml Mailing List
Your solution is quite good and follows ocamlbuild principles.
Excerpts from Erick Tryzelaar's message of Mon Aug 06 12:11:16 +0200 2007:
> 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]]);
You can use the Outcome.ignore_good function.
List.iter Outcome.ignore_good (build [[dypgen]])
>
> Cmd(S[A dypgen; T tags; Px dyp])
> end;
> | _ -> ()
> end;;
>
--
Nicolas Pouillard aka Ertai
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2007-08-09 18:35 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-08-04 10:15 ocamlbuild and bootstrapping projects erickt
2007-08-06 10:11 ` [Caml-list] " Erick Tryzelaar
2007-08-09 18:34 ` Nicolas Pouillard
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox