a not-quite-working regex parser translated from scheme to ruby