Inline expand_var

Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
This commit is contained in:
Rudi Grinberg 2018-06-06 20:14:10 +07:00
parent 9cc8ff920a
commit c96df4dc15
1 changed files with 6 additions and 11 deletions

View File

@ -142,14 +142,6 @@ 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 syntax 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 partial_expand t ~mode ~dir ~f = let partial_expand t ~mode ~dir ~f =
let commit_text acc_text acc = let commit_text acc_text acc =
let s = concat_rev acc_text in let s = concat_rev acc_text in
@ -163,9 +155,12 @@ let partial_expand t ~mode ~dir ~f =
| _ -> Unexpanded { t with items = List.rev (commit_text acc_text acc) } | _ -> Unexpanded { t with items = List.rev (commit_text acc_text acc) }
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, var) as it :: items ->
begin match expand_var syntax ~var:v ~dir ~f t with begin match f syntax t.loc var with
| Some values -> loop (List.rev_append values acc_text) acc items | Some ([] | _::_::_ as e) when not t.quoted ->
invalid_multivalue syntax ~var 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