def _get_next_struct_field(fields_string):
  fieldname, rest = fields_string.split(':', 1)
  balanced = 0
  for pos, char in enumerate(rest):
    balanced += {'<': 1, '>': -1, '(': 1, ')': -1}.get(char, 0)
    if balanced == 0 and char in ['>', ',']:
      return (fieldname, rest[:pos+1].strip(',')), rest[pos+1:]
  return (fieldname, rest), None
dataset/ETHPy150Open cloudera/hue/apps/metastore/src/metastore/parser.py/_get_next_struct_field/original