ppxlib icon indicating copy to clipboard operation
ppxlib copied to clipboard

Ast_builder documentation

Open patricoferris opened this issue 1 year ago • 2 comments

Related to: https://github.com/ocaml-ppx/ppxlib/issues/324, https://github.com/ocaml-ppx/ppxlib/issues/435

Much of Ast_builder is undocumented. The names of functions are derived from the things they construct from Ast.ml (mostly AST nodes from Parsetree). The parsetree is well-documented. This PR pulls through that documentation directly to Ast_builder.

In order for this to work well, the gen_ast_builder script now produces module types for the interface to Ast_builder (one for functions with ~loc arguments called S_located and one without, corresponding to the original S).

Before:

Screenshot 2024-08-30 at 14 53 03

After:

Screenshot 2024-08-30 at 14 49 12

Known problems:

Some of the doc attributes pulled from the parsetree contain odoc references which clash with the function names defined in the generated code e.g. type label_declaration and val label_declaration clash for the documentation comment attached to ptyp_poly.


If there is agreement to add this we could do the same for Ast_pattern I'm sure.

patricoferris avatar Aug 30 '24 13:08 patricoferris

On a slightly unrelated note, I wonder if we shouldn't change the way we generate those files to promote the generated sources so they can be inspected and we are notified whenever they are updated rather than all of it being silent as it is now. That's of course a matter for a separate PR but I'm still curious to know what you think about it!

I think that's a great idea and would make debugging a little easier I think (a few times, especially for docs, I was having to open _build/default/src/ast_builder_generated.ml

patricoferris avatar Sep 03 '24 16:09 patricoferris

@patricoferris I think you can go ahead and merge this!

NathanReb avatar Sep 23 '24 08:09 NathanReb