# Buggy code
def tokenize(snippet):
    """Split snippet into well-defined tokens."""
    tokens = []
    word = ""
    i = 0
    last_name = None
    while i < len(snippet):
        c = snippet[i]
        if whitespace.match(c) is not None:
            if last_name is not None:
                token = Token(last_name, word, 1, i + 1)
                tokens.append(token)
            token = Token("whitespace", c, line=1, col=i + 1)
            tokens.append(token)
            word = ""
            last_name = None
            i += 1
        else:
            temp_word = word + c
            match_found = False
            for token_name in token_regex:
                regex = token_regex[token_name]
                if regex.match(temp_word) is not None:
                    last_name = token_name
                    match_found = True
                    word = temp_word
                    break
            if not match_found:
                if last_name is not None:
                    token = Token(last_name, word, 1, i + 1)
                    tokens.append(token)
                    word = ""
                    last_name = None
            else:
                i += 1
    if last_name is not None:
        token = Token(last_name, word, 1, i + 1)
        tokens.append(token)
    return tokens


# Traceback (AttributeError)
File "/home/dbau/miniconda3/envs/spyder-beta/lib/python3.7/site-packages/spyder/plugins/editor/extensions/snippets.py", line 194, in _on_key_pressed
self._process_text(text)
File "/home/dbau/miniconda3/envs/spyder-beta/lib/python3.7/site-packages/spyder/plugins/editor/extensions/snippets.py", line 49, in wrapper
return f(self, *args, **kwargs)
File "/home/dbau/miniconda3/envs/spyder-beta/lib/python3.7/site-packages/spyder/plugins/editor/extensions/snippets.py", line 204, in _process_text
self.delete_text(line, column)
File "/home/dbau/miniconda3/envs/spyder-beta/lib/python3.7/site-packages/spyder/plugins/editor/extensions/snippets.py", line 240, in delete_text
self._delete_token(delete_token, text_parent, line, column)
File "/home/dbau/miniconda3/envs/spyder-beta/lib/python3.7/site-packages/spyder/plugins/editor/extensions/snippets.py", line 263, in _delete_token
if left_node.name in MERGE_ALLOWED:
AttributeError: 'PlaceholderNode' object has no attribute 'name'

# Fixed code
def tokenize(snippet):
    """Split snippet into well-defined tokens."""
    tokens = []
    word = ""
    i = 0
    last_name = None
    while i < len(snippet):
        c = snippet[i]
        if whitespace.match(c) is not None:
            if last_name is not None:
                token = Token(last_name, word, 1, i + 1)
                tokens.append(token)
            token = Token("whitespace", c, line=1, col=i + 1)
            tokens.append(token)
            word = ""
            last_name = None
            i += 1
        else:
            temp_word = word + c
            match_found = False
            for token_name in token_regex:
                regex = token_regex[token_name]
                if regex.match(temp_word) is not None:
                    last_name = token_name
                    match_found = True
                    word = temp_word
                    break
            if not match_found:
                if last_name is not None:
                    token = Token(last_name, word, 1, i + 1)
                    tokens.append(token)
                    word = ""
                    last_name = None
            else:
                word = temp_word
                i += 1
    if last_name is not None:
        token = Token(last_name, word, 1, i + 1)
        tokens.append(token)
    return tokens