let build_tree annot_string =
let rec iter acc pos =
match
try Some (Str.search_forward location_re annot_string pos)
with Not_found -> None
with
None -> List.rev acc
| Some _ ->
let left = int_of_string (Str.matched_group 5 annot_string) in
let right = int_of_string (Str.matched_group 10 annot_string) in
let newp = Str.match_end () in
match
try Some (Str.search_forward type_annot_re annot_string newp)
with Not_found -> None
with
None -> List.rev acc
| Some _ ->
let start = Str.group_beginning 1 in
let stop = Str.group_end 1 in
let newp = Str.match_end () in
let new_acc = add_node acc ~left ~right ~start ~stop in
iter new_acc newp
in
match iter [] 0 with
[t] -> Some t
| [] -> None
| l ->
let t = {
t_pos_left = (List.hd l).t_pos_left ;
t_pos_right = (List.hd (List.rev l)).t_pos_right ;
t_type_info = None ;
t_children = l;
}
in
Some t