Skip to content

Commit

Permalink
Merge branch 'main' into feat/ppx-by-example
Browse files Browse the repository at this point in the history
* main: (22 commits)
  Remove vendored ppx_sexp_conv opam file
  Avoid duplication in gen_ast_builder
  Only pass type declaration once to gen_combinator_for_record
  Simplify type variable reconstruction
  Changelog entry
  Explicitly construct ast_builder floating comments
  Add sections and parsetree docs to ast_builder
  Refactor ast_builder to add documentation comments
  Support class type declarations in derivers
  Add configured and configurable printer types to Pp_ast
  Add Submodules with simpler APIs to Pp_ast
  Bring expect_in version ranges in line with opam notations
  Add [%%ignore] to expect_test runner and fix quoter tests
  Add support for single version [%%expect_in]
  Use [%%expect_in to make test pass under 5.3
  Make expect test runner compatible with 5.3+ again
  Make new [%%expect_in syntax compatible with ocamlformat
  Add versioned expect block to expect test runner
  Fix out of date test
  Replace -dparsetree sexp output with a pretty-printed AST
  ...
  • Loading branch information
pedrobslisboa committed Dec 9, 2024
2 parents 8bf8330 + 2414959 commit b398f9d
Show file tree
Hide file tree
Showing 24 changed files with 1,064 additions and 1,525 deletions.
11 changes: 10 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,16 @@ details.

- Add ppxlib's AST pretty-printing utilities in `Ppxlib.Pp_ast` and
a `ppxlib-pp-ast` executable in a new separate `ppxlib-tools` package
(#517, @NathanReb)
(#517, #525, #537, @NathanReb)

- Change `-dparsetree` from a sexp output to a pretty printed AST, closer
to what the compiler's `-dparsetree` is.
(#530, @NathanReb)

- Add Parsetree documentation comments to `Ast_builder` functions (#518, @patricoferris)

- Support class type declarations in derivers with the new, optional arguments
`{str,sig}_class_type_decl` in `Deriving.add` (#538, @patricoferris)

0.33.0 (2024-07-22)
-------------------
Expand Down
23 changes: 0 additions & 23 deletions bench/vendored/ppx_sexp_conv.v0.15.1/ppx_sexp_conv.opam

This file was deleted.

2 changes: 0 additions & 2 deletions doc/writing-ppxs.mld
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,6 @@ Global transformations are the most general kind of transformation. As such, the
factorised, resulting in slower compilation time.
- If you don't make sure that you really follow all {{!"good-practices"}good practices}, you might end up messing up the global developer experience.

- If you don't make sure that you really follow all {{!"good-practices"}good practices}, you might end up messing up the global developer experience.

For all these reasons, a global transformation should be avoided whenever a
context-free transformation could do the job, which by experience seems to be most of the time.
The API for defining a global transformation is easy. A global transformation consists simply of the function and can be directly be registered with {{!Ppxlib.Driver.register_transformation}[Driver.register_transformation]}.
Expand Down
6 changes: 1 addition & 5 deletions src/ast_builder_intf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,6 @@ type 'a with_location = loc:Location.t -> 'a

module type S = sig
module Located : Located with type 'a with_loc := 'a without_location

include module type of Ast_builder_generated.Make (struct
let loc = Location.none
end)

include Ast_builder_generated.Intf_located
include Additional_helpers with type 'a with_loc := 'a without_location
end
5 changes: 5 additions & 0 deletions src/attribute.ml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module Context = struct
| Class_infos : _ class_infos t
| Class_expr : class_expr t
| Class_field : class_field t
| Class_type_decl : class_type_declaration t
| Module_type : module_type t
| Module_declaration : module_declaration t
| Module_type_declaration : module_type_declaration t
Expand Down Expand Up @@ -54,6 +55,7 @@ module Context = struct
let class_infos = Class_infos
let class_expr = Class_expr
let class_field = Class_field
let class_type_decl = Class_type_decl
let module_type = Module_type
let module_declaration = Module_declaration
let module_type_declaration = Module_type_declaration
Expand Down Expand Up @@ -101,6 +103,7 @@ module Context = struct
| Class_infos -> x.pci_attributes
| Class_expr -> x.pcl_attributes
| Class_field -> x.pcf_attributes
| Class_type_decl -> x.pci_attributes
| Module_type -> x.pmty_attributes
| Module_declaration -> x.pmd_attributes
| Module_type_declaration -> x.pmtd_attributes
Expand Down Expand Up @@ -135,6 +138,7 @@ module Context = struct
| Class_infos -> { x with pci_attributes = attrs }
| Class_expr -> { x with pcl_attributes = attrs }
| Class_field -> { x with pcf_attributes = attrs }
| Class_type_decl -> { x with pci_attributes = attrs }
| Module_type -> { x with pmty_attributes = attrs }
| Module_declaration -> { x with pmd_attributes = attrs }
| Module_type_declaration -> { x with pmtd_attributes = attrs }
Expand Down Expand Up @@ -176,6 +180,7 @@ module Context = struct
| Class_infos -> "class declaration"
| Class_expr -> "class expression"
| Class_field -> "class field"
| Class_type_decl -> "class type declaration"
| Module_type -> "module type"
| Module_declaration -> "module declaration"
| Module_type_declaration -> "module type declaration"
Expand Down
2 changes: 2 additions & 0 deletions src/attribute.mli
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module Context : sig
| Class_infos : _ class_infos t
| Class_expr : class_expr t
| Class_field : class_field t
| Class_type_decl : class_type_declaration t
| Module_type : module_type t
| Module_declaration : module_declaration t
| Module_type_declaration : module_type_declaration t
Expand Down Expand Up @@ -60,6 +61,7 @@ module Context : sig
val class_infos : _ class_infos t
val class_expr : class_expr t
val class_field : class_field t
val class_type_decl : class_type_declaration t
val module_type : module_type t
val module_declaration : module_declaration t
val module_type_declaration : module_type_declaration t
Expand Down
49 changes: 49 additions & 0 deletions src/context_free.ml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ module Rule = struct
| Attr_sig_type_ext : (signature_item, type_extension) Attr_inline.t t
| Attr_str_exception : (structure_item, type_exception) Attr_inline.t t
| Attr_sig_exception : (signature_item, type_exception) Attr_inline.t t
| Attr_str_class_type_decl
: (structure_item, class_type_declaration) Attr_group_inline.t t
| Attr_sig_class_type_decl
: (signature_item, class_type_declaration) Attr_group_inline.t t

type (_, _) equality = Eq : ('a, 'a) equality | Ne : (_, _) equality

Expand All @@ -97,6 +101,8 @@ module Rule = struct
| Attr_sig_exception, Attr_sig_exception -> Eq
| Attr_str_module_type_decl, Attr_str_module_type_decl -> Eq
| Attr_sig_module_type_decl, Attr_sig_module_type_decl -> Eq
| Attr_str_class_type_decl, Attr_str_class_type_decl -> Eq
| Attr_sig_class_type_decl, Attr_sig_class_type_decl -> Eq
| _ -> Ne
end

Expand Down Expand Up @@ -159,6 +165,12 @@ module Rule = struct
let attr_sig_exception attribute expand =
T (Attr_sig_exception, T { attribute; expand; expect = false })

let attr_str_class_type_decl attribute expand =
T (Attr_str_class_type_decl, T { attribute; expand; expect = false })

let attr_sig_class_type_decl attribute expand =
T (Attr_sig_class_type_decl, T { attribute; expand; expect = false })

let attr_str_type_decl_expect attribute expand =
T (Attr_str_type_decl, T { attribute; expand; expect = true })

Expand All @@ -182,6 +194,12 @@ module Rule = struct

let attr_sig_exception_expect attribute expand =
T (Attr_sig_exception, T { attribute; expand; expect = true })

let attr_str_class_type_decl_expect attribute expand =
T (Attr_str_class_type_decl, T { attribute; expand; expect = true })

let attr_sig_class_type_decl_expect attribute expand =
T (Attr_sig_class_type_decl, T { attribute; expand; expect = true })
end

module Generated_code_hook = struct
Expand Down Expand Up @@ -515,6 +533,15 @@ class map_top_down ?(expect_mismatch_handler = Expect_mismatch_handler.nop)
|> sort_attr_inline |> Rule.Attr_inline.split_normal_and_expect
in

let attr_str_class_decls, attr_str_class_decls_expect =
Rule.filter Attr_str_class_type_decl rules
|> sort_attr_group_inline |> Rule.Attr_group_inline.split_normal_and_expect
in
let attr_sig_class_decls, attr_sig_class_decls_expect =
Rule.filter Attr_sig_class_type_decl rules
|> sort_attr_group_inline |> Rule.Attr_group_inline.split_normal_and_expect
in

let map_node = map_node ~hook ~embed_errors in
let map_nodes = map_nodes ~hook ~embed_errors in
let handle_attr_group_inline = handle_attr_group_inline ~embed_errors in
Expand Down Expand Up @@ -787,6 +814,17 @@ class map_top_down ?(expect_mismatch_handler = Expect_mismatch_handler.nop)
>>= fun expect_items ->
with_extra_items expanded_item ~extra_items ~expect_items
~rest ~in_generated_code
| Pstr_class_type cds, Pstr_class_type exp_cds ->
handle_attr_group_inline attr_str_class_decls Nonrecursive
~items:cds ~expanded_items:exp_cds ~loc ~base_ctxt
~convert_exn
>>= fun extra_items ->
handle_attr_group_inline attr_str_class_decls_expect
Nonrecursive ~items:cds ~expanded_items:exp_cds ~loc
~base_ctxt ~convert_exn
>>= fun expect_items ->
with_extra_items expanded_item ~extra_items ~expect_items
~rest ~in_generated_code
| _, _ ->
self#structure base_ctxt rest >>| fun rest ->
expanded_item :: rest))
Expand Down Expand Up @@ -885,6 +923,17 @@ class map_top_down ?(expect_mismatch_handler = Expect_mismatch_handler.nop)
>>= fun expect_items ->
with_extra_items expanded_item ~extra_items ~expect_items
~rest ~in_generated_code
| Psig_class_type cds, Psig_class_type exp_cds ->
handle_attr_group_inline attr_sig_class_decls Nonrecursive
~items:cds ~expanded_items:exp_cds ~loc ~base_ctxt
~convert_exn
>>= fun extra_items ->
handle_attr_group_inline attr_sig_class_decls_expect
Nonrecursive ~items:cds ~expanded_items:exp_cds ~loc
~base_ctxt ~convert_exn
>>= fun expect_items ->
with_extra_items expanded_item ~extra_items ~expect_items
~rest ~in_generated_code
| _, _ ->
self#signature base_ctxt rest >>| fun rest ->
expanded_item :: rest))
Expand Down
12 changes: 12 additions & 0 deletions src/context_free.mli
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,18 @@ module Rule : sig

val attr_sig_exception_expect :
(signature_item, type_exception, _) attr_inline

val attr_str_class_type_decl :
(structure_item, class_type_declaration, _) attr_group_inline

val attr_sig_class_type_decl :
(signature_item, class_type_declaration, _) attr_group_inline

val attr_str_class_type_decl_expect :
(structure_item, class_type_declaration, _) attr_group_inline

val attr_sig_class_type_decl_expect :
(signature_item, class_type_declaration, _) attr_group_inline
end

(**/**)
Expand Down
Loading

0 comments on commit b398f9d

Please sign in to comment.