[wg-camlp4] Reconciling Merlin and ppx

Frédéric Bour defree at gmail.com
Mon Nov 4 12:39:21 GMT 2013


On 04/11/2013 10:07, Alain Frisch wrote:
> On 11/02/2013 06:21 PM, Yaron Minsky wrote:
>> A better idea, perhaps, would be to have some libraries or standards
>> about how to present an AST transformer so that it's suitable for
>> running against a partial AST. I don't really know the details of how
>> Merlin works, but I understand it does a first pass to parse
>> expressions into top-level units, the parsing of which is done
>> independently. AST transformers that operate on those units would
>> naturally gain some level of incrementality.
>
> I don't know anything about Merlin. I assume that it uses a special 
> representation of the AST which is more robust w.r.t. ill-formed 
> fragments (syntax errors). Is that right? Could this representation of 
> partial ASTs be encoded in the official Parsetree using extension 
> nodes to denote invalid fragments? Independently of the question of 
> supporting ppx transformers, anything which brings Merlin closer to 
> the official system is likely to make it more future-proof.

Merlin uses the original AST definition, so that the typer can be used 
with minimal modifications.
Internally the Ocaml AST for a given file is split in a list of chunks 
(around one per definition plus a special case for entering/exiting 
sub-structures).

The two changes wrt to ASTs produced by original ocaml are:
− an hack to store more positional information in AST Nodes, by 
working-around ocaml value representation.
− when detected and recoverable, ill-formed expressions are replaced by 
an expression of type "forall 'a .'a".

The first case could obviously be made less hacky through extension nodes.

>
> Alain
> _______________________________________________
> wg-camlp4 mailing list
> wg-camlp4 at lists.ocaml.org
> http://lists.ocaml.org/listinfo/wg-camlp4



More information about the wg-camlp4 mailing list