def tgrep_positions(pattern, trees, search_leaves=True):
 if isinstance(pattern, (binary_type, text_type)):
  pattern = tgrep_compile(pattern)
 for tree in trees:
  try:
   if search_leaves:
    positions = tree.treepositions()
   else:
    positions = treepositions_no_leaves(tree)
   (yield [position for position in positions if pattern(tree[position])])
  except AttributeError:
   (yield [])

def tgrep_positions ( pattern , trees , search_leaves = True ) : if isinstance ( pattern , ( binary_type , text_type ) ) : pattern = tgrep_compile ( pattern ) for tree in trees : try : if search_leaves : positions = tree . treepositions ( ) else : positions = treepositions_no_leaves ( tree ) ( yield [ position for position in positions if pattern ( tree [ position ] ) ] ) except AttributeError : ( yield [ ] )
return the tree positions in the trees which match the given pattern .