Warning: status of this documentation
This documentation tries to cover the latest version of Camlp4 (3.10) by explaining it from scratch and also by explaining differences with the previous version (3.09). This is a work in progress, but feel free to contribute (please send an email to firstname.lastname@example.org if you wish to obtain an account).
Here is a page that states the priorities of that documentation: Camlp4_documentation_priorities.
Camlp4 is a Pre-Processor-Pretty-Printer (this is what the "p4" part stands for) for the Objective Caml language.
- Pre-processor: Camlp4 may be used as a Pre-Processor for the Objective Caml compiler; the parsing is done by Camlp4, and the Objective Caml compiler resumes the rest of the compilation.
- Pretty-printer: Camlp4 can pretty print the normal OCaml concrete syntax or the revised one using a Pretty-Printer. It is therefore always possible to have a version of your sources compilable by the compiler Objective Caml without preprocessing.
Where to begin?
- The using Camlp4 page describes how to use the various Camlp4 executables.
- The syntax extension tutorial is a must-see for the new Camlp4 user, as it explains how to create a basic syntax extension module.
- The OCaml code generation tutorial provides information on how to generate OCaml code in Camlp4.
- The full parser tutorial explains how to use Camlp4 as a complete parser for a given grammar.
- pa_float, a simple OCaml extension showing how to locally transform the AST.
This part should be reorganized
Camlp4 can parse normal OCaml concrete syntax or any other user-definable syntax. As an example, an alternative syntax is provided, named Revised, because it tries to fix some problems of the original syntax.
OCaml-independent parts of Camlp4
The main source of documentation about theses parsers is: Extensible Parser.
However there are some related points.
It includes a Quotation system.
Camlp4 is also OCaml oriented
- Support of the Original and Revised syntax.
- Syntax extensions
- New Quotations for OCaml
- Reflective OCaml: Reflection in OCaml through Quotations
- Camlp4MapGenerator and Camlp4FoldGenerator: A way to "scrap your boiler plate" in OCaml
- Existing Camlp4 contributions (syntax extensions, quotations...)
- Relevant Source Files