Loading ...
Sorry, an error occurred while loading the content.
 

Re: Syntax extension for including strings from external file

Expand Messages
  • Sylvain Le Gall
    ... There is a small utility call ocamlify: https://forge.ocamlcore.org/projects/ocamlify/ http://darcs.ocamlcore.org/repos/ocamlify/ocamlify/ (darcs
    Message 1 of 6 , Jul 9, 2009
      On 09-07-2009, Dario Teixeira <darioteixeira@...> wrote:
      >
      > Hi,
      >
      > Is there a syntax extension that allows a string to be assigned the content=
      > s
      > 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
      > Hump,
      > 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.
      >

      There is a small utility call ocamlify:
      https://forge.ocamlcore.org/projects/ocamlify/
      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:
      http://darcs.ocamlcore.org/repos/ocaml-autobuild/ocaml-autobuild/src/base/BaseData.mlify

      with the following rules in ocamlbuild:
      let ocamlify = A"ocamlify";;

      rule "ocamlify: %.mlify -> %.mlify.depends"
      ~prod:"%.mlify.depends"
      ~dep:"%.mlify"
      begin
      fun env _ ->
      Cmd(S[ocamlify;
      T(tags_of_pathname (env "%.mlify")++"ocamlify"++"depends");
      A"--depends";
      A"--output"; P(env "%.mlify.depends");
      P(env "%.mlify");])
      end
      ;;

      rule "ocamlify: %.mlify & %.mlify.depends -> %.ml"
      ~prod:"%.ml"
      ~deps:["%.mlify"; "%.mlify.depends"]
      begin
      fun env build ->
      depends_from_file
      env
      build
      (env "%.mlify.depends");
      Cmd(S[ocamlify; A"--output"; P(env "%.ml"); P(env "%.mlify")])
      end
      ;;


      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.

      Regards,
      Sylvain Le Gall
    • Dario Teixeira
      Hi, ... Thank you all for your suggestions. I ended up using xstrp4, because its include_file facility allows me to directly assign to a string the
      Message 2 of 6 , Jul 10, 2009
        Hi,

        > Is there a syntax extension that allows a string to be assigned the
        > contents of a file?  (...)

        Thank you all for your suggestions. I ended up using xstrp4, because
        its "include_file" facility allows me to directly assign to a string
        the unadulterated contents of an external file.

        Cheers,
        Dario Teixeira
      Your message has been successfully submitted and would be delivered to recipients shortly.