Skip to content

Commit 8a02c23

Browse files
authored
indexing: use String.remove_prefix (#1455)
- error.ml: fix comment - Indexing.parse_file: test prefix "file://" instead of "file:///", and use Lplib.String.remove_prefix - Library.path_of_file error message: put filename between double quotes
1 parent 33c092a commit 8a02c23

3 files changed

Lines changed: 6 additions & 12 deletions

File tree

src/common/error.ml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ let no_wrn : ('a -> 'b) -> 'a -> 'b = fun f x ->
4040
description of the error, displayed differently from the error itself. *)
4141
exception Fatal of Pos.popt option * string * string
4242

43-
(** [fatal_str fmt] may be called an arbitrary number of times to build up the
43+
(** [fatal_msg fmt] may be called an arbitrary number of times to build up the
4444
error message of the [fatal] or [fatal_no_pos] functions prior to calling
4545
them. Note that the messages are stored in a buffer that is flushed by the
4646
[fatal] or [fatal_no_pos] function. Hence, they must be called. *)
@@ -50,8 +50,7 @@ let fatal_msg : 'a outfmt -> 'a =
5050
(** [fatal popt fmt] raises the [Fatal(popt,msg,err_desc)] exception, in which
5151
[msg] is built from the format [fmt] (provided the necessary arguments).
5252
[err_desc] continues the error message and is printed in normal format
53-
instead of red color*)
54-
53+
instead of red color. *)
5554
let fatal : Pos.popt -> ?err_desc:string -> ('a,'b) koutfmt -> 'a =
5655
fun pos ?(err_desc="") fmt ->
5756
let err_desc _ =
@@ -89,4 +88,4 @@ let handle_exceptions : (unit -> unit) -> unit = fun f ->
8988
| e ->
9089
exit_with "" "Uncaught [%s].\n%s"
9190
(Printexc.to_string e)
92-
(Printexc.get_backtrace())
91+
(Printexc.get_backtrace())

src/common/library.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ let path_of_file : (string -> string) -> string -> Path.t =
220220
match !mapping with
221221
| Some(mp, fp) -> (mp, fp)
222222
| None ->
223-
fatal_msg "%s cannot be mapped under the library root.@." fname;
223+
fatal_msg "\"%s\" cannot be mapped under the library root.@." fname;
224224
fatal_msg "Consider adding a package file under your source tree, ";
225225
fatal_no_pos "or use the [--map-dir] option."
226226
in

src/tool/indexing.ml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ module DB = struct
450450
(* given a filename/URI it returns the stream of lines
451451
and a function to close the resources *)
452452
let parse_file fname =
453-
if String.starts_with ~prefix:"file:///" fname then
453+
if String.starts_with ~prefix:"file://" fname then
454454
(assert (fst Stdlib.(!lsp_input) = fname) ;
455455
let text = snd Stdlib.(!lsp_input) in
456456
let lines = ref (String.split_on_char '\n' text) in
@@ -742,12 +742,7 @@ let index_rule sym ({Core.Term.lhs=lhsargs ; rule_pos ; _} as rule) =
742742
let rhs = rule.rhs in
743743
let get_relation = function | DB.Conclusion r -> r | _ -> assert false in
744744
let filename = Option.get rule_pos.fname in
745-
let filename =
746-
if String.starts_with ~prefix:"file:///" filename then
747-
let n = String.length "file://" in
748-
String.sub filename n (String.length filename - n)
749-
else
750-
filename in
745+
let filename = Lplib.String.remove_prefix "file://" filename in
751746
let path = Library.path_of_file Parsing.LpLexer.escape filename in
752747
let rule_name = (path,Common.Pos.to_string ~print_fname:false rule_pos) in
753748
index_term_and_subterms ~is_spine:false lhs

0 commit comments

Comments
 (0)