def call_of_leaf(leaf, cut_own_trailer=False):
 trailer = leaf.parent
 if ((trailer.type != 'trailer') or (leaf not in (trailer.children[0], trailer.children[(-1)]))):
  if (trailer.type == 'atom'):
   return trailer
  return leaf
 power = trailer.parent
 index = power.children.index(trailer)
 power = deep_ast_copy(power)
 if cut_own_trailer:
  cut = index
 else:
  cut = (index + 1)
 power.children[cut:] = []
 if (power.type == 'error_node'):
  start = index
  while True:
   start -= 1
   if (power.children[start].type != 'trailer'):
    break
  transformed = tree.Node('power', power.children[start:])
  transformed.parent = power.parent
  return transformed
 return power

def call_of_leaf ( leaf , cut_own_trailer = False ) : trailer = leaf . parent if ( ( trailer . type != 'trailer' ) or ( leaf not in ( trailer . children [ 0 ] , trailer . children [ ( - 1 ) ] ) ) ) : if ( trailer . type == 'atom' ) : return trailer return leaf power = trailer . parent index = power . children . index ( trailer ) power = deep_ast_copy ( power ) if cut_own_trailer : cut = index else : cut = ( index + 1 ) power . children [ cut : ] = [ ] if ( power . type == 'error_node' ) : start = index while True : start -= 1 if ( power . children [ start ] . type != 'trailer' ) : break transformed = tree . Node ( 'power' , power . children [ start : ] ) transformed . parent = power . parent return transformed return power
creates a "call" node that consist of all trailer and power objects .