Longitudinal structure formation in a nonlinear resonator