SassScriptParser::evaluate PHP Method

evaluate() public method

Evaluate a SassScript.
public evaluate ( string $expression, SassContext $context, integer $environment = self::DEFAULT_ENV ) : SassLiteral
$expression string expression to parse
$context SassContext the context in which the expression is evaluated
$environment integer the environment in which the expression is evaluated
return SassLiteral parsed value
    public function evaluate($expression, $context, $environment = self::DEFAULT_ENV)
    {
        self::$context = $context;
        $operands = array();
        $tokens = $this->parse($expression, $context, $environment);
        while (count($tokens)) {
            $token = array_shift($tokens);
            if ($token instanceof SassScriptFunction) {
                $perform = $token->perform();
                array_push($operands, $perform);
            } elseif ($token instanceof SassLiteral) {
                if ($token instanceof SassString) {
                    $token = new SassString($this->interpolate($token->toString(), self::$context));
                }
                array_push($operands, $token);
            } else {
                $args = array();
                for ($i = 0, $c = $token->operandCount; $i < $c; $i++) {
                    $args[] = array_pop($operands);
                }
                array_push($operands, $token->perform($args));
            }
        }
        return self::makeSingular($operands);
    }