[wg-camlp4] Changes to the parsetree

Alain Frisch alain.frisch at lexifi.com
Tue Mar 26 11:34:32 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 would also make sense to merge the ptype_variance 
information into ptype_params (probably introducing a record type to 
represent each type parameter).

> Before you submit the changes to the core team, we really need to add
> the:
>      {x{ ... }x}
> syntax for use with quotations. It should be simple enough to add to the
> lexer, and then accept as a "constant" in the parser. In the parsetree
> it should either be represented by its own node (Const_quote) or just
> translated into a Const_string.

I've committed this change, using {x| ... |x} instead of {x{ ... }x} 
(this just looks more readable to me; feel free to object).  In this 
syntax, x is an arbitrary (possibly empty) sequence of lowercase 
letters, no whitespaces allowed between { and |.  Inside the quoted 
string, no character is interpreted in a special way.  In the Parsetree, 
this is represented by changing Const_string to:

   | Const_string of string * string option

where the delimiter is stored in the "string option" (None for the 
regular syntax of OCaml strings).

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:


Leo: you mentioned that you're working on a revised ocamldoc.  Do you 
have plans to have it rely on attributes?


More information about the wg-camlp4 mailing list