Parses a single function argument. Can be expression or
function by itself.

@param string $funcName
@param int $context
@throws \Exception
@return Functions\SoqlFunctionInterface|AST\SoqlName
430268
private function parseFunctionArgument($funcName, $context)
    {
        try
        {
            return $this->parsePrimitiveValue();
        }
        catch(\Exception $e)
        {
            $name = $this->tokenizer->getTokenValue();

            if($name)
            {
                // ADVANCE
                $this->tokenizer->readNextToken();

                // NESTED FUNCTION
                if($this->tokenizer->is(TokenType::LEFT_PAREN))
                {
                    return $this->parseFunctionExpression($name, $context);
                }

                // ARBITRARY IDENTIFIER, e.g. SOQL NAME
                return new AST\SoqlName($name);
            }
            throw $e;
        }
    }
700336
private function funcNameToUnderscore($funcName)
    {
        $camel = \preg_replace(
            '/(?!^)[[:upper:]][[:lower:]]/',
            '$0',
            \preg_replace(
                '/(?!^)[[:upper:]]+/', "_" . '$0',
                \str_replace(['::__construct', '::'], ['', '.'], $funcName)
            )
        );

        return \str_replace('_attribute', '', \strtolower($camel));
    }
462676
public static function executeWithLocale($locale, $func)
    {
        $currentLocale = static::getLocale();
        $result = call_user_func($func, static::setLocale($locale) ? static::getLocale() : false, static::translator());
        static::setLocale($currentLocale);

        return $result;
    }
183959
public function callFunction($functionName, $parameters)
    {
        $parameters = is_array($parameters) ? $parameters : array();
        $response = call_user_func_array(array($this->getObject(), $functionName), $parameters);

        return $response;
    }
261174
@Override
    public Object visitFunctionCall(ExcellentParser.FunctionCallContext ctx) {
        String funcName = ctx.fnname().getText();
        List<Object> parameters;
        if (ctx.parameters() != null) {
            parameters = (List<Object>) visit(ctx.parameters());
        } else {
            parameters = Collections.emptyList();
        }
        return m_functions.invokeFunction(m_evalContext, funcName, parameters);
    }
536725
public function registerFunction(ExpressionFunctionInterface $function)
    {
        $this->expressionLanguage->register(
            $function->getName(),
            $function->getCompiler(),
            $function->getEvaluator()
        );

        foreach ($function->getContextVariables() as $name => $value) {
            $this->setContextVariable($name, $value);
        }

        return $this;
    }
691117
protected function func($name, &$func)
    {
        $s = $this->count;

        if ($this->matchChar('(')) {
            if ($name === 'alpha' && $this->argumentList($args)) {
                $func = [Type::T_FUNCTION, $name, [Type::T_STRING, '', $args]];

                return true;
            }

            if ($name !== 'expression' && ! preg_match('/^(-[a-z]+-)?calc$/', $name)) {
                $ss = $this->count;

                if ($this->argValues($args) && $this->matchChar(')')) {
                    $func = [Type::T_FUNCTION_CALL, $name, $args];

                    return true;
                }

                $this->seek($ss);
            }

            if (($this->openString(')', $str, '(') || true) &&
                $this->matchChar(')')
            ) {
                $args = [];

                if (! empty($str)) {
                    $args[] = [null, [Type::T_STRING, '', [$str]]];
                }

                $func = [Type::T_FUNCTION_CALL, $name, $args];

                return true;
            }
        }

        $this->seek($s);

        return false;
    }
871041
public static function fromFunction(
        string $fn
    ): array
    {
        try {

            $fn = new \ReflectionFunction($fn);
        }
        catch (\ReflectionException $e) {

            throw new Exception(
                "Function {$fn} not found.",
                Exception::FUNCTION_NOT_FOUND
            );
        }

        $docComment = $fn->getDocComment();

        unset($fn);

        if ($docComment === false) {

            return [];
        }

        return Parser::parseDocComment($docComment);
    }
1068235
protected function parseFunc($func)
    {
        $result = '';
        switch (strtolower(trim($func))) {
            case 'eq':
                $result = self::TMPL_ALIAS . ' = ' . self::TMPL_VALUE;
                break;
            case 'neq':
                $result = self::TMPL_ALIAS . ' <> ' . self::TMPL_VALUE;
                break;
            case 'gt':
                $result = self::TMPL_ALIAS . ' > ' . self::TMPL_VALUE;
                break;
            case 'gte':
                $result = self::TMPL_ALIAS . ' >= ' . self::TMPL_VALUE;
                break;
            case 'lt':
                $result = self::TMPL_ALIAS . ' < ' . self::TMPL_VALUE;
                break;
            case 'lte':
                $result = self::TMPL_ALIAS . ' <= ' . self::TMPL_VALUE;
                break;
            case 'like':
                $result = self::TMPL_ALIAS . ' LIKE ' . self::TMPL_VALUE;
                break;
            case 'is_null':
                $result = self::TMPL_ALIAS . ' IS NULL';
                break;
            case 'is_not_null':
                $result = self::TMPL_ALIAS . ' IS NOT NULL';
                break;
        }
        return $result;
    }
