peng/functions.py
def _get_functions(expr, ldelim="(", rdelim=")"):
    """Parse function calls."""
    tpars = _pair_delims(expr, ldelim=ldelim, rdelim=rdelim)
    alphas = "abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    fchars = "abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "0123456789" "_"
    tfuncs = []
    for lnum, rnum in tpars:
        if lnum and expr[lnum - 1] in fchars:
            for cnum, char in enumerate(reversed(expr[:lnum])):
                if char not in fchars:
                    break
            else:
                cnum = lnum
            tfuncs.append(
                {
                    "fname": expr[lnum - cnum : lnum],
                    "expr": expr[lnum + 1 : rnum],
                    "start": lnum - cnum,
                    "stop": rnum,
                }
            )
            if expr[lnum - cnum] not in alphas:
                raise RuntimeError(
                    "Function name `{0}` is not valid".format(expr[lnum - cnum : lnum])
                )
    return tfuncs
def _get_functions(expr, ldelim="(", rdelim=")"):
    """Parse function calls."""
    tpars = _pair_delims(expr, ldelim=ldelim, rdelim=rdelim)
    alphas = "abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    fchars = "abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "0123456789" "_"
    tfuncs = []
    for lnum, rnum in tpars:
        if lnum and expr[lnum - 1] in fchars:
            for cnum, char in enumerate(reversed(expr[:lnum])):
                if char not in fchars:
                    break
            else:
                cnum = lnum
            tfuncs.append(
                {
                    "fname": expr[lnum - cnum : lnum],
                    "expr": expr[lnum + 1 : rnum],
                    "start": lnum - cnum,
                    "stop": rnum,
                }
            )
            if expr[lnum - cnum] not in alphas:
                raise RuntimeError(
                    "Function name `{0}` is not valid".format(expr[lnum - cnum : lnum])
                )
    return tfuncs
Parse function calls.