Print out a nice message if trying to load camlp4 with no support.

This handles #camlp4o;; #camlp4r;; and also indirect cases
like #require "sexplib.syntax";;.
This commit is contained in:
Peter Zotov 2014-10-20 20:04:18 +04:00
parent 9254d5cf92
commit f17f8f2959
1 changed files with 21 additions and 17 deletions

View File

@ -602,6 +602,14 @@ let handle_findlib_error = function
| exn -> | exn ->
raise exn raise exn
let check_for_camlp4_support () =
try
ignore (Fl_package_base.query "utop.camlp4");
true
with Fl_package_base.No_such_package("utop.camlp4", "") ->
Lwt_main.run (print_error "utop was built without camlp4 support.\n");
false
let set_syntax syntax = let set_syntax syntax =
match get_syntax (), syntax with match get_syntax (), syntax with
| Normal, Normal | Normal, Normal
@ -610,25 +618,21 @@ let set_syntax syntax =
() ()
| (Camlp4o | Camlp4r), _ -> | (Camlp4o | Camlp4r), _ ->
Lwt_main.run (print_error "Camlp4 already loaded, you cannot change the syntax now.\n") Lwt_main.run (print_error "Camlp4 already loaded, you cannot change the syntax now.\n")
| Normal, Camlp4o -> begin | Normal, Camlp4o ->
set_syntax Camlp4o; if check_for_camlp4_support () then begin
set_phrase_terminator ";;";
try
Topfind.syntax "camlp4o"; Topfind.syntax "camlp4o";
Topfind.load_deeply ["utop.camlp4"] Topfind.load_deeply ["utop.camlp4"];
with exn -> set_syntax Camlp4o;
handle_findlib_error exn set_phrase_terminator ";;"
end end
| Normal, Camlp4r -> begin | Normal, Camlp4r ->
set_syntax Camlp4r; if check_for_camlp4_support () then begin
set_phrase_terminator ";";
add_keyword "value";
try
Topfind.syntax "camlp4r"; Topfind.syntax "camlp4r";
Topfind.load_deeply ["utop.camlp4"] Topfind.load_deeply ["utop.camlp4"];
with exn -> set_syntax Camlp4r;
handle_findlib_error exn set_phrase_terminator ";";
end add_keyword "value"
end
let () = let () =
Hashtbl.add Hashtbl.add