Rigorous theory of grating-assisted couplers