The standard use of Camlp4 is as a preprocessor for Objective Caml
with the printer ``pr_dump.cmo''. The Objective Caml compiler
``ocamlc'' recognizes it is a dump, and does not apply another
parsing. In case of typing errors, the error is normally showed
in the input file.
We remind that the command ``ocaml'' has an option
``-pp'' for calling a preprocessor which automatically deals
with intermediate files (see the documentation of Objective Caml). So,
the normal use of the combinaison Camlp4-Objective Caml is done by the
command:
ocamlc -pp "camlp4 camlp4-options" ocaml-options input-files
It is often necessary to add the Camlp4 library directory in
ocaml's path, using option ``-I''. For information, the Camlp4
command has an option ``-where'' echoing the full name of this
directory.
It is possible to use Camlp4 with ``pr_o.cmo'', instead of
``pr_dump.cmo'' for Objective
Caml preprocessing, but it is not recommended, for:
pa_o.cmo accepts a syntax larger than Objective Caml's (some
syntax restriction is done in pr_dump.cmo)
However, there is a case where it is interesting to use
``pr_o.cmo'' for objective Caml preprocessing. When the error
is located in a quotation (chapter 2) or in a syntax
extension (chapter 4), it is not always obvious to
understand where the error is exactly located, and there may be no
location for the error. Using temporarily camlp4 with
``pr_o.cmo'' allows to see the exact location of the error,
which can be understood by the programmer of the quotation expander or
the syntax extension.
The Objective Caml toplevel, ``ocaml'' can use Camlp4. To do
this, it must be started with the option ``-I Camlp4
library directory'', or, under Unix, ``-I `camlp4 -where`''.
Then, one must load:
camlp4o.cma'' to continue with
Objective Caml syntax.
camlp4r.cma'' to continue with
the Righteous syntax.
To change the behavior of Camlp4, just load the needed module with
the directives ``#load'' and ``#use'': for example, each
load of ``pa_o.cmo'' or ``pa_r.cmo'' would change
the current input syntax to be used in the next sentences.
The files included by the directive ``#use'' are treated by the
current Camlp4 syntax too. Important remark: a syntax modification
takes place after the complete load of a file, not after each sentence
inside the file.
It is not possible to load a Camlp4 printing syntax file in the toplevel. The printing results are done by the Objective Caml toplevel in standard Objective Caml syntax.