(self, grp_cls, tokens, ignore_ws=False)
return grp
Replace tokens by an instance of *grp_cls*.
Replace tokens by an instance of *grp_cls*.
Replace tokens by an instance of * grp_cls * .
def group_tokens(self, grp_cls, tokens, ignore_ws=False):
        """Replace tokens by an instance of *grp_cls*."""
        idx = self.token_index(tokens[0])
        if ignore_ws:
            while tokens and tokens[-1].is_whitespace():
                tokens = tokens[:-1]
        for t in tokens:
            self.tokens.remove(t)
        grp = grp_cls(tokens)
        for token in tokens:
            token.parent = grp
        grp.parent = self
        self.tokens.insert(idx, grp)
        return grp
def group_tokens ( self , grp_cls , tokens , ignore_ws = False ) : idx = self . token_index ( tokens [ 0 ] ) if ignore_ws : while tokens and tokens [ - 1 ] . is_whitespace ( ) : tokens = tokens [ : - 1 ] for t in tokens : self . tokens . remove ( t ) grp = grp_cls ( tokens ) for token in tokens : token . parent = grp grp . parent = self self . tokens . insert ( idx , grp ) return grp