add tree pattern docs and implementation