code: def transform_except_subquery(sql, func):
      
      start = 0
      out = []
      while sql.find('(SELECT', start) > -1:
          pos = sql.find('(SELECT', start)
          out.append(func(sql[start:pos]))
          start, pos = find_closing_parenthesis(sql, pos)
          out.append(sql[start:pos])
          start = pos
      out.append(func(sql[start:len(sql)]))
      return ''.join(out)
docs: Call a func on every part of SOQL query except nested (SELECT ...)