def _tokenize_ge_list()

in gridengine/src/gridengine/util.py [0:0]


def _tokenize_ge_list(expr: str) -> List[str]:
    """ Since GE can use either a comma or space to separate both expressions and
        the lists that map a hostgroup to various things, we have to use a stateful parser.
        e.g. NONE,[@hostgroup=pe1 pe2],[@hostgroup2=pe3,pe4]
        A simple re.split is fine for the subexprs.
    """
    buf = StringIO()
    toks = []

    def append_if_token() -> StringIO:
        if buf.getvalue():
            toks.append(buf.getvalue())
        return StringIO()

    in_left_bracket = False

    for c in expr:
        if c.isalnum():
            buf.write(c)
        elif c == "[":
            in_left_bracket = True
            buf.write(c)
        elif c == "]":
            in_left_bracket = False
            buf.write(c)
        elif c in [" ", ","] and not in_left_bracket:
            buf = append_if_token()
        else:
            buf.write(c)

    buf = append_if_token()
    return toks