Example #1
0
 def Visit_dotted_name(self, node):  # pylint: disable=invalid-name
     # dotted_name ::= NAME ('.' NAME)*
     for child in node.children:
         self.Visit(child)
     start = 2 if hasattr(node.children[0], 'is_pseudo') else 1
     for i in py3compat.range(start, len(node.children)):
         _SetUnbreakable(node.children[i])
Example #2
0
 def _SetUnbreakableOnChildren(self, node):
     """Set an UNBREAKABLE penalty annotation on children of node."""
     for child in node.children:
         self.Visit(child)
     start = 2 if hasattr(node.children[0], 'is_pseudo') else 1
     for i in py3compat.range(start, len(node.children)):
         self._SetUnbreakable(node.children[i])
Example #3
0
 def _SetUnbreakableOnChildren(self, node):
   """Set an UNBREAKABLE penalty annotation on children of node."""
   for child in node.children:
     self.Visit(child)
   start = 2 if hasattr(node.children[0], 'is_pseudo') else 1
   for i in py3compat.range(start, len(node.children)):
     self._SetUnbreakable(node.children[i])
Example #4
0
def _SetExpressionOperandPenalty(node, ops):
  for index in py3compat.range(1, len(node.children) - 1):
    child = node.children[index]
    if pytree_utils.NodeName(child) in ops:
      if style.Get('SPLIT_BEFORE_ARITHMETIC_OPERATOR'):
        _SetSplitPenalty(child, style.Get('SPLIT_PENALTY_ARITHMETIC_OPERATOR'))
      else:
        _SetSplitPenalty(
            pytree_utils.FirstLeafNode(node.children[index + 1]),
            style.Get('SPLIT_PENALTY_ARITHMETIC_OPERATOR'))
Example #5
0
def _SetBitwiseOperandPenalty(node, op):
  for index in py3compat.range(1, len(node.children) - 1):
    child = node.children[index]
    if isinstance(child, pytree.Leaf) and child.value == op:
      if style.Get('SPLIT_BEFORE_BITWISE_OPERATOR'):
        _SetSplitPenalty(child, style.Get('SPLIT_PENALTY_BITWISE_OPERATOR'))
      else:
        _SetSplitPenalty(
            pytree_utils.FirstLeafNode(node.children[index + 1]),
            style.Get('SPLIT_PENALTY_BITWISE_OPERATOR'))
Example #6
0
def _SetExpressionOperandPenalty(node, ops):
  for index in py3compat.range(1, len(node.children) - 1):
    child = node.children[index]
    if pytree_utils.NodeName(child) in ops:
      if style.Get('SPLIT_BEFORE_ARITHMETIC_OPERATOR'):
        _SetSplitPenalty(child, style.Get('SPLIT_PENALTY_ARITHMETIC_OPERATOR'))
      else:
        _SetSplitPenalty(
            pytree_utils.FirstLeafNode(node.children[index + 1]),
            style.Get('SPLIT_PENALTY_ARITHMETIC_OPERATOR'))
Example #7
0
def _SetBitwiseOperandPenalty(node, op):
  for index in py3compat.range(1, len(node.children) - 1):
    child = node.children[index]
    if isinstance(child, pytree.Leaf) and child.value == op:
      if style.Get('SPLIT_BEFORE_BITWISE_OPERATOR'):
        _SetSplitPenalty(child, style.Get('SPLIT_PENALTY_BITWISE_OPERATOR'))
      else:
        _SetSplitPenalty(
            pytree_utils.FirstLeafNode(node.children[index + 1]),
            style.Get('SPLIT_PENALTY_BITWISE_OPERATOR'))
Example #8
0
  def Visit_tname(self, node):  # pylint: disable=invalid-name
    # tname ::= NAME [':' test]
    self.DefaultNodeVisit(node)

    for index in py3compat.range(1, len(node.children) - 1):
      child = node.children[index]
      if isinstance(child, pytree.Leaf) and child.value == ':':
        _SetSplitPenalty(
            pytree_utils.FirstLeafNode(node.children[index]), NAMED_ASSIGN)
        _SetSplitPenalty(
            pytree_utils.FirstLeafNode(node.children[index + 1]), NAMED_ASSIGN)
