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

rtop: work around #use .. syntax errors #2793

Merged
merged 1 commit into from
Aug 21, 2024
Merged
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
38 changes: 24 additions & 14 deletions rtop/reason_toploop.cppo.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,37 @@
* LICENSE file in the root directory of this source tree.
*)

(* this file's triggered by utop/rtop *)
let main () =
if List.exists ((=) "camlp4o") !Topfind.predicates ||
List.exists ((=) "camlp4r") !Topfind.predicates then
print_endline "Reason is incompatible with camlp4!"
else begin
Toploop.parse_toplevel_phrase := Reason_util.correctly_catch_parse_errors
(fun x ->
let r = Reason_toolchain.To_current.copy_toplevel_phrase
(Reason_toolchain.RE.toplevel_phrase x)
in
let default_parse_toplevel_phrase = !Toploop.parse_toplevel_phrase
let reason_parse_toplevel_phrase =
Reason_util.correctly_catch_parse_errors
(fun x ->
let r =
Reason_toolchain.To_current.copy_toplevel_phrase
(Reason_toolchain.RE.toplevel_phrase x)
in
#if OCAML_VERSION >= (5,2,0)
(* NOTE(anmonteiro): after https://github.com/ocaml/ocaml/pull/12029, we get a
(* NOTE(anmonteiro): after https://github.com/ocaml/ocaml/pull/12029, we get a

Fatal error: exception Invalid_argument("index out of bounds")
Raised by primitive operation at Toploop.ends_with_lf in file "toplevel/toploop.ml"

Setting `lex_eof_reached` seems to avoid whatever check upstream is doing. *)
x.lex_eof_reached <- true;
x.lex_eof_reached <- true;
#endif
r);
r)


(* this file's triggered by utop/rtop *)
let main () =
if List.exists ((=) "camlp4o") !Topfind.predicates ||
List.exists ((=) "camlp4r") !Topfind.predicates then
print_endline "Reason is incompatible with camlp4!"
else begin
Toploop.parse_toplevel_phrase := (fun t ->
if !Reason_utop.current_top = UTop then
default_parse_toplevel_phrase t
else
reason_parse_toplevel_phrase t);
Toploop.parse_use_file := Reason_util.correctly_catch_parse_errors
(fun x -> List.map Reason_toolchain.To_current.copy_toplevel_phrase
(Reason_toolchain.RE.use_file x));
Expand Down
Loading