Convert spec to internal tree structure before filtering