def parse_inlinefunc(string, strip=False, **kwargs):
    """
    Parse the incoming string.

    Args:
        string (str): The incoming string to parse.
        strip (bool, optional): Whether to strip function calls rather than
            execute them.
    Kwargs:
        session (Session): This is sent to this function by Evennia when triggering
            it. It is passed to the inlinefunc.
        kwargs (any): All other kwargs are also passed on to the inlinefunc.


    """
    global _PARSING_CACHE
    if string in _PARSING_CACHE:
        # stack is already cached
        stack = _PARSING_CACHE[string]
    else:
        # not a cached string.
        if not _RE_STARTTOKEN.search(string):
            # if there are no unescaped start tokens at all, return immediately.
            return string

        # build a new cache entry
        stack = ParseStack()
        ncallable = 0
        for match in _RE_TOKEN.finditer(string):
            gdict = match.groupdict()
            if gdict["singlequote"]:
                stack.append(gdict["singlequote"])
            elif gdict["doublequote"]:
                stack.append(gdict["doublequote"])
            elif gdict["end"]:
                if ncallable <= 0:
                    stack.append(")")
                    continue
                args = []
                while stack:
                    operation = stack.pop()
                    if callable(operation):
                        if not strip:
                            stack.append((operation, [arg for arg in reversed(args)]))
                        ncallable -= 1
                        break
                    else:
                        args.append(operation)
            elif gdict["start"]:
                funcname = _RE_STARTTOKEN.match(gdict["start"]).group(1)
                try:
                    # try to fetch the matching inlinefunc from storage
                    stack.append(_INLINE_FUNCS[funcname])
                except __HOLE__:
                    stack.append(_INLINE_FUNCS["nomatch"])
                    stack.append(funcname)
                ncallable += 1
            elif gdict["escaped"]:
                # escaped tokens
                token = gdict["escaped"].lstrip("\\")
                stack.append(token)
            elif gdict["comma"]:
                if ncallable > 0:
                    # commas outside strings and inside a callable are
                    # used to mark argument separation - we use None
                    # in the stack to indicate such a separation.
                    stack.append(None)
                else:
                    # no callable active - just a string
                    stack.append(",")
            else:
                # the rest
                stack.append(gdict["rest"])

        if ncallable > 0:
            # this means not all inlinefuncs were complete
            return string

        if _STACK_MAXSIZE > 0 and _STACK_MAXSIZE < len(stack):
            # if stack is larger than limit, throw away parsing
            return string + gdict["stackfull"](*args, **kwargs)
        else:
            # cache the result
            _PARSING_CACHE[string] = stack

    # run the stack recursively
    def _run_stack(item, depth=0):
        retval = item
        if isinstance(item, tuple):
            if strip:
                return ""
            else:
                func, arglist = item
                args = [""]
                for arg in arglist:
                    if arg is None:
                        # an argument-separating comma - start a new arg
                        args.append("")
                    else:
                        # all other args should merge into one string
                        args[-1] += _run_stack(arg, depth=depth+1)
                # execute the inlinefunc at this point or strip it.
                kwargs["inlinefunc_stack_depth"] = depth
                retval = "" if strip else func(*args, **kwargs)
        return utils.to_str(retval, force_string=True)

    # execute the stack from the cache
    return "".join(_run_stack(item) for item in _PARSING_CACHE[string])
dataset/ETHPy150Open evennia/evennia/evennia/utils/nested_inlinefuncs.py/parse_inlinefunc