Example #9
0
  def Visit_argument(self, node):  # pylint: disable=invalid-name
    # argument ::= test [comp_for] | test '=' test  # Really [keyword '='] test
    self.DefaultNodeVisit(node)

    for index in py3compat.range(1, len(node.children) - 1):
      child = node.children[index]
      if isinstance(child, pytree.Leaf) and child.value == '=':
        _SetSplitPenalty(
            pytree_utils.FirstLeafNode(node.children[index]), NAMED_ASSIGN)
        _SetSplitPenalty(
            pytree_utils.FirstLeafNode(node.children[index + 1]), NAMED_ASSIGN)
Example #10
0
  def Visit_tname(self, node):  # pylint: disable=invalid-name
    # tname ::= NAME [':' test]
    self.DefaultNodeVisit(node)

    for index in py3compat.range(1, len(node.children) - 1):
      child = node.children[index]
      if isinstance(child, pytree.Leaf) and child.value == ':':
        _SetSplitPenalty(
            pytree_utils.FirstLeafNode(node.children[index]), NAMED_ASSIGN)
        _SetSplitPenalty(
            pytree_utils.FirstLeafNode(node.children[index + 1]), NAMED_ASSIGN)
Example #11
0
  def Visit_argument(self, node):  # pylint: disable=invalid-name
    # argument ::= test [comp_for] | test '=' test  # Really [keyword '='] test
    self.DefaultNodeVisit(node)

    for index in py3compat.range(1, len(node.children) - 1):
      child = node.children[index]
      if isinstance(child, pytree.Leaf) and child.value == '=':
        _SetSplitPenalty(
            pytree_utils.FirstLeafNode(node.children[index]), NAMED_ASSIGN)
        _SetSplitPenalty(
            pytree_utils.FirstLeafNode(node.children[index + 1]), NAMED_ASSIGN)
Example #12
0
    def Visit_arglist(self, node):  # pylint: disable=invalid-name
        # arglist ::= argument (',' argument)* [',']
        self.DefaultNodeVisit(node)

        for index in py3compat.range(1, len(node.children)):
            child = node.children[index]
            if isinstance(child, pytree.Leaf) and child.value == ',':
                _SetUnbreakable(child)

        for child in node.children:
            if pytree_utils.NodeName(child) == 'atom':
                _IncreasePenalty(child, CONNECTED)
Example #13
0
  def Visit_arglist(self, node):  # pylint: disable=invalid-name
    # arglist ::= argument (',' argument)* [',']
    self.DefaultNodeVisit(node)

    for index in py3compat.range(1, len(node.children)):
      child = node.children[index]
      if isinstance(child, pytree.Leaf) and child.value == ',':
        _SetUnbreakable(child)

    for child in node.children:
      if pytree_utils.NodeName(child) == 'atom':
        _IncreasePenalty(child, CONNECTED)
Example #14
0
    def Visit_arglist(self, node):  # pylint: disable=invalid-name
        # arglist ::= argument (',' argument)* [',']
        if node.children[0].type == grammar_token.STAR:
            # Python 3 treats a star expression as a specific expression type.
            # Process it in that method.
            self.Visit_star_expr(node)
            return

        self.DefaultNodeVisit(node)

        for index in py3compat.range(1, len(node.children)):
            child = node.children[index]
            if isinstance(child, pytree.Leaf) and child.value == ',':
                _SetUnbreakable(child)

        for child in node.children:
            if pytree_utils.NodeName(child) == 'atom':
                _IncreasePenalty(child, CONNECTED)
Example #15
0
 def _SetUnbreakableOnChildren(self, node, num_children):
   """Set an UNBREAKABLE penalty annotation on children of node."""
   for child in node.children:
     self.Visit(child)
   for i in py3compat.range(1, num_children):
     self._SetUnbreakable(node.children[i])
Example #16
0
 def _SetUnbreakableOnChildren(self, node, num_children):
     """Set an UNBREAKABLE penalty annotation on children of node."""
     for child in node.children:
         self.Visit(child)
     for i in py3compat.range(1, num_children):
         self._SetUnbreakable(node.children[i])