Skip to content

Commit

Permalink
Rename -pp-simple to -pp-ast
Browse files Browse the repository at this point in the history
Co-authored-by: Nathan Rebours <[email protected]>
Signed-off-by: Patrick Ferris <[email protected]>
  • Loading branch information
patricoferris and NathanReb committed Sep 25, 2024
1 parent d9f2c19 commit 0ea8c52
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 129 deletions.
16 changes: 8 additions & 8 deletions src/driver.ml
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,7 @@ let load_source_file fn =

type output_mode =
| Pretty_print
| Pp_simple
| Pp_ast
| Dump_ast
| Dparsetree
| Reconcile of Reconcile.mode
Expand Down Expand Up @@ -1150,7 +1150,7 @@ let process_file (kind : Kind.t) fn ~input_name ~relocate ~output_mode
Ast_io.write oc
{ input_name; input_version; ast }
~add_ppx_context:true)
| Pp_simple ->
| Pp_ast ->
with_output output ~binary:false ~f:(fun oc ->
let ppf = Stdlib.Format.formatter_of_out_channel oc in
let ast = add_cookies ast in
Expand Down Expand Up @@ -1200,12 +1200,12 @@ let set_output_mode mode =
match (!output_mode, mode) with
| Pretty_print, _ -> output_mode := mode
| _, Pretty_print -> assert false
| Dump_ast, Dump_ast | Pp_simple, Pp_simple | Dparsetree, Dparsetree -> ()
| Dump_ast, Dump_ast | Pp_ast, Pp_ast | Dparsetree, Dparsetree -> ()
| Reconcile a, Reconcile b when Poly.equal a b -> ()
| x, y ->
let arg_of_output_mode = function
| Pretty_print -> assert false
| Pp_simple -> "-pp-simple"
| Pp_ast -> "-pp-ast"
| Dump_ast -> "-dump-ast"
| Dparsetree -> "-dparsetree"
| Reconcile Using_line_directives -> "-reconcile"
Expand Down Expand Up @@ -1353,13 +1353,13 @@ let standalone_args =
Arg.Unit (fun () -> set_output_mode Dump_ast),
" Dump the marshaled ast to the output file instead of pretty-printing it"
);
( "-pp-simple",
Arg.Unit (fun () -> set_output_mode Pp_simple),
( "-pp-ast",
Arg.Unit (fun () -> set_output_mode Pp_ast),
" Pretty-print a simple version of the AST using the internal Pp_ast \
module. This is useful for comparing ASTs. For more configuration see \
the ppxlib-tools package." );
( "--pp-simple",
Arg.Unit (fun () -> set_output_mode Pp_simple),
( "--pp-ast",
Arg.Unit (fun () -> set_output_mode Pp_ast),
" Same as -pp-simple" );
( "--dump-ast",
Arg.Unit (fun () -> set_output_mode Dump_ast),
Expand Down
126 changes: 5 additions & 121 deletions test/501_migrations/one_migration.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,70 +3,11 @@ as the ppxlib AST is either 5.0.0 or 5.1.0. While the ppxlib AST is on 5.0.0, th
test checks whether parsing on 5.0.0 (result of test running on 5.0.0) is the same as
parsing on 5.1.0 and then migrating down to 5.0.0 (result of test running on 5.1.0).

The test is mostly useful for debuggung problems in a full round-trip. Since Ppxlib's
`pp-simple` option doesn't compactify or strip locations, its output is very long.
So let's only keep one example.
The test is mostly useful for debuggung problems in a full round-trip.

$ echo "let x : int = 5" > file.ml
$ ./identity_driver.exe -pp-simple file.ml
[ Pstr_attribute
{ attr_name = "ocaml.ppx.context"
; attr_payload =
PStr
[ Pstr_eval
( Pexp_record
( [ ( Lident "tool_name"
, Pexp_constant
(Pconst_string ( "ppxlib_driver", __loc, None))
)
; ( Lident "include_dirs"
, Pexp_construct ( Lident "[]", None)
)
; ( Lident "load_path"
, Pexp_construct ( Lident "[]", None)
)
; ( Lident "open_modules"
, Pexp_construct ( Lident "[]", None)
)
; ( Lident "for_package"
, Pexp_construct ( Lident "None", None)
)
; ( Lident "debug"
, Pexp_construct ( Lident "false", None)
)
; ( Lident "use_threads"
, Pexp_construct ( Lident "false", None)
)
; ( Lident "use_vmthreads"
, Pexp_construct ( Lident "false", None)
)
; ( Lident "recursive_types"
, Pexp_construct ( Lident "false", None)
)
; ( Lident "principal"
, Pexp_construct ( Lident "false", None)
)
; ( Lident "transparent_modules"
, Pexp_construct ( Lident "false", None)
)
; ( Lident "unboxed_types"
, Pexp_construct ( Lident "false", None)
)
; ( Lident "unsafe_string"
, Pexp_construct ( Lident "false", None)
)
; ( Lident "cookies"
, Pexp_construct ( Lident "[]", None)
)
]
, None
)
, __attrs
)
]
; attr_loc = __loc
}
; Pstr_value
$ ./identity_driver.exe -pp-ast file.ml
[ Pstr_value
( Nonrecursive
, [ { pvb_pat =
Ppat_constraint
Expand All @@ -89,65 +30,8 @@ So let's only keep one example.
> module F () = struct end
> module M = F ()
> EOF
$ ./identity_driver.exe -pp-simple file.ml
[ Pstr_attribute
{ attr_name = "ocaml.ppx.context"
; attr_payload =
PStr
[ Pstr_eval
( Pexp_record
( [ ( Lident "tool_name"
, Pexp_constant
(Pconst_string ( "ppxlib_driver", __loc, None))
)
; ( Lident "include_dirs"
, Pexp_construct ( Lident "[]", None)
)
; ( Lident "load_path"
, Pexp_construct ( Lident "[]", None)
)
; ( Lident "open_modules"
, Pexp_construct ( Lident "[]", None)
)
; ( Lident "for_package"
, Pexp_construct ( Lident "None", None)
)
; ( Lident "debug"
, Pexp_construct ( Lident "false", None)
)
; ( Lident "use_threads"
, Pexp_construct ( Lident "false", None)
)
; ( Lident "use_vmthreads"
, Pexp_construct ( Lident "false", None)
)
; ( Lident "recursive_types"
, Pexp_construct ( Lident "false", None)
)
; ( Lident "principal"
, Pexp_construct ( Lident "false", None)
)
; ( Lident "transparent_modules"
, Pexp_construct ( Lident "false", None)
)
; ( Lident "unboxed_types"
, Pexp_construct ( Lident "false", None)
)
; ( Lident "unsafe_string"
, Pexp_construct ( Lident "false", None)
)
; ( Lident "cookies"
, Pexp_construct ( Lident "[]", None)
)
]
, None
)
, __attrs
)
]
; attr_loc = __loc
}
; Pstr_module
$ ./identity_driver.exe -pp-ast file.ml
[ Pstr_module
{ pmb_name = Some "F"
; pmb_expr = Pmod_functor ( Unit, Pmod_structure [])
; pmb_attributes = __attrs
Expand Down

0 comments on commit 0ea8c52

Please sign in to comment.