def field_names(opt_fields)
      fields = []
      token_stack = []
      last_token = false
      tokens = opt_fields.split /(\(|,|\))/
      tokens << nil
      tokens.each do |t|
        if t.nil? then
          fields << (token_stack + [last_token]).join('.') if last_token
        elsif t.empty? then
          next
        elsif t == ',' then
          fields << (token_stack + [last_token]).join('.') if last_token
        elsif t == '(' then
          token_stack.push(last_token)
        elsif t == ')' then
          fields << (token_stack + [last_token]).join('.') if last_token
          token_stack.pop
          last_token = false
        else
          last_token = t
        end
      end
      fields
    end
def field_names(opt_fields)
      fields = []
      token_stack = []
      last_token = false
      tokens = opt_fields.split /(\(|,|\))/
      tokens << nil
      tokens.each do |t|
        if t.nil? then
          fields << (token_stack + [last_token]).join('.') if last_token
        elsif t.empty? then
          next
        elsif t == ',' then
          fields << (token_stack + [last_token]).join('.') if last_token
        elsif t == '(' then
          token_stack.push(last_token)
        elsif t == ')' then
          fields << (token_stack + [last_token]).join('.') if last_token
          token_stack.pop
          last_token = false
        else
          last_token = t
        end
      end
      fields
    end
This method accepts a string containing a list of fields. The fields can be nested
 in a format like...

 'a,b,c(d,e(f,g)),h'

 representing a structure like

 {
   a: "val",
   b: "val",
   c: {
     d: "val",
     e: {
       f: "val",
       g: "val"
     }
   },
   h: "val"
 }

 That string will get parsed and yield an array like
 [ a, b, c.d, c.e.f, c.e.g, h ]