예제 #1
0
파일: Parser.php 프로젝트: lopo/phpsass
 /**
  * Evaluate a Script.
  *
  * @param string $expression to parse
  * @param Context $context the context in which the expression is evaluated
  * @param int $environment the environment in which the expression is evaluated
  * @return Literals\Literal parsed value
  */
 public function evaluate($expression, $context, $environment = self::DEFAULT_ENV)
 {
     self::$context = $context;
     $operands = [];
     $tokens = $this->parse($expression, $context, $environment);
     while (count($tokens)) {
         $token = array_shift($tokens);
         if ($token instanceof ScriptFunction) {
             $perform = $token->perform();
             array_push($operands, $perform);
         } elseif ($token instanceof Literals\Literal) {
             if ($token instanceof Literals\SassString) {
                 $token = new Literals\SassString($this->interpolate($token->toString(), self::$context));
             }
             array_push($operands, $token);
         } else {
             $args = [];
             for ($i = 0, $c = $token->operandCount; $i < $c; $i++) {
                 $args[] = array_pop($operands);
             }
             array_push($operands, $token->perform($args));
         }
     }
     return self::makeSingular($operands);
 }