Basic functionality is almost there, however still plenty to make it production quality. In this changeset I regenerated setup.ml via. oasis 3 so it contains a huge diff.

Ignore-this: 357d4c82baa1ecdf5c49bf65459059e9

darcs-hash:20120321031530-33bd9-43e454ae62709103edfb0208e7ab95a5319ae93a
This commit is contained in:
wojciech.meyer 2012-03-21 04:15:30 +01:00
parent 4264dc3d92
commit 11cf629c46
6 changed files with 5751 additions and 5 deletions

9
_oasis
View File

@ -57,6 +57,15 @@ Library "utop-camlp4"
XMETAType: syntax
XMETADescription: Camlp4 integration
Library "utop-camlp5"
FindlibName: camlp5
FindlibParent: utop
Path: src/camlp5
Modules: UTop_camlp5
BuildDepends: utop
XMETAType: syntax
XMETADescription: Camlp5 integration
Executable utop
Install: true
Path: src/top

3
_tags
View File

@ -9,5 +9,8 @@
# Use compiler interfaces
<src/**/*.ml{,i}>: use_compiler_libs
# Use camlp5
<src/camlp5/**/*.ml{,i}>: use_camlp5
# OASIS_START
# OASIS_STOP

View File

@ -47,6 +47,11 @@ let () =
flag ["ocaml"; "ocamldep"; "use_compiler_libs"] & S paths;
flag ["ocaml"; "doc"; "use_compiler_libs"] & S paths;
let paths = [A "-I"; A "+camlp5"] in
flag ["ocaml"; "compile"; "use_camlp5"] & S paths;
flag ["ocaml"; "ocamldep"; "use_camlp5"] & S paths;
flag ["ocaml"; "doc"; "use_camlp5"] & S paths;
(* Expunge compiler modules *)
rule "toplevel expunge"
~dep:"%.top"

5650
setup.ml

File diff suppressed because it is too large Load Diff

66
src/camlp5/uTop_camlp5.ml Normal file
View File

@ -0,0 +1,66 @@
(*
* 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

@ -0,0 +1,23 @@
(*
* 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. *)