Quotation System in Original Syntax for Ocaml Abstract
Syntax Trees
The quotation expander q_MLast.cmo in the Ocaml distribution
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 ocamlp4 (ocamlp4 stands for Original syntax for
CAMLP4) 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 Camlp4 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
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)
- 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 Camlp4 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 Camlp4's LIST0 and LIST1 operators)
More on Camlp4
During the development I found out about some features of Camlp4,
especially of the revised syntax, that are not described in
the Camlp4 reference manual. I'll describe all that on a
separate page on the undocumented
features of Camlp4.
News
- 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 camlp4/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
7 Oct 2005
by Hendrik