Пример #1
0
 def parenthesize_test(self, node_to_split):
     first_child = node_to_split.children[0]
     if first_child != LParen():
         # node_to_split.children[0] is the "print" literal strip the
         # current 1st child, since we will be prepending an LParen
         if first_child.prefix != first_child.prefix.strip():
             first_child.prefix = first_child.prefix.strip()
             first_child.changed()
         left_paren = LParen()
         left_paren.prefix = " "
         node_to_split.insert_child(0, left_paren)
         node_to_split.append_child(RParen())
         node_to_split.changed()
Пример #2
0
 def parenthesize_test(self, node_to_split):
     first_child = node_to_split.children[0]
     if first_child != LParen():
         # node_to_split.children[0] is the "print" literal strip the
         # current 1st child, since we will be prepending an LParen
         if first_child.prefix != first_child.prefix.strip():
             first_child.prefix = first_child.prefix.strip()
             first_child.changed()
         left_paren = LParen()
         left_paren.prefix = " "
         node_to_split.insert_child(0, left_paren)
         node_to_split.append_child(RParen())
         node_to_split.changed()
Пример #3
0
 def parenthesize_after_arg(self, node_to_split, value):
     # parenthesize the leaves after the first node with the value
     value_index = 0
     for index, child in enumerate(node_to_split.children):
         if child.value == value:
             value_index = index + 1
             break
     value_child = node_to_split.children[value_index]
     if value_child != LParen():
         # strip the current 1st child, since we will be prepending an
         # LParen
         if value_child.prefix != value_child.prefix.strip():
             value_child.prefix = value_child.prefix.strip()
             value_child.changed()
         # We set a space prefix since this is after the '='
         left_paren = LParen()
         left_paren.prefix = " "
         node_to_split.insert_child(value_index, left_paren)
         node_to_split.append_child(RParen())
         node_to_split.changed()
Пример #4
0
 def parenthesize_after_arg(self, node_to_split, value):
     # parenthesize the leaves after the first node with the value
     value_index = 0
     for index, child in enumerate(node_to_split.children):
         if child.value == value:
             value_index = index + 1
             break
     value_child = node_to_split.children[value_index]
     if value_child != LParen():
         # strip the current 1st child, since we will be prepending an
         # LParen
         if value_child.prefix != value_child.prefix.strip():
             value_child.prefix = value_child.prefix.strip()
             value_child.changed()
         # We set a space prefix since this is after the '='
         left_paren = LParen()
         left_paren.prefix = " "
         node_to_split.insert_child(value_index, left_paren)
         node_to_split.append_child(RParen())
         node_to_split.changed()