A generalization of the Baker–Hausdorff lemma