175365
public function functionExists($functionName, CompilationContext $context)
    {
        if (\function_exists($functionName)) {
            return true;
        }
        if ($this->isBuiltInFunction($functionName)) {
            return true;
        }

        $internalName = ['f__'.$functionName];
        if (isset($context->classDefinition)) {
            $lowerNamespace = strtolower($context->classDefinition->getNamespace());
            $prefix = 'f_'.str_replace('\\', '_', $lowerNamespace);

            $internalName[] = $prefix.'_'.$functionName;
        }

        foreach ($internalName as $name) {
            if (isset($context->compiler->functionDefinitions[$name])) {
                return true;
            }
        }

        return false;
    }
969737
public function execute($callable, array $args = [], $context = null)
    {
        if ($callable instanceof \Closure) {
            $ref = new \ReflectionObject($callable);

            $args = $this->getMethodArgs($ref->getMethod('__invoke'), $args);
        } else {
            if (is_string($callable)) {
                $callable = explode('::', $callable);
            }

            list($object, $method) = $callable;

            $ref = new \ReflectionClass($object);

            $args = $this->getMethodArgs($ref->getMethod($method), $args);
        }

        $closure = function () use ($args, $callable) {
            switch (count($args)) {
                case 0:
                    return $callable();
                case 1:
                    return $callable($args[0]);
                case 2:
                    return $callable($args[0], $args[1]);
                case 3:
                    return $callable($args[0], $args[1], $args[2]);
                case 4:
                    return $callable($args[0], $args[1], $args[2], $args[3]);
                default:
                    return call_user_func_array($callable, $args);
            }
        };

        if ($context) {
            $closure = $closure->bindTo($context, $context);
        }

        return $closure();
    }
34414
public static function __callstatic($name, $params)
    {
        $matches = static::isFigletCall($name);

        if (null === $matches) {
            throw new Exception("Unknown figlet function name $name");
        }

        $fontName = $matches[2];

        // target string is expected to be:
        $targetString = $params[0][0];

        return static::render($targetString, $fontName);
    }
937961
public function evaluate(Context $context, $arity, $arguments) {
		if($arity <= 1) {
			throw new FunctionCallException(
				'substr', 
				'Too few arguments.',
                $context->getFilename(),
                $context->tag->getLineNumber()
			);
		}

		$string = $arguments[0];
		$start = $arguments[1];
		if(3 <= $arity) {
			$length = $arguments[2];
			return substr($string, $start ,$length);
		} else {
			return substr($string, $start);
		}
	}
711565
public function listen($name, $fn, $context = array())
    {
        $event = new Event($name, $fn, $context);
        if (!isset($this->handlers[$name])) {
            $this->handlers[$name] = array();
        }
        $this->handlers[$name][] = $event;// array('fn' => $fn, 'context' => $context);
        return $event;
    }
112883
public function addFunc(FunctionEntity $func)
    {
        $this->fullClassName = $func->getClass();

        // Skip the method if it's an @internal one.
        $methodFullDoc = (new ReflectionMethod($this->fullClassName, $func->getName()))->getDocComment();
        foreach (explode(PHP_EOL, $methodFullDoc) as $line) {
            if (strpos($line, ' @internal ') !== false) {
                return '';
            }
        }

        $str = PHP_EOL . '<h3>' . $func->getName() . '</h3>' . "\n\n<hr>\n\n";

        $str .= $this->parser->text($func->getDescription());

        if (!$func->getExample()) {
            throw new RuntimeException("Method {$func->getClass()}::{$func->getName()} is missing an example.");
        }

        $rawExample = $func->getExample();
        $example = $this->parser->text($rawExample);
        $str .= PHP_EOL . $example;

        if ($func->hasParams()) {
            $str .= PHP_EOL . '<h4>Parameters</h4>' . PHP_EOL . '<ul>';
            $params = [];
            foreach ($func->getParams() as $param) {
                $paramStr = sprintf('<li><code>%s</code> <strong>%s</strong>', $param->getType(), $param->getName());

                $description = $param->getDescription();

                if (!empty($description)) {
                    $paramStr .= ' - ' . $this->parser->line($param->getDescription());
                }

                $params[] = $paramStr . '</li>';
            }
            $str .= PHP_EOL . implode(PHP_EOL, $params);
            $str .= '</ul>';
        }


        $this->output .= PHP_EOL . $str . PHP_EOL  . '  ';
        $this->index[] = $func->getName();
        return $str;
    }
674516
static function gnameForRef($fname) {
		$refDefs = static::refDefs();
		$gname = $refDefs[$fname][static::GNAME];
		if ($gname === null) {
			throw new \Exception("Invalid fname `$fname` called for gnameForRef");
		}
		return $gname;
	}
605140
public function create($funcName) {
		
		$dirname = dirname(__FILE__).'/functions';
		$filename = "$dirname/Function_$funcName.php";
		if( !file_exists($filename) ) {
					return null;
		}


		require_once "$dirname/Function_$funcName.php";

		$funcClassName = '\\figdice\\classes\\functions\\Function_'.$funcName;

		$reflection = new \ReflectionClass($funcClassName);
		/** @var FigFunction $function */
		$function = $reflection->newInstance();
		return $function;
	}