@normalize.implementation(for_type=ast.VariadicExpression)<EOL>def normalize(expr):
children = []<EOL>for child in expr.children:<EOL><INDENT>branch = normalize(child)<EOL>if branch is None:<EOL><INDENT>continue<EOL><DEDENT>if type(branch) is type(expr):<EOL><INDENT>children.extend(branch.children)<EOL><DEDENT>else:<EOL><INDENT>children.append(branch)<EOL><DEDENT><DEDENT>if len(children) == <NUM_LIT:0>:<EOL><INDENT>return None<EOL><DEDENT>if len(children) == <NUM_LIT:1>:<EOL><INDENT>return children[<NUM_LIT:0>]<EOL><DEDENT>return type(expr)(*children, start=children[<NUM_LIT:0>].start,<EOL>end=children[-<NUM_LIT:1>].end)<EOL>
Pass through n-ary expressions, and eliminate empty branches.

    Variadic and binary expressions recursively visit all their children.

    If all children are eliminated then the parent expression is also
    eliminated:

    (& [removed] [removed]) => [removed]

    If only one child is left, it is promoted to replace the parent node:

    (& True) => True