[wg-camlp4] Changes to the parsetree

Leo White lpw25 at cam.ac.uk
Tue Mar 26 19:56:49 GMT 2013

> On 03/25/2013 03:05 PM, Leo White wrote:
>> Another small clean-up I'd like would be to change "ptype_params" from
>> "string loc option list" to "core_type list" and the first part of
>> "pci_params" from "string loc list" to "core_type list".
> Would you change the parser to accept arbitrary types (instead of _ and type variables), and enforce the previous
> constraint in the type-checker?  

It might be better to get a syntax error there as it's probably
a common beginner mistake. On the other hand, if the error from the type
checker is nice and clear then it shouldn't be a problem. Either way, we
might as well support extensions and attributes there.

> I've committed this change, using {x| ... |x} instead of {x{ ... }x} (this just looks more readable to me; feel free to
> object).

I slightly prefer {{ ... }} but either seems fine.

> In this syntax, x is an arbitrary (possibly empty) sequence of lowercase letters, no whitespaces allowed
> between { and |.

It might be better for x to be a sequence of operator symbols (and maybe
numbers), since most lexical tokens in OCaml are all symbols or all
characters, but this is probably a matter of taste.

> Another change I've committed recently is an update to the Typedtree representation, to bring it closer to the current
> state of the Parsetree, including attributes.  This makes it possible for external tools to process attributes in
> .cmt/.cmti files.  I've committed an example of a "mini-ocamldoc" based on this technique:
> http://caml.inria.fr/cgi-bin/viewvc.cgi/ocaml/branches/extension_points/experimental/frisch/minidoc.ml?revision=HEAD&view=markup
> http://caml.inria.fr/cgi-bin/viewvc.cgi/ocaml/branches/extension_points/experimental/frisch/testdoc.mli?revision=HEAD&view=markup 
> Leo: you mentioned that you're working on a revised ocamldoc.  Do you have plans to have it rely on attributes?

My plans, which are about half implemented, are for the compiler (or
ocamldoc) to be able to produce a ".cmd" file describing the
documentation for a module. Then tools can combine this file with a
".cmt" file to produce the actual documentation.

The ".cmd" file is kept separate from the ".cmt" to make it easier to do
things like providing multiple translations for documentation, creating
documentation not related to a source file, or using a single
documentation article for multiple source files.

While I think that comments are a good place for documentation, and will
primarily support the current ocamldoc format, it would be very simple
to write a "-ppx" that created a ".cmd" file from attributes. It would
also be very easy to write a tool that extracted a ".cmd" file from the
attributes in a ".cmt" file.

More information about the wg-camlp4 mailing list