package rtop

  1. Overview
  2. Docs

Source file reason_toploop.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# 1 "reason_toploop.cppo.ml"
(*
 * Copyright (c) 2015-present, Facebook, Inc.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *)

open Reason

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
  
# 19 "reason_toploop.cppo.ml"
  (* 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;
  
# 27 "reason_toploop.cppo.ml"
  r)


(* this file's triggered by utop/rtop *)
let main () =
  if List.exists ~f:((=) "camlp4o") !Topfind.predicates ||
     List.exists ~f:((=) "camlp4r") !Topfind.predicates then
    print_endline "Reason is incompatible with camlp4!"
  else begin
    
# 37 "reason_toploop.cppo.ml"
    if not (Toploop.prepare Format.err_formatter ()) then raise (Compenv.Exit_with_status 2);
    
# 39 "reason_toploop.cppo.ml"
    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 ~f:Reason_toolchain.To_current.copy_toplevel_phrase
            (Reason_toolchain.RE.use_file x));
     (* Toploop.print_out_sig_item := M17n_util.utf8_print_out_sig_item !Toploop.print_out_sig_item; *)
    (* Toploop.install_printer Predef.path_string Predef.type_string *)
    (*   (fun fmt obj -> M17n_util.utf8_print_string fmt (Obj.magic obj)); *)
  end