Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PoC: support OCaml 5.3's keywords entry in OCAMLPARAM #535

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ details.

- Add initial OCaml 5.3 support (#487, @NathanReb, @hhugo, @nojb)

- Initialise OCaml 5.3's lexer with the `keywords` setting from `OCAMLPARAM` to
allow the standalone ppx driver to process old packages using `effect` as an
identifier (#535, @dra27)

### Other changes

- Fix `deriving_inline` round-trip check so that it works with 5.01 <-> 5.02
Expand Down
24 changes: 24 additions & 0 deletions astlib/keyword.ml
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,27 @@ let is_keyword = function
| "lsr" -> true
| "asr" -> true
| _ -> false

let apply_keyword_edition () =
match Sys.getenv "OCAMLPARAM" with
| s ->
let items =
if String.equal s "" then []
else
(* cf. Compenv.parse_args *)
match s.[0] with
| (':' | '|' | ';' | ' ' | ',') as c ->
List.tl (String.split_on_char c s)
| _ -> String.split_on_char ',' s
in
let fold_settings acc item =
let len = String.length item in
if len >= 9 && String.sub item 0 9 = "keywords=" then
Some (String.sub item 9 (len - 9))
else acc
in
let keyword_edition = List.fold_left fold_settings None items in
(*IF_AT_LEAST 503 let () = if Option.is_some keyword_edition then Clflags.keyword_edition := keyword_edition in*)
(*IF_NOT_AT_LEAST 503 let () = ignore keyword_edition in*)
()
| exception Not_found -> ()
4 changes: 4 additions & 0 deletions astlib/keyword.mli
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
val is_keyword : string -> bool
(** Check if a string is an OCaml keyword. *)

val apply_keyword_edition : unit -> unit
(** Processes any keywords= sections from the OCAMLPARAM environment variable
and initialises the compiler's lexer with the correct keyword set. *)
1 change: 1 addition & 0 deletions src/driver.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1417,6 +1417,7 @@ let get_args ?(standalone_args = standalone_args) () =
let standalone_main () =
let usage = Printf.sprintf "%s [extra_args] [<files>]" exe_name in
let args = get_args () in
Astlib.Keyword.apply_keyword_edition ();
Arg.parse (Arg.align args) set_input usage;
interpret_mask ();
if !request_print_transformations then (
Expand Down
Loading