Categorical rewriting of term-like structures