let add_node acc ~left ~right ~kind =
match acc with
[] ->
let t =
{ t_pos_left = left;
t_pos_right = right;
t_kind = Some kind ;
t_children = [] ;
}
in
[ t ]
| l ->
let rec find_children acc = function
[] -> (List.rev acc, [])
| h :: q ->
if h.t_pos_right < left then
(* no more children *)
(List.rev acc, h ::q)
else
find_children (h::acc) q
in
let (children, others) = find_children [] l in
let t =
{ t_pos_left = left ;
t_pos_right = right ;
t_kind = Some kind;
t_children = children ;
}
in
t :: others