'Recursively adds a linear pattern to the AC automaton'

def add(self, pattern, start):

    if (not pattern):
        return [start]
    else:
        if isinstance(pattern[0], tuple):
            match_nodes = []
            for alternative in pattern[0]:
                end_nodes = self.add(alternative, start=start)
                for end in end_nodes:
                    match_nodes.extend(self.add(pattern[1:], end))
            return match_nodes
        if (pattern[0] not in start.transition_table):
            next_node = BMNode()
            start.transition_table[pattern[0]] = next_node
        else:
            next_node = start.transition_table[pattern[0]]
        if pattern[1:]:
            end_nodes = self.add(pattern[1:], start=next_node)
        else:
            end_nodes = [next_node]
        return end_nodes
