Inspired by https://orteil.dashnet.org/nested.