···3232let add_keyword kwd = keywords := String_set.add kwd !keywords
33333434(* +-----------------------------------------------------------------+
3535+ | Span of Lines |
3636+ +-----------------------------------------------------------------+ *)
3737+3838+type lines = {
3939+ start: int;
4040+ stop: int;
4141+}
4242+4343+(* +-----------------------------------------------------------------+
3544 | Error reporting |
3645 +-----------------------------------------------------------------+ *)
3746···5261 Scanf.sscanf
5362 str
5463 "Characters %d-%d:\n%[\000-\255]"
5555- (fun start stop msg -> ((start, stop), msg))
5656- with _ ->
5757- ((0, 0), str)
6464+ (fun start stop msg -> ((start, stop), msg, None))
6565+ with Scanf.Scan_failure(_) ->
6666+ try
6767+ Scanf.sscanf
6868+ str
6969+ "Line %d, characters %d-%d:\n%[\000-\255]"
7070+ (fun line start stop msg -> ((start, stop), msg, Some{start=line; stop=line}))
7171+ with Scanf.Scan_failure(_) ->
7272+ try
7373+ Scanf.sscanf
7474+ str
7575+ "Lines %d-%d, characters %d-%d:\n%[\000-\255]"
7676+ (fun start_line stop_line start stop msg -> ((start, stop),
7777+ msg, Some{start=start_line;stop=stop_line}))
7878+ with Scanf.Scan_failure(_) ->
7979+ ((0, 0), str, None)
58805981let collect_formatters buf pps f =
6082 (* First flush all formatters. *)
···167189 (* If the string is empty, do not report an error. *)
168190 raise Need_more
169191 | Lexer.Error (error, loc) ->
170170-#if OCAML_VERSION >= (4, 08, 0)
171192 (match Location.error_of_exn (Lexer.Error (error, loc)) with
172193 | Some (`Ok error)->
173194 Error ([mkloc loc], get_message Location.print_report error)
174195 | _-> raise Need_more)
175175-#else
176176- Error ([mkloc loc], get_message Lexer.report_error error)
177177-#endif
178196 | Syntaxerr.Error error -> begin
179197 match error with
180198 | Syntaxerr.Unclosed (opening_loc, opening, closing_loc, closing) ->
···198216 | Syntaxerr.Ill_formed_ast (loc, s) ->
199217 Error ([mkloc loc],
200218 Printf.sprintf "Error: broken invariant in parsetree: %s" s)
201201-#if OCAML_VERSION >= (4, 03, 0)
202219 | Syntaxerr.Invalid_package_type (loc, s) ->
203220 Error ([mkloc loc],
204221 Printf.sprintf "Invalid package type: %s" s)
222222+#if OCAML_VERSION >= (5, 0, 0)
223223+ | Syntaxerr.Removed_string_set loc ->
224224+ Error ([mkloc loc],
225225+ "Syntax error: strings are immutable, there is no assignment \
226226+ syntax for them.\n\
227227+ Hint: Mutable sequences of bytes are available in the Bytes module.\n\
228228+ Hint: Did you mean to use 'Bytes.set'?")
205229#endif
206230 end
207231 | Syntaxerr.Escape_error | Parsing.Parse_error ->
···231255 Location.loc = loc;
232256}
233257234234-#if OCAML_VERSION >= (4, 03, 0)
235235-let nolabel = Asttypes.Nolabel
236236-#else
237237-let nolabel = ""
238238-#endif
239239-240258(* Check that the given phrase can be evaluated without typing/compile
241259 errors. *)
242260let check_phrase phrase =
···263281 with_default_loc loc
264282 (fun () ->
265283 Str.eval
266266- (Exp.fun_ nolabel None (Pat.construct unit None)
284284+ (Exp.fun_ Nolabel None (Pat.construct unit None)
267285 (Exp.letmodule (with_loc loc
268286 #if OCAML_VERSION >= (4, 10, 0)
269287 (Some "_")
···287305 None
288306 with exn ->
289307 (* The phrase contains errors. *)
290290- let loc, msg = get_ocaml_error_message exn in
308308+ let loc, msg, line = get_ocaml_error_message exn in
291309 Toploop.toplevel_env := env;
292310 Btype.backtrack snap;
293293- Some ([loc], msg)
311311+ Some ([loc], msg, [line])
294312295313296314···329347 | Compiler-libs re-exports |
330348 +-----------------------------------------------------------------+ *)
331349332332-#if OCAML_VERSION >= (4, 08, 0)
333333-let get_load_path ()= Load_path.get_paths ()
334334-let set_load_path path= Load_path.init path
335335-#else
336336-let get_load_path ()= !Config.load_path
337337-let set_load_path path= Config.load_path := path
338338-#endif
350350+let get_load_path () = Load_path.get_paths ()
339351352352+#if OCAML_VERSION >= (5, 0, 0)
353353+let set_load_path path =
354354+ Load_path.init path ~auto_include:Load_path.no_auto_include
355355+#else
356356+let set_load_path path = Load_path.init path
357357+#endif
+20-12
lib/uTop.mli
···1818val add_keyword : string -> unit
1919(** Add a new OCaml keyword. *)
20202121+(** {6 Parsing} *)
2222+2123type location = int * int
2222-(** Type of a string-location. It is composed of a start and stop offsets (in
2323- bytes). *)
2424+ (** Type of a string-location. It is composed of a start and stop
2525+ offsets (in bytes). *)
2626+2727+type lines = {
2828+ start: int;
2929+ stop: int;
3030+}
3131+ (** Type for a range of lines in a buffer from start to stop. *)
24322533(** Result of a function processing a programx. *)
2634type 'a result =
···7280(** [get_message printer x] applies [printer] on [x] and returns everything it
7381 prints as a string. *)
74827575-val get_ocaml_error_message : exn -> location * string
7676-(** [get_ocaml_error_message exn] returns the location and error message for the
7777- exception [exn] which must be an exception from the compiler. *)
7878-7979-val check_phrase : Parsetree.toplevel_phrase -> (location list * string) option
8080-(** [check_phrase phrase] checks that [phrase] can be executed without typing or
8181- compilation errors. It returns [None] if [phrase] is OK and an error message
8282- otherwise.
8383+val get_ocaml_error_message : exn -> location * string * (lines option)
8484+ (** [get_ocaml_error_message exn] returns the location and error
8585+ message for the exception [exn] which must be an exception from
8686+ the compiler. *)
83878484- If the result is [None] it is guaranteed that [Toploop.execute_phrase] won't
8585- raise any exception. *)
8888+val check_phrase : Parsetree.toplevel_phrase -> (location list * string * lines option list) option
8989+ (** [check_phrase phrase] checks that [phrase] can be executed
9090+ without typing or compilation errors. It returns [None] if
9191+ [phrase] is OK and an error message otherwise.
9292+ If the result is [None] it is guaranteed that
9393+ [Toploop.execute_phrase] won't raise any exception. *)
86948795val collect_formatters : Buffer.t -> Format.formatter list -> (unit -> 'a) -> 'a
8896(** [collect_formatters buf pps f] executes [f] and redirect everything it