A tokenizer, not a search-and-replace
Before a single space moves, the query is split into tokens: strings, quoted identifiers, line and block comments, dollar-quoted bodies, numbers and operators. That is why a comma inside a string literal is never treated as a list separator, and why a comment cannot be orphaned from the line it explains.