Skip to content

Commit

Permalink
WIP: parse the keywords item from OCAMLPARAM
Browse files Browse the repository at this point in the history
TODO:
 - Should be 5.3+
 - Command line option as well?
 - Duplicates the splitting logic slightly with Compenv

Signed-off-by: David Allsopp <[email protected]>
  • Loading branch information
dra27 committed Nov 5, 2024
1 parent 8a0cb71 commit 50bdcac
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/driver.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1414,9 +1414,30 @@ let standalone_args =
let get_args ?(standalone_args = standalone_args) () =
standalone_args @ List.rev !args

let apply_keyword_edition () =
match Sys.getenv_opt "OCAMLPARAM" with
| None -> ()
| Some s ->
let items =
if String.equal s "" then []
else
(* cf. Compenv.parse_args *)
match s.[0] with
| (':' | '|' | ';' | ' ' | ',') as sep ->
List.tl (String.split_on_char s ~sep)
| _ -> String.split_on_char s ~sep:','
in
let apply_if_keyword item =
if String.starts_with ~prefix:"keywords=" item then
Clflags.keyword_edition :=
Some (String.sub item ~pos:9 ~len:(String.length item - 9))
in
List.iter items ~f:apply_if_keyword

let standalone_main () =
let usage = Printf.sprintf "%s [extra_args] [<files>]" exe_name in
let args = get_args () in
apply_keyword_edition ();
Arg.parse (Arg.align args) set_input usage;
interpret_mask ();
if !request_print_transformations then (
Expand Down
1 change: 1 addition & 0 deletions src/dune
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
(public_name ppxlib)
(libraries
(re_export ppxlib_ast)
compiler-libs.common
ocaml-compiler-libs.shadow
astlib
ppxlib_print_diff
Expand Down

0 comments on commit 50bdcac

Please sign in to comment.