Quotation System in Original Syntax for Ocaml Abstract
Syntax Trees
Warning: This is a legacy page that is only
available for historical reasons. I stopped developing OCamlp5
(called OCamlp4 at that time) in spring 2007 when Nicolas
Pouillard
announced a rewrite of Camlp5 on the OCaml list.
The quotation expander q_MLast.cmo from Camlp5
requires you to use the revised syntax in the quotation. A
quotation for two imperative updates looks like this:
<:expr< do { flag.val := not flag.val; record.field := 2 } >>
With the software from this page one can relax and instead write
something which looks more familiar:
<:expr< flag := not !flag; record.field <- 2 >>
This package ocamlp5 (ocamlp5 stands for Original syntax for
Camlp5) contains
- a quotation expander qo_MLast for ocaml abstract syntax tree (ast)
nodes that uses the original syntax inside the quotations
- an Ocaml ast pretty printer written with original quotations (i.e.
the quotation system in qo_MLast provided here)
- the same written with revised quotations (i.e. the quotation
system in q_MLast in the ocaml distribution)
- an Camlp5 parsing module for Ocaml written with original quotations
- the qocheck test frame
Warning! This is work in progress.
The package currently supports
the core language, modules, module types, classes and class
types.
Polymorphic variants, optional or labelled arguments are
not supported (yet).
See the documentation or the file test_input.ml to see what is currently supported.
Download
(See News for a description of the differences
between 0.2 and 0.3)
Version 0.3:
[tar.gz]
Version 0.2:
[tar.gz]
Documentation
The Original quotation documentation
contains all forms of quotations, anti-quotations and their
types.
The README file contains other relevant
information, especially for the test frame qocheck.
Differences to the quotations in revised syntax
The quotation expander qo_MLast differs from q_MLast (which is
contained in the Ocaml distribution) in the following ways:
- original syntax inside quotations (see below for
incompatibilities)
- no support for optional or labelled arguments (yet), see the documentation or the file test_input.ml for precise information
- full support for the bigarray syntax
- support all prefix and infix operators (and not only the
predefined ones)
- support for immediate objects
- full documentation available
(including the types of the anti-quotations)
The original syntax in the quotations differs in the following
ways from what is accepted by the official Camlp5 parser pa_o:
- declare blocks (from revised
syntax) are accepted inside modules, module types, objects and
object types.
- no terminating semicolons in sequences, records and the like
(I view this as shortcoming of Camlp5's LIST0 and LIST1 operators)
More on Camlp5
During the development I found out about some features of Camlp5,
especially of the revised syntax, that are not described in
the Camlp5 reference manual. I'll describe all that on a
separate page on the undocumented
features of Camlp5.
News
- version 0.3:
-
- Development has been stalled since the Nicolas Pouillard's announcement of a renovation of Camlp4,
because it is still unclear whether he will support
quotations in the original syntax.
This version is a snapshot for those who want to use ocamlp5 with ocaml 3.09
in the meantime. If Nicolas does not support quotations in
original syntax in ocaml 3.10 (as the beta release seems to indicate)
I will continue this project.
- covers immediate objects and the new syntax in 3.09 (I
believe), polymorphic variants are the last piece that is not
supported yet
- out-of-date documentation (sorry but if Nicolas supports
original syntax it is not worth the trouble)
- version 0.2:
-
- cover module language, classes and class types (no polymorphic
variants, no immediate objects)
- pretty printer indents nested structures
- version 0.1:
-
- first public release
- covers core language only (no modules, no classes, no
polymorphic variants)
Acknowledgements
This package contains significant portions of the Ocaml source
distribution. More precisely, the grammar in qo_MLast.ml is taken
almost literally from camlp5/etc/pa_o.ml, the semantic actions
are from qo_MLast.ml. The parser paqo_o is a translation of pa_o
to the original syntax (both in- and outside of quotations).
Disclaimer
I do not judge the advantages and disadvantages of the revised
syntax in any way. I only believe that most Ocaml users (like
myself) are not familiar with the revised syntax. For all those a
quotation system in the original syntax is certainly beneficial.
last changed on
20 Sep 2011
by Hendrik