Re: Syntax extension for including strings from external file
- On 09-07-2009, Dario Teixeira <darioteixeira@...> wrote:
>There is a small utility call ocamlify:
> Is there a syntax extension that allows a string to be assigned the content=
> of a file? So instead of doing
> let str =3D "very long string"
> one would just
> let str =3D #include "file.txt" (* or something like this *)
> where file.txt would contain a "very long string". I've looked in the
> but there doesn't seem to be anything that matches this description. Also,
> I know the same functionality can be implemented via the C-interface by
> linking in a binary object, but that's overkill for my purposes.
http://darcs.ocamlcore.org/repos/ocamlify/ocamlify/ (darcs repository)
You should look at ocaml-autobuild that use it extensively to include
files in the exec:
with the following rules in ocamlbuild:
let ocamlify = A"ocamlify";;
rule "ocamlify: %.mlify -> %.mlify.depends"
fun env _ ->
T(tags_of_pathname (env "%.mlify")++"ocamlify"++"depends");
A"--output"; P(env "%.mlify.depends");
rule "ocamlify: %.mlify & %.mlify.depends -> %.ml"
fun env build ->
Cmd(S[ocamlify; A"--output"; P(env "%.ml"); P(env "%.mlify")])
This allow to create a .ml file containing the various file you want to
include as string or string list.
There is no release for now, as the project is tightly coupled with
ocaml-autobuild which is not yet released.
Sylvain Le Gall
> Is there a syntax extension that allows a string to be assigned theThank you all for your suggestions. I ended up using xstrp4, because
> contents of a file? (...)
its "include_file" facility allows me to directly assign to a string
the unadulterated contents of an external file.