let build_tree annot_string =
  let locs = cut_by_locations annot_string in
  let rec iter trees = function
    [] -> trees
  | [(_,stop,left,right)] ->
      get_annots annot_string trees ~left ~right stop None
  | (_,pos_start,left,right)::(((pos_end,_,_,_) :: _) as q) ->
      let t = get_annots annot_string
        trees ~left ~right pos_start (Some pos_end)
      in
      iter t q
  in
  
  (** the list of trees is supposed to be sorted, left-most first, and inner first because the list of annotation is ordered that way in the .annot file *)

  match iter [] locs 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_kind = None ;
          t_children = l;
        }
      in
      Some t