def FindNextMatchingAngleBracket(clean_lines, linenum, init_suffix):
 line = init_suffix
 nesting_stack = ['<']
 while True:
  match = Search('^[^<>(),;\\[\\]]*([<>(),;\\[\\]])(.*)$', line)
  if match:
   operator = match.group(1)
   line = match.group(2)
   if (nesting_stack[(-1)] == '<'):
    if (operator in ('<', '(', '[')):
     nesting_stack.append(operator)
    elif (operator == '>'):
     nesting_stack.pop()
     if (not nesting_stack):
      return True
    elif (operator == ','):
     return True
    else:
     return False
   elif (operator in ('<', '(', '[')):
    nesting_stack.append(operator)
   elif (operator in (')', ']')):
    nesting_stack.pop()
  else:
   linenum += 1
   if (linenum >= len(clean_lines.elided)):
    break
   line = clean_lines.elided[linenum]
 return True

def FindNextMatchingAngleBracket ( clean_lines , linenum , init_suffix ) : line = init_suffix nesting_stack = [ '<' ] while True : match = Search ( '^[^<>(),;\\[\\]]*([<>(),;\\[\\]])(.*)$' , line ) if match : operator = match . group ( 1 ) line = match . group ( 2 ) if ( nesting_stack [ ( - 1 ) ] == '<' ) : if ( operator in ( '<' , '(' , '[' ) ) : nesting_stack . append ( operator ) elif ( operator == '>' ) : nesting_stack . pop ( ) if ( not nesting_stack ) : return True elif ( operator == ',' ) : return True else : return False elif ( operator in ( '<' , '(' , '[' ) ) : nesting_stack . append ( operator ) elif ( operator in ( ')' , ']' ) ) : nesting_stack . pop ( ) else : linenum += 1 if ( linenum >= len ( clean_lines . elided ) ) : break line = clean_lines . elided [ linenum ] return True
find the corresponding > to close a template .