[wg-camlp4] Structure/signature attributes suggestion

Alain Frisch alain.frisch at lexifi.com
Fri Oct 11 21:51:07 BST 2013


On 10/11/2013 7:26 PM, Gabriel Scherer wrote:
> My understanding of Alain's ";;[@..]" was that he introduced a specific
> "empty item" in the AST of the current structure/signature.

Attributes attached to signature/structure items are actually attached, 
in the Parsetree representation, to individual declarations, not items, 
because a group of mutually recursive type declarations count as a 
single item in the current definition of the Parsetree but one really 
wants to be able to attach attributes to each of them.  Floating 
attributes are just a new kind of structure/signature items in the 
Parsetree.


Concretely, we have today:


and signature_item_desc =
   | Psig_value of value_description
   | Psig_type of type_declaration list
   ...
   | Psig_include of module_type * attributes
   ...
   | Psig_attribute of attribute


and value_description =
     {
      ...
      pval_attributes: attributes;
     }

and type_declaration =
     {
      ...
      ptype_attributes: attributes;
     }


Another approach would be to split groups of declarations into 
successive items, as in the Types representation:

and signature_item =
     Sig_value of Ident.t * value_description
   | Sig_type of Ident.t * type_declaration * rec_status
   ...

(where rec_status indicates if the declaration is in the same group as 
the previous one)


This adds some invariants which are not represented in the data 
structure (a Trec_next Sig_type must immediately follow another 
Sig_type), but it allows for a more uniform representation of 
attributes.  (That said, it's also very useful to have attributes 
directly represented in the value_description/type_declaration/... 
records, especially in the Typedtree representation.)


Alain


More information about the wg-camlp4 mailing list