Share quote handling in partial and normal expansion
The partial expansion had a bug in its condition for a 1 element value list. This fixes the bug by implementing the condition once and for all. Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
This commit is contained in:
parent
589943df60
commit
ff173b98d8
|
@ -142,6 +142,14 @@ let invalid_multivalue syntax ~var t x =
|
||||||
Please quote this atom."
|
Please quote this atom."
|
||||||
(string_of_var syntax var) (List.length x)
|
(string_of_var syntax var) (List.length x)
|
||||||
|
|
||||||
|
let expand_var syntax ~var ~dir ~f t =
|
||||||
|
match f t.loc var, t.quoted with
|
||||||
|
| Some ([] | _::_::_ as e) , false ->
|
||||||
|
invalid_multivalue syntax ~var t e
|
||||||
|
| Some ([_] as t), false
|
||||||
|
| Some t, true -> Some (Value.to_strings ~dir t)
|
||||||
|
| None, _ -> None
|
||||||
|
|
||||||
let expand t ~mode ~dir ~f =
|
let expand t ~mode ~dir ~f =
|
||||||
match t.items with
|
match t.items with
|
||||||
| [Var (syntax, v)] when not t.quoted ->
|
| [Var (syntax, v)] when not t.quoted ->
|
||||||
|
@ -159,12 +167,9 @@ let expand t ~mode ~dir ~f =
|
||||||
List.concat_map t.items ~f:(function
|
List.concat_map t.items ~f:(function
|
||||||
| Text s -> [s]
|
| Text s -> [s]
|
||||||
| Var (syntax, v) ->
|
| Var (syntax, v) ->
|
||||||
begin match f t.loc v, t.quoted with
|
begin match expand_var syntax ~var:v ~dir ~f t with
|
||||||
| Some ([] | _::_::_ as e) , false ->
|
| Some values -> values
|
||||||
invalid_multivalue syntax ~var:v t e
|
| None -> [string_of_var syntax v]
|
||||||
| Some ([_] as t), false
|
|
||||||
| Some t, true -> Value.to_strings ~dir t
|
|
||||||
| None, _ -> [string_of_var syntax v]
|
|
||||||
end)
|
end)
|
||||||
|> String.concat ~sep:"")
|
|> String.concat ~sep:"")
|
||||||
|
|
||||||
|
@ -182,11 +187,8 @@ let partial_expand t ~mode ~dir ~f =
|
||||||
end
|
end
|
||||||
| Text s :: items -> loop (s :: acc_text) acc items
|
| Text s :: items -> loop (s :: acc_text) acc items
|
||||||
| Var (syntax, v) as it :: items ->
|
| Var (syntax, v) as it :: items ->
|
||||||
begin match f t.loc v with
|
begin match expand_var syntax ~var:v ~dir ~f t with
|
||||||
| Some (([] | _::_) as e) when not t.quoted ->
|
| Some values -> loop (List.rev_append values acc_text) acc items
|
||||||
invalid_multivalue syntax ~var:v t e
|
|
||||||
| Some t ->
|
|
||||||
loop (List.rev_append (Value.to_strings ~dir t) acc_text) acc items
|
|
||||||
| None -> loop [] (it :: commit_text acc_text acc) items
|
| None -> loop [] (it :: commit_text acc_text acc) items
|
||||||
end
|
end
|
||||||
in
|
in
|
||||||
|
|
Loading…
Reference in New Issue