Move maybe_quoted to string module
This commit is contained in:
parent
9aa827ac35
commit
980f5037cc
|
@ -519,7 +519,7 @@ let add_spec t fn spec ~copy_source =
|
|||
As a result, the rule is currently ignored, however this will become an error \
|
||||
in the future.\n\
|
||||
%t"
|
||||
(maybe_quoted (Path.basename fn))
|
||||
(String.maybe_quoted (Path.basename fn))
|
||||
(fun ppf ->
|
||||
match rule.mode with
|
||||
| Not_a_rule_stanza ->
|
||||
|
|
|
@ -86,15 +86,6 @@ let hint name candidates =
|
|||
sprintf "\nHint: did you mean %s?" (mk_hint l)
|
||||
|
||||
|
||||
(* [maybe_quoted s] is [s] if [s] doesn't need escaping according to OCaml lexing
|
||||
conventions and [sprintf "%S" s] otherwise. *)
|
||||
let maybe_quoted s =
|
||||
let escaped = String.escaped s in
|
||||
if s == escaped || s = escaped then
|
||||
s
|
||||
else
|
||||
sprintf {|"%s"|} escaped
|
||||
|
||||
(* Disable file operations to force to use the IO module *)
|
||||
let open_in = `Use_Io
|
||||
let open_in_bin = `Use_Io
|
||||
|
|
|
@ -247,7 +247,7 @@ let to_string = function
|
|||
| t -> t
|
||||
|
||||
let to_string_maybe_quoted t =
|
||||
maybe_quoted (to_string t)
|
||||
String.maybe_quoted (to_string t)
|
||||
|
||||
let root = ""
|
||||
|
||||
|
|
|
@ -175,5 +175,13 @@ let exists s ~f =
|
|||
with Exit ->
|
||||
true
|
||||
|
||||
let maybe_quoted s =
|
||||
let escaped = escaped s in
|
||||
if s == escaped || s = escaped then
|
||||
s
|
||||
else
|
||||
Printf.sprintf {|"%s"|} escaped
|
||||
|
||||
|
||||
module Set = Set.Make(T)
|
||||
module Map = Map.Make(T)
|
||||
|
|
|
@ -40,5 +40,9 @@ val longest_map : 'a list -> f:('a -> string) -> int
|
|||
|
||||
val exists : t -> f:(char -> bool) -> bool
|
||||
|
||||
(** [maybe_quoted s] is [s] if [s] doesn't need escaping according to OCaml
|
||||
lexing conventions and [sprintf "%S" s] otherwise. *)
|
||||
val maybe_quoted : t -> t
|
||||
|
||||
module Set : Set.S with type elt = t
|
||||
module Map : Map.S with type key = t
|
||||
|
|
|
@ -117,7 +117,7 @@ let executable_object_directory ~dir name =
|
|||
|
||||
let program_not_found ?context ?hint prog =
|
||||
die "@{<error>Error@}: Program %s not found in the tree or in PATH%s%a"
|
||||
(maybe_quoted prog)
|
||||
(String.maybe_quoted prog)
|
||||
(match context with
|
||||
| None -> ""
|
||||
| Some name -> sprintf " (context: %s)" name)
|
||||
|
@ -127,7 +127,7 @@ let program_not_found ?context ?hint prog =
|
|||
hint
|
||||
|
||||
let library_not_found ?context ?hint lib =
|
||||
die "@{<error>Error@}: Library %s not found%s%a" (maybe_quoted lib)
|
||||
die "@{<error>Error@}: Library %s not found%s%a" (String.maybe_quoted lib)
|
||||
(match context with
|
||||
| None -> ""
|
||||
| Some name -> sprintf " (context: %s)" name)
|
||||
|
|
Loading…
Reference in New Issue