def parse(str)
      fields = []
      nest = 0
      field = ''
      str.each_char do |ch|
        got = false
        if nest == 0
          if ch == '('
            nest += 1
          end
        else
          if ch == '('
            nest += 1
            field << ch
          elsif ch == ')'
            nest -= 1
            if nest == 0
              got = true
            else
              field << ch
            end
          else
            field << ch
          end
        end

        if got
          fields << field
          field = ''
        end
      end

      fields
    end
def parse(str)
      fields = []
      nest = 0
      field = ''
      str.each_char do |ch|
        got = false
        if nest == 0
          if ch == '('
            nest += 1
          end
        else
          if ch == '('
            nest += 1
            field << ch
          elsif ch == ')'
            nest -= 1
            if nest == 0
              got = true
            else
              field << ch
            end
          else
            field << ch
          end
        end

        if got
          fields << field
          field = ''
        end
      end

      fields
    end
Parse a string that consists of a sequence of values enclosed within parentheses.
 Ignore any bytes that are outside of parentheses. Values may include nested parentheses.

 @param [String] str e.g. "(foo) ((bar)) ... (baz)"
 @return [Array] e.g. ["foo", "bar", "baz"]