Skip to content

Commit

Permalink
Fix #1: incompatibility with toplevel
Browse files Browse the repository at this point in the history
Reported by Daian Yue.
  • Loading branch information
thierry-martinez committed Feb 28, 2021
1 parent bc28b4a commit db00365
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 2021-02-28, version 0.2.1

- Fix #1: incompatibility with toplevel
(Reported by Daian Yue).

# 2020-05-21, version 0.2.0

- Reverse the parenthesis and the constructor name for single argument,
Expand Down
2 changes: 1 addition & 1 deletion COPYING
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BSD 2-Clause License

Copyright (c) 2019-2020, Thierry Martinez.
Copyright (c) 2019-2021, Thierry Martinez.
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
14 changes: 7 additions & 7 deletions src/ppx_show.ml
Original file line number Diff line number Diff line change
Expand Up @@ -375,23 +375,23 @@ let show_type_of_type_decl (td : type_declaration) : value_description =
Ast_helper.Val.mk name ty
end

let make_str ~loc ~path (rec_flag, tds) (with_path : expression option)
let make_str ~ctxt (rec_flag, tds) (with_path : expression option)
: structure =
let with_path =
match with_path with
| Some [%expr false] -> None
| _ ->
match String.split_on_char '.' (Filename.basename path) with
| filename :: "ml" :: path
| filename :: _ :: "ml" :: path ->
Some (String.capitalize_ascii filename :: path)
| _ -> prerr_endline path; assert false in
let code_path = Ppxlib.Expansion_context.Deriver.code_path ctxt in
let main_module_name = Ppxlib.Code_path.main_module_name code_path in
let submodule_path = Ppxlib.Code_path.submodule_path code_path in
Some (main_module_name :: submodule_path) in
let vbs = tds |> List.map (pp_of_type_decl ~with_path) in
let loc = Ppxlib.Expansion_context.Deriver.derived_item_loc ctxt in
[Ast_helper.Str.value ~loc rec_flag vbs;
Ast_helper.Str.value ~loc Nonrecursive (tds |> List.map show_of_type_decl)]

let str_type_decl =
Ppxlib.Deriving.Generator.make
Ppxlib.Deriving.Generator.V2.make
Ppxlib.Deriving.Args.(empty +>
arg "with_path" __)
make_str
Expand Down

0 comments on commit db00365

Please sign in to comment.