def walk_to_end(ch, input_iter):
 if (ch == '('):
  nesting = 1
 else:
  nesting = 0
 for (ch, escaped) in input_iter:
  if escaped:
   continue
  elif (ch == '('):
   nesting += 1
  elif (ch == ')'):
   if (not nesting):
    return
   nesting -= 1

def walk_to_end ( ch , input_iter ) : if ( ch == '(' ) : nesting = 1 else : nesting = 0 for ( ch , escaped ) in input_iter : if escaped : continue elif ( ch == '(' ) : nesting += 1 elif ( ch == ')' ) : if ( not nesting ) : return nesting -= 1
the iterator is currently inside a capturing group .