def FindEndOfExpressionInLine(line, startpos, depth, startchar, endchar):
 for i in xrange(startpos, len(line)):
  if (line[i] == startchar):
   depth += 1
  elif (line[i] == endchar):
   depth -= 1
   if (depth == 0):
    return ((i + 1), 0)
 return ((-1), depth)

def FindEndOfExpressionInLine ( line , startpos , depth , startchar , endchar ) : for i in xrange ( startpos , len ( line ) ) : if ( line [ i ] == startchar ) : depth += 1 elif ( line [ i ] == endchar ) : depth -= 1 if ( depth == 0 ) : return ( ( i + 1 ) , 0 ) return ( ( - 1 ) , depth )
find the position just after the matching endchar .