diff --git a/src/action.ml b/src/action.ml index c8b5f49b..8ab14e38 100644 --- a/src/action.ml +++ b/src/action.ml @@ -275,6 +275,10 @@ module Var_expansion = struct | Paths of Path.t list | Strings of string list + let length = function + | Paths x -> List.length x + | Strings x -> List.length x + let is_multivalued = function | Paths [_] -> false | Strings [_] -> false diff --git a/src/string_with_vars.ml b/src/string_with_vars.ml index 33df64ef..61a1f86c 100644 --- a/src/string_with_vars.ml +++ b/src/string_with_vars.ml @@ -106,6 +106,7 @@ let string_of_var syntax v = module type EXPANSION = sig type t + val length : t -> int val is_multivalued : t -> bool type context val to_string : context -> t -> string @@ -132,12 +133,12 @@ end module Expand_to(V: EXPANSION) = struct - let check_valid_multivalue syntax ~var t ctx = - if not t.quoted && V.is_multivalued ctx then - Loc.fail t.loc "Variable %s expands to multiple values, \ + let check_valid_multivalue syntax ~var t x = + if not t.quoted && V.is_multivalued x then + Loc.fail t.loc "Variable %s expands to %d values, \ however a single value is expected here. \ Please quote this atom. " - (string_of_var syntax var) + (string_of_var syntax var) (V.length x) let expand ctx t ~f = match t.items with @@ -189,6 +190,7 @@ end module String_expansion = struct type t = string + let length _ = 1 let is_multivalued _ = false type context = unit let to_string () (s: string) = s diff --git a/src/string_with_vars.mli b/src/string_with_vars.mli index 9dc3ab38..89e4fd95 100644 --- a/src/string_with_vars.mli +++ b/src/string_with_vars.mli @@ -49,6 +49,8 @@ module type EXPANSION = sig type t (** The value to which variables are expanded. *) + val length : t -> int + val is_multivalued : t -> bool (** Report whether the value is a multivalued one (such as for example ${@}) which much be in quoted strings to be concatenated