bs-batteries
Version:
Ocaml batteries for bucklescript
92 lines (60 loc) • 2.16 kB
Plain Text
Optional compilation with cpp-like directives
Jeremie Dimino <jeremie@dimino.org>
December 2008
* What it does
Optcomp is a syntax extension which handles
in ocaml source files.
For example, to switch between two pieces of code according to the
ocaml compiler version, one can write:
let x = 1
let x = 2
* What the difference between cpp and optcomp ?
Optcomp is more caml-friendly than cpp:
- it does not interpret "//", "/*", and "*/" as comment delimiters
- it does not complains about missing "'"
- it is easier to integrate in the build process when using other
camlp4 syntax extensions
By the way optcomp does not do macro expansion while cpp does.
* What the difference between pa_macro and optcomp ?
Optcomp does not require code that will be dropped to be valid caml
code. So for example this code will be rejected by camlp4+pa_macro:
let f = function
| <:patt< $id:id$ >> -> "ident"
| <:patt< $int:x$ >> -> "int"
| <:patt< $x$, $y$ >> -> "pair"
IFDEF HAVE_LAZY_PATTERNS THEN
| <:patt< lazy x >> -> "lazy"
ENDIF
But this one will be accepted by camlp4+optcomp:
let f = function
| <:patt< $id:id$ >> -> "ident"
| <:patt< $int:x$ >> -> "int"
| <:patt< $x$, $y$ >> -> "pair"
| <:patt< lazy x >> -> "lazy"
* Building instructions
To compile optcomp type:
$ make
* Installation
To install optcomp type:
$ make install
and to uninstall it:
$ make uninstall
* How to use it
You can use optcomp with ocamlfind, with the package optcomp or you
can directly include it in your project.
* Hacking
To add support to more expressions, you can modify the eval function
of pa_optcomp.ml. It takes a camlp4 expression ast and must return
something of type value.
* Development
The last development version of optcomp can always be found in the
darcs repository hosted at darcs.ocamlcore.org:
$ darcs get http://darcs.ocamlcore.org/repos/optcomp/optcomp
local variables:
mode: outline
end: