def chunk_string(instr):
    """Convert a single multi-line string into a list of chunks (= list of strings.)
    The beginning of each chunk is denoted by a keyword beginning with '%'.
    Empty lines are ignored.
    Continuation lines (backslash at end of a line) are honoured.
    Comment lines (first non-space character is '#') are ignored.
    """
    # treat lines ending in '\' as continuation lines
    instr = instr.replace('\\\n', ' ')
    nonblank_lines = [ln.strip() for ln in instr.splitlines() if ln]
    ll_lst = [ln for ln in nonblank_lines if not ln.startswith('#')]
    ndxlst = [ndx for ndx, l in enumerate(ll_lst) if l.startswith('%')] + [len(ll_lst)]
    return [ll_lst[strt:stop] for strt, stop in [(ndxlst[nn], ndxlst[nn+1]) for nn in range(len(ndxlst)-1)]]