Analytic few-photon scattering in waveguide QED