this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Bring compatibility with OCaml 5

authored by

Thibaut Mattio and committed by
Jon Ludlam
76476476 0e9a2256

+62 -37
-1
js_top_worker.opam
··· 14 14 "js_of_ocaml-toplevel" 15 15 "js_of_ocaml-compiler" 16 16 "js_of_ocaml-ppx" 17 - "js_top_worker-rpc" {= version} 18 17 ] 19 18 build : [ 20 19 ["dune" "subst"] {pinned}
+42 -24
lib/uTop.ml
··· 32 32 let add_keyword kwd = keywords := String_set.add kwd !keywords 33 33 34 34 (* +-----------------------------------------------------------------+ 35 + | Span of Lines | 36 + +-----------------------------------------------------------------+ *) 37 + 38 + type lines = { 39 + start: int; 40 + stop: int; 41 + } 42 + 43 + (* +-----------------------------------------------------------------+ 35 44 | Error reporting | 36 45 +-----------------------------------------------------------------+ *) 37 46 ··· 52 61 Scanf.sscanf 53 62 str 54 63 "Characters %d-%d:\n%[\000-\255]" 55 - (fun start stop msg -> ((start, stop), msg)) 56 - with _ -> 57 - ((0, 0), str) 64 + (fun start stop msg -> ((start, stop), msg, None)) 65 + with Scanf.Scan_failure(_) -> 66 + try 67 + Scanf.sscanf 68 + str 69 + "Line %d, characters %d-%d:\n%[\000-\255]" 70 + (fun line start stop msg -> ((start, stop), msg, Some{start=line; stop=line})) 71 + with Scanf.Scan_failure(_) -> 72 + try 73 + Scanf.sscanf 74 + str 75 + "Lines %d-%d, characters %d-%d:\n%[\000-\255]" 76 + (fun start_line stop_line start stop msg -> ((start, stop), 77 + msg, Some{start=start_line;stop=stop_line})) 78 + with Scanf.Scan_failure(_) -> 79 + ((0, 0), str, None) 58 80 59 81 let collect_formatters buf pps f = 60 82 (* First flush all formatters. *) ··· 167 189 (* If the string is empty, do not report an error. *) 168 190 raise Need_more 169 191 | Lexer.Error (error, loc) -> 170 - #if OCAML_VERSION >= (4, 08, 0) 171 192 (match Location.error_of_exn (Lexer.Error (error, loc)) with 172 193 | Some (`Ok error)-> 173 194 Error ([mkloc loc], get_message Location.print_report error) 174 195 | _-> raise Need_more) 175 - #else 176 - Error ([mkloc loc], get_message Lexer.report_error error) 177 - #endif 178 196 | Syntaxerr.Error error -> begin 179 197 match error with 180 198 | Syntaxerr.Unclosed (opening_loc, opening, closing_loc, closing) -> ··· 198 216 | Syntaxerr.Ill_formed_ast (loc, s) -> 199 217 Error ([mkloc loc], 200 218 Printf.sprintf "Error: broken invariant in parsetree: %s" s) 201 - #if OCAML_VERSION >= (4, 03, 0) 202 219 | Syntaxerr.Invalid_package_type (loc, s) -> 203 220 Error ([mkloc loc], 204 221 Printf.sprintf "Invalid package type: %s" s) 222 + #if OCAML_VERSION >= (5, 0, 0) 223 + | Syntaxerr.Removed_string_set loc -> 224 + Error ([mkloc loc], 225 + "Syntax error: strings are immutable, there is no assignment \ 226 + syntax for them.\n\ 227 + Hint: Mutable sequences of bytes are available in the Bytes module.\n\ 228 + Hint: Did you mean to use 'Bytes.set'?") 205 229 #endif 206 230 end 207 231 | Syntaxerr.Escape_error | Parsing.Parse_error -> ··· 231 255 Location.loc = loc; 232 256 } 233 257 234 - #if OCAML_VERSION >= (4, 03, 0) 235 - let nolabel = Asttypes.Nolabel 236 - #else 237 - let nolabel = "" 238 - #endif 239 - 240 258 (* Check that the given phrase can be evaluated without typing/compile 241 259 errors. *) 242 260 let check_phrase phrase = ··· 263 281 with_default_loc loc 264 282 (fun () -> 265 283 Str.eval 266 - (Exp.fun_ nolabel None (Pat.construct unit None) 284 + (Exp.fun_ Nolabel None (Pat.construct unit None) 267 285 (Exp.letmodule (with_loc loc 268 286 #if OCAML_VERSION >= (4, 10, 0) 269 287 (Some "_") ··· 287 305 None 288 306 with exn -> 289 307 (* The phrase contains errors. *) 290 - let loc, msg = get_ocaml_error_message exn in 308 + let loc, msg, line = get_ocaml_error_message exn in 291 309 Toploop.toplevel_env := env; 292 310 Btype.backtrack snap; 293 - Some ([loc], msg) 311 + Some ([loc], msg, [line]) 294 312 295 313 296 314 ··· 329 347 | Compiler-libs re-exports | 330 348 +-----------------------------------------------------------------+ *) 331 349 332 - #if OCAML_VERSION >= (4, 08, 0) 333 - let get_load_path ()= Load_path.get_paths () 334 - let set_load_path path= Load_path.init path 335 - #else 336 - let get_load_path ()= !Config.load_path 337 - let set_load_path path= Config.load_path := path 338 - #endif 350 + let get_load_path () = Load_path.get_paths () 339 351 352 + #if OCAML_VERSION >= (5, 0, 0) 353 + let set_load_path path = 354 + Load_path.init path ~auto_include:Load_path.no_auto_include 355 + #else 356 + let set_load_path path = Load_path.init path 357 + #endif
+20 -12
lib/uTop.mli
··· 18 18 val add_keyword : string -> unit 19 19 (** Add a new OCaml keyword. *) 20 20 21 + (** {6 Parsing} *) 22 + 21 23 type location = int * int 22 - (** Type of a string-location. It is composed of a start and stop offsets (in 23 - bytes). *) 24 + (** Type of a string-location. It is composed of a start and stop 25 + offsets (in bytes). *) 26 + 27 + type lines = { 28 + start: int; 29 + stop: int; 30 + } 31 + (** Type for a range of lines in a buffer from start to stop. *) 24 32 25 33 (** Result of a function processing a programx. *) 26 34 type 'a result = ··· 72 80 (** [get_message printer x] applies [printer] on [x] and returns everything it 73 81 prints as a string. *) 74 82 75 - val get_ocaml_error_message : exn -> location * string 76 - (** [get_ocaml_error_message exn] returns the location and error message for the 77 - exception [exn] which must be an exception from the compiler. *) 78 - 79 - val check_phrase : Parsetree.toplevel_phrase -> (location list * string) option 80 - (** [check_phrase phrase] checks that [phrase] can be executed without typing or 81 - compilation errors. It returns [None] if [phrase] is OK and an error message 82 - otherwise. 83 + val get_ocaml_error_message : exn -> location * string * (lines option) 84 + (** [get_ocaml_error_message exn] returns the location and error 85 + message for the exception [exn] which must be an exception from 86 + the compiler. *) 83 87 84 - If the result is [None] it is guaranteed that [Toploop.execute_phrase] won't 85 - raise any exception. *) 88 + val check_phrase : Parsetree.toplevel_phrase -> (location list * string * lines option list) option 89 + (** [check_phrase phrase] checks that [phrase] can be executed 90 + without typing or compilation errors. It returns [None] if 91 + [phrase] is OK and an error message otherwise. 92 + If the result is [None] it is guaranteed that 93 + [Toploop.execute_phrase] won't raise any exception. *) 86 94 87 95 val collect_formatters : Buffer.t -> Format.formatter list -> (unit -> 'a) -> 'a 88 96 (** [collect_formatters buf pps f] executes [f] and redirect everything it