import re


def _ppddl_tokenize(ppddl_txt):
    """Break PPDDL into tokens (brackets, non-bracket chunks)"""
    # strip comments
    lines = ppddl_txt.splitlines()
    mod_lines = []
    for line in lines:
        try:
            semi_idx = line.index(';')
        except ValueError:
            pass
        else:
            line = line[:semi_idx]
        mod_lines.append(line)
    ppddl_txt = '\n'.join(mod_lines)

    # convert to lower case
    ppddl_txt = ppddl_txt.lower()

    matches = re.findall(r'\(|\)|[^\s\(\)]+', ppddl_txt)

    return matches