.cmo
'' or ``.cma
'').camlp4
'' runs the Camlp4 program. The first
options are objects (``.cmo
'') or library (``.cma
'')
files which are loaded, selecting different parsing and printing
operations. Among these first options, it is also possible to use the
option ``-I
'' to select directories where objects and library
files are searched. But, important remark: by default, the system does not searches in the current directory: to select some object file,
e.g. ``foo.cmo
'' in the current directory, write
``./foo.cmo
'' or add the option ``-I .
''./usr/local/lib/camlp4
: in the whole document, this
directory is named camlp4-lib-dir
). The provided files are:pa_o.cmo
: OCaml.
pa_r.cmo
: Revised: this is an alternative syntax for the
language (chapter 5).
pr_o.cmo
: Pretty print with OCaml syntax. Add an
option -l
to the command line to specify a line length.
pr_r.cmo
: Pretty print with revised syntax. Add this option
-l
too.
pr_dump.cmo
: Dump the syntax tree
pa_oop.cmo
: (to be loaded after ``pa_o.cmo
'')
Parsers and streams, with OCaml syntax, without code
optimization, corresponding to what is internally generated by
the OCaml compiler.
pa_op.cmo
: (to be loaded after ``pa_o.cmo
'')
Parsers and streams, with OCaml syntax, with code optimization.
pa_rp.cmo
: (to be loaded after ``pa_r.cmo
'')
Parsers and streams, with revised syntax and code optimization.
pa_extend.cmo
: (to be loaded either after
``pa_o.cmo
'' or ``pa_r.cmo
'') Syntax extensions for the
Camlp4 grammar system (Chapter 3).
pa_ifdef.cmo
: add ifdef
statement like in C
(conditional compilation), in expressions or structure items. Add
the options -D
and -U
to the camlp4 command line. To
define the symbol FOO
, either use ``-DFOO
'' in the
camlp4 command line, e.g.:
camlp4o pa_ifdef.cmo -DFOO file.mlor make a file, e.g. ``
foo.ml
'', holding
Pa_ifdef.define "FOO";;compile it and load its corresponding object file:
camlp4o pa_ifdef.cmo ./foo.cmo file.mlTo undefine the symbol
FOO
, use either ``-UFOO
'' or
the function ``Pa_ifdef.undef
''. The statement
``ifdef
'' can be used in a place of a structure item or an expression:
in this last case, ``else
'' is mandatory:
ifdef FOO then type t = A of int;; let f x = ifdef FOO then x + 1 else x - 1;;
pa_ru.cmo
: (to be loaded after ``pa_r.cmo
'' only)
Add type constraints of type unit
inside sequences.
pr_op.cmo
:
Try to rebuild parsers and streams in OCaml syntax.
pr_rp.cmo
: Try to rebuild parsers and streams in revised syntax.
pr_extend.cmo
: Try to rebuilt EXTEND instructions.
pr_depend.cmo
: Print file dependencies.
camlp4o
'' is equivalent to:
camlp4 pa_o.cmo pa_op.cmo pr_dump.cmo
camlp4r
'' is equivalent to:
camlp4 pa_r.cmo pa_rp.cmo pr_dump.cmo
pr_dump.cmo
''. The OCaml compiler
``ocamlc
'' recognizes it as a dump, and does not apply another
parsing. In case of typing errors, the error is normally showed
in the input file.ocaml
'' has an option
``-pp
'' for calling a preprocessor which automatically deals
with intermediate files (see the documentation of OCaml). So,
the normal use of the combination Camlp4-OCaml is done by the
command:ocamlc -pp "camlp4 camlp4-options" ocaml-options input-filesIt 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.pr_o.cmo
'', instead of
``pr_dump.cmo
'' for OCaml preprocessing, but it is not
recommended, for:
pa_o.cmo
accepts a syntax larger than OCaml's (some
syntax restriction is done in pr_dump.cmo
)
pr_o.cmo
'' for OCaml 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.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
OCaml syntax.
camlp4r.cma
'' to continue with
the Revised syntax.
#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.#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.pr_dump.cmo
'', the other
printing files, displaying source text, are just provided for
convenience and their behaviors are not (yet) modifiable.