Removed camlp4/camlp5

This commit is contained in:
Jérémie Dimino 2017-03-15 23:56:36 +00:00 committed by Jeremie Dimino
parent ba3d278b32
commit eae41f42a6
5 changed files with 0 additions and 252 deletions

View File

@ -1,9 +0,0 @@
(jbuild_version 1)
(library
((name uTop_camlp4)
(public_name utop.camlp4)
(optional)
(modes (byte))
(libraries (utop camlp4.lib))
(preprocess (action (run ${bin:cppo} -V OCAML:${ocaml_version} ${<})))))

View File

@ -1,130 +0,0 @@
(*
* uTop_camlp4.ml
* --------------
* Copyright : (c) 2012, Jeremie Dimino <jeremie@dimino.org>
* Licence : BSD3
*
* This file is a part of utop.
*)
open Lexing
open Camlp4
open Camlp4.PreCast
module Ast2pt = Camlp4.Struct.Camlp4Ast2OCamlAst.Make(Ast)
#if OCAML_VERSION < (4, 02, 0)
external cast_toplevel_phrase : Camlp4_import.Parsetree.toplevel_phrase -> Parsetree.toplevel_phrase = "%identity"
#else
let cast_toplevel_phrase x = x
#endif
let print_camlp4_error pp exn =
Format.fprintf pp "@[<0>%a@]" Camlp4.ErrorHandler.print exn;
Format.pp_print_flush pp ()
let get_camlp4_error_message exn =
let loc, exn =
match exn with
| Loc.Exc_located (loc, exn) ->
((Loc.start_off loc, Loc.stop_off loc), exn)
| exn ->
((0, 0), exn)
in
let msg = UTop.get_message print_camlp4_error exn in
(* Camlp4 sometimes generate several empty lines at the end... *)
let idx = ref (String.length msg - 1) in
while !idx > 0 && msg.[!idx] = '\n' do
decr idx
done;
if !idx + 1 < String.length msg then
(loc, String.sub msg 0 (!idx + 1))
else
(loc, msg)
let convert_camlp4_toplevel_phrase ast =
try
UTop.Value (cast_toplevel_phrase (Ast2pt.phrase ast))
with exn ->
let loc, msg = get_camlp4_error_message exn in
UTop.Error ([loc], msg)
let parse_camlp4 syntax str eos_is_error =
(* Execute delayed actions now. *)
Register.iter_and_take_callbacks (fun (_, f) -> f ());
let eof = ref false in
try
let len = String.length str in
let char_stream =
Stream.from
(fun i ->
if i >= len then begin
eof := true;
None
end else
Some str.[i])
in
let token_stream = Gram.filter (Gram.lex (Loc.mk UTop.input_name) char_stream) in
UTop.Value (Gram.parse_tokens_after_filter syntax token_stream)
with exn ->
if !eof && not eos_is_error then
raise UTop.Need_more
else
let loc, msg = get_camlp4_error_message exn in
UTop.Error ([loc], msg)
let filter phrase =
try
UTop.Value (AstFilters.fold_topphrase_filters (fun t filter -> filter t) phrase)
with exn ->
let loc, msg = get_camlp4_error_message exn in
UTop.Error ([loc], msg)
;;
let parse_toplevel_phrase_camlp4 str eos_is_error =
match parse_camlp4 Syntax.top_phrase str eos_is_error with
| UTop.Value None ->
raise UTop.Need_more
| UTop.Value (Some ast) ->
filter ast
| UTop.Error (locs, msg) ->
UTop.Error (locs, msg)
let parse_toplevel_phrase str eos_is_error =
match parse_toplevel_phrase_camlp4 str eos_is_error with
| UTop.Value ast ->
convert_camlp4_toplevel_phrase ast
| UTop.Error (locs, msg) ->
UTop.Error (locs, msg)
let parse_use_file str eos_is_error =
match parse_camlp4 Syntax.use_file str eos_is_error with
| UTop.Value ([], _) ->
raise UTop.Need_more
| UTop.Value (asts, _) ->
let rec loop phrases = function
| [] -> UTop.Value (List.rev phrases)
| (ast::more_asts) ->
match filter ast with
| UTop.Error _ as e -> e
| UTop.Value ast ->
match convert_camlp4_toplevel_phrase ast with
| UTop.Error _ as e -> e
| UTop.Value y -> loop (y::phrases) more_asts
in loop [] asts
| UTop.Error (locs, msg) ->
UTop.Error (locs, msg)
let () =
UTop.parse_toplevel_phrase := parse_toplevel_phrase;
UTop.parse_use_file := parse_use_file;
(* So that camlp4 doesn't display its welcome message. *)
let interactive = !Sys.interactive in
Sys.interactive := false;
let () =
try
ignore (!Toploop.parse_toplevel_phrase (Lexing.from_string ""))
with _ ->
()
in
Sys.interactive := interactive

View File

@ -1,24 +0,0 @@
(*
* uTop_camlp4.mli
* ---------------
* Copyright : (c) 2012, Jeremie Dimino <jeremie@dimino.org>
* Licence : BSD3
*
* This file is a part of utop.
*)
val parse_toplevel_phrase : string -> bool -> Parsetree.toplevel_phrase UTop.result
(** Toplevel phrase parser for utop using camlp4. *)
val parse_toplevel_phrase_camlp4 : string -> bool -> Camlp4.PreCast.Ast.str_item UTop.result
(** Camlp4 toplevel phrase parser. Same as {!parse_toplevel_phrase}
but the result is not converted to an OCaml ast. *)
val convert_camlp4_toplevel_phrase : Camlp4.PreCast.Ast.str_item -> Parsetree.toplevel_phrase UTop.result
(** Converts a camlp4 toplevel phrase into a standard OCaml toplevel
phrase. Note that a camlp4 ast may not be convertible to an
OCaml one, in which case it returns {!UTop.Error}. *)
val get_camlp4_error_message : exn -> UTop.location * string
(** [get_camlp4_error_message exn] returns the location and error
message for the exception [exn] as printed by camlp4. *)

View File

@ -1,66 +0,0 @@
(*
* uTop_camlp5.ml
* --------------
* Copyright : (c) 2012, Wojciech Meyer <wojciech.meyer@gmail.org>
* Licence : BSD3
*
* This file is a part of utop.
*)
open Lexing
let print_camlp5_error pp exn =
let save = Format.get_formatter_output_functions () in
Format.set_formatter_output_functions
(fun str s e -> Format.pp_print_string pp (String.sub str s e))
(fun () -> Format.pp_print_flush pp ());
Format.printf "@[<0>%a@]@." (fun _ -> Pcaml.report_error) exn;
Format.set_formatter_output_functions (fst save) (snd save)
let get_camlp5_error_message exn =
let loc, exn =
match exn with
| Ploc.Exc (loc, exn) ->
((Ploc.first_pos loc, Ploc.last_pos loc), exn)
| exn ->
((0, 0), exn)
in
let msg = UTop.get_message print_camlp5_error exn in
loc, msg
let convert_camlp5_toplevel_phrase ast =
try
UTop.Value (Ast2pt.phrase ast)
with exn ->
let loc, msg = get_camlp5_error_message exn in
UTop.Error ([loc], msg)
let parse_toplevel_phrase_camlp5 str eos_is_error =
try
let token_stream = Stream.of_string str in
match Grammar.Entry.parse Pcaml.top_phrase token_stream with
| Some ast ->
UTop.Value ast
| None ->
raise UTop.Need_more
with exn ->
if not eos_is_error then
raise UTop.Need_more
else
let loc, msg = get_camlp5_error_message exn in
UTop.Error ([loc], msg)
let parse_toplevel_phrase str eos_is_error =
match parse_toplevel_phrase_camlp5 str eos_is_error with
| UTop.Value ast ->
convert_camlp5_toplevel_phrase ast
| UTop.Error (locs, msg) ->
UTop.Error (locs, msg)
let () =
UTop.parse_toplevel_phrase := parse_toplevel_phrase;
(* Force camlp5 to display its welcome message. *)
try
ignore (!Toploop.parse_toplevel_phrase (Lexing.from_string ""))
with _ ->
()

View File

@ -1,23 +0,0 @@
(*
* uTop_camlp5.mli
* ---------------
* Copyright : (c) 2012, Wojciech Meyer <wojciech.meyer@gmail.com>
* Licence : BSD3
*
* This file is a part of utop.
*)
val parse_toplevel_phrase : string -> bool -> Parsetree.toplevel_phrase UTop.result
(** Toplevel phrase parser for utop using camlp5. *)
val parse_toplevel_phrase_camlp5 : string -> bool -> MLast.str_item UTop.result
(** Camlp5 toplevel phrase parser. Same as {!parse_toplevel_phrase}
but the result is not converted to an OCaml ast. *)
val convert_camlp5_toplevel_phrase : MLast.str_item -> Parsetree.toplevel_phrase UTop.result
(** Converts a camlp5 toplevel phrase into a standard OCaml toplevel
phrase. Note that a camlp5 ast may not be convertible to an
OCaml one, in which case it returns {!UTop.Error}. *)
val get_camlp5_error_message : exn -> UTop.location * string
(** [get_camlp5_error_message exn] returns the location and error
message for the exception [exn] as printed by camlp5. *)