(self, parser, group)
return top
This filter finds open and close bracket markers in a flat group
        and uses them to organize the nodes into a hierarchy.
This filter finds open and close bracket markers in a flat group
        and uses them to organize the nodes into a hierarchy.
This filter finds open and close bracket markers in a flat group and uses them to organize the nodes into a hierarchy .
def do_groups(self, parser, group):
        """This filter finds open and close bracket markers in a flat group
        and uses them to organize the nodes into a hierarchy.
        """

        ob, cb = self.OpenBracket, self.CloseBracket
        # Group hierarchy stack
        stack = [parser.group()]
        for node in group:
            if isinstance(node, ob):
                # Open bracket: push a new level of hierarchy on the stack
                stack.append(parser.group())
            elif isinstance(node, cb):
                # Close bracket: pop the current level of hierarchy and append
                # it to the previous level
                if len(stack) > 1:
                    last = stack.pop()
                    stack[-1].append(last)
            else:
                # Anything else: add it to the current level of hierarchy
                stack[-1].append(node)

        top = stack[0]
        # If the parens were unbalanced (more opens than closes), just take
        # whatever levels of hierarchy were left on the stack and tack them on
        # the end of the top-level
        if len(stack) > 1:
            for ls in stack[1:]:
                top.extend(ls)

        if len(top) == 1 and isinstance(top[0], syntax.GroupNode):
            boost = top.boost
            top = top[0]
            top.boost = boost

        return top
def do_groups ( self , parser , group ) : ob , cb = self . OpenBracket , self . CloseBracket # Group hierarchy stack stack = [ parser . group ( ) ] for node in group : if isinstance ( node , ob ) : # Open bracket: push a new level of hierarchy on the stack stack . append ( parser . group ( ) ) elif isinstance ( node , cb ) : # Close bracket: pop the current level of hierarchy and append # it to the previous level if len ( stack ) > 1 : last = stack . pop ( ) stack [ - 1 ] . append ( last ) else : # Anything else: add it to the current level of hierarchy stack [ - 1 ] . append ( node ) top = stack [ 0 ] # If the parens were unbalanced (more opens than closes), just take # whatever levels of hierarchy were left on the stack and tack them on # the end of the top-level if len ( stack ) > 1 : for ls in stack [ 1 : ] : top . extend ( ls ) if len ( top ) == 1 and isinstance ( top [ 0 ] , syntax . GroupNode ) : boost = top . boost top = top [ 0 ] top . boost = boost return top