High-resolution one- and two-photon spectroscopy of matrix-isolated molecules. I. Construction and performance of the spectrometer