Generalized where clause parser

This is the same branch as #20002 but with the pretty-printing test fixed.