You are here

function lessc::evaluate in Less CSS Preprocessor 6.3

Same name and namespace in other branches
  1. 6 lessc.inc.php \lessc::evaluate()
3 calls to lessc::evaluate()
lessc::compileValue in lessphp/lessc.inc.php
lessc::expHelper in lessphp/lessc.inc.php
lessc::reduce in lessphp/lessc.inc.php

File

lessphp/lessc.inc.php, line 902

Class

lessc

Code

function evaluate($op, $left, $right) {
  $left = $this
    ->reduce($left);
  $right = $this
    ->reduce($right);
  if ($left[0] == 'color' && $right[0] == 'color') {
    $out = $this
      ->op_color_color($op, $left, $right);
    return $out;
  }
  if ($left[0] == 'color') {
    return $this
      ->op_color_number($op, $left, $right);
  }
  if ($right[0] == 'color') {
    return $this
      ->op_number_color($op, $left, $right);
  }

  // concatenate strings
  if ($op == '+' && $left[0] == 'string') {
    $append = $this
      ->compileValue($right);
    if ($this
      ->quoted($append)) {
      $append = substr($append, 1, -1);
    }
    $lhs = $this
      ->compileValue($left);
    if ($q = $this
      ->quoted($lhs)) {
      $lhs = substr($lhs, 1, -1);
    }
    if (!$q) {
      $q = '';
    }
    return array(
      'string',
      $q . $lhs . $append . $q,
    );
  }
  if ($left[0] == 'keyword' || $right[0] == 'keyword' || $left[0] == 'string' || $right[0] == 'string') {

    // look for negative op
    if ($op == '-') {
      $right[1] = '-' . $right[1];
    }
    return array(
      'keyword',
      $this
        ->compileValue($left) . ' ' . $this
        ->compileValue($right),
    );
  }

  // default to number operation
  return $this
    ->op_number_number($op, $left, $right);
}