def match_automaton(string, automaton, boundary_check=None):
    """
    See if can match string to string matching automaton.
    This is aided by a boundary check callable which helps ascertain
    whether the matched substring occurs within some boundaries (e.g. token boundaries).

    """
    for end_position, (length, *tail) in automaton.iter(string):
        end_idx = end_position + 1
        start_idx = end_idx - length
        if boundary_check and not boundary_check(string, start_idx, end_idx):
            continue
        return True
    return False
