Some improvements to the query parser

The `collapse()` support works now, but is still sorta in flux: the name "collapse" isn't great, and it's not yet clear whether we want `collapse()` to close all open group-by chains, or have them act as balanced pairs.