def process_string_for_escapes(string_or_char_list, escape_char, open_group
    =None, close_group=None):
    """A utility routine which takes a string or character list with
    possibly-escaped elements as an argument and returns a list of two-tuples.

    The first element of a returned two-tuple is the actual character, and the
    second a boolean for whether or not it is escaped.

    If `open_group` and/or `close_group` is set to an opening or closing paren
    or bracket character the function returns a list of three-tuples, where the
    last element gives the level of parenthesis nesting, starting at zero and
    increasing.  An open and its corresponding close have the same level."""
    escaped = False
    tuple_list = []
    p_count = 0
    for elem in string_or_char_list:
        if elem == escape_char and not escaped:
            escaped = True
            continue
        if escaped:
            bool_val = True
            if open_group and elem == open_group:
                p_count += 1
        else:
            bool_val = False
        if open_group or close_group:
            tuple_list.append((elem, bool_val, p_count))
        else:
            tuple_list.append((elem, bool_val))
        if escaped:
            escaped = False
            if close_group and elem == close_group:
                p_count -= 1
    return tuple_list
