def FindPreviousMatchingAngleBracket(clean_lines, linenum, init_prefix):
 line = init_prefix
 nesting_stack = ['>']
 while True:
  match = Search('^(.*)([<>(),;\\[\\]])[^<>(),;\\[\\]]*$', line)
  if match:
   operator = match.group(2)
   line = match.group(1)
   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 < 0):
    break
   line = clean_lines.elided[linenum]
 return False

def FindPreviousMatchingAngleBracket ( clean_lines , linenum , init_prefix ) : line = init_prefix nesting_stack = [ '>' ] while True : match = Search ( '^(.*)([<>(),;\\[\\]])[^<>(),;\\[\\]]*$' , line ) if match : operator = match . group ( 2 ) line = match . group ( 1 ) 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 < 0 ) : break line = clean_lines . elided [ linenum ] return False
find the corresponding < that started a template .