Wrap `child` in parentheses. This replaces `child` with an atom holding the parentheses and the old child. That requires moving the prefix. If `visible` is False, the leaves will be valueless (and thus invisible).
(parent: Node, child: LN, *, visible: bool = True)
| 988 | |
| 989 | |
| 990 | def wrap_in_parentheses(parent: Node, child: LN, *, visible: bool = True) -> None: |
| 991 | """Wrap `child` in parentheses. |
| 992 | |
| 993 | This replaces `child` with an atom holding the parentheses and the old |
| 994 | child. That requires moving the prefix. |
| 995 | |
| 996 | If `visible` is False, the leaves will be valueless (and thus invisible). |
| 997 | """ |
| 998 | lpar = Leaf(token.LPAR, "(" if visible else "") |
| 999 | rpar = Leaf(token.RPAR, ")" if visible else "") |
| 1000 | prefix = child.prefix |
| 1001 | child.prefix = "" |
| 1002 | index = child.remove() or 0 |
| 1003 | new_child = Node(syms.atom, [lpar, child, rpar]) |
| 1004 | new_child.prefix = prefix |
| 1005 | parent.insert_child(index, new_child) |
| 1006 | |
| 1007 | |
| 1008 | def unwrap_singleton_parenthesis(node: LN) -> LN | None: |
no test coverage detected