From 460f2d895a6bf60e9c3b8aaabad3b5fccd2a379a Mon Sep 17 00:00:00 2001 From: John Estabrook Date: Fri, 10 Apr 2026 15:08:07 -0500 Subject: T8488: add utility refpath_from_partial Infer the reference path from a path that may or may not contain intervening tag nodes. Return an empty list on a nonsensical path. --- src/reference_tree.ml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/reference_tree.ml') diff --git a/src/reference_tree.ml b/src/reference_tree.ml index 8ff7b54..dead1be 100644 --- a/src/reference_tree.ml +++ b/src/reference_tree.ml @@ -648,6 +648,33 @@ let refpath reftree path = | _, [] -> acc in aux [] path +(* Convert from partial config path to reference tree path. + 'Partial' here means that there may or may not be intervening tag node + values. + *) +let refpath_from_partial reftree path = + let check_existence p = + match p with + | [] -> false + | _ -> (Vytree.exists[@alert "-exn"]) reftree p + in + let rec aux acc p = + match acc, p with + | [], h :: tl -> + if check_existence [h] then aux [h] tl else [] + | _, [h] -> + let p = acc @ [h] in + if check_existence p then p else + if is_tag reftree acc then acc else [] + | _, h :: h' :: tl -> + let p = acc @ [h] in + if check_existence p then aux p ([h'] @ tl) else + let p = acc @ [h'] in + if is_tag reftree acc && check_existence p then aux p tl + else [] + | _, [] -> acc + in aux [] path + let set_tag_data rtree ctree path = (* raises: [Vytree.Empty_path], -- cgit v1.2.3