[wg-camlp4] About 'a loc in the Parsetree

Alain Frisch alain.frisch at lexifi.com
Thu Apr 4 13:58:21 BST 2013


Dear all (caml-devel + wg-camlp4),

I'd like to discuss the use of the 'a loc type (string loc and 
Longident.loc) in the definition of the Parsetree.  I think this type 
was introduced as part of the "binannot" project, in order to keep more 
location information in the Typedtree, to be used by external tools 
reading .cmt files.

First, some "unlocated" identifiers remain in the Parsetree
(cf Ptyp_var, Ptyp_alias, Ptyp_poly, Pfield, Pexp_send, Pexp_newtype, 
Pctf_val, Pctf_virt, Pctf_meth, Pcf_inher).  I assume this is simply an 
oversight. Or is there any deeper reason for keeping locations for some 
identifiers but not all of them?

Second, some locations are redundant for constructions whose syntax is 
just the identifier (Ppat_var, Pexp_ident, Pmty_ident, Pmod_ident).  The 
same location is store in the 'a loc record and in pexp_loc/ppat_loc/etc 
field.  I guess that the rationale is that some imaginary alternative 
concrete syntax for the language would use a different representation 
for those constructions.  Another argument is uniformity of 
representation.  But those redundant location introduce some overhead 
when building and deconstructing very common fragments of Parsetrees. 
For building fragments, this can be largely accommodated by the use of 
constructor functions, but for pattern matching on AST, there is no such 
easy solution.  One could consider getting rid of those redundant "'a 
loc" wrappers.  Any opinion on this topic?


Alain



More information about the wg-camlp4 mailing list