Наследование: extends SassLiteral
Пример #1
0
 /**
  * Lex an expression into SassScript tokens.
  * @param string $string expression to lex
  * @param SassContext $context the context in which the expression is lexed
  * @return array tokens
  */
 public function lex($string, $context)
 {
     // if it's already lexed, just return it as-is
     if (is_object($string)) {
         return array($string);
     }
     if (is_array($string)) {
         return $string;
     }
     $tokens = array();
     // whilst the string is not empty, split it into it's tokens.
     while ($string !== false) {
         if (($match = $this->isWhitespace($string)) !== false) {
             $tokens[] = null;
         } elseif (($match = SassScriptFunction::isa($string)) !== false) {
             preg_match(SassScriptFunction::MATCH_FUNC, $match, $matches);
             $args = array();
             foreach (SassScriptFunction::extractArgs($matches[SassScriptFunction::ARGS], false, $context) as $key => $expression) {
                 $args[$key] = $this->parser->evaluate($expression, $context);
             }
             $tokens[] = new SassScriptFunction($matches[SassScriptFunction::NAME], $args);
         } elseif (($match = SassBoolean::isa($string)) !== false) {
             $tokens[] = new SassBoolean($match);
         } elseif (($match = SassColour::isa($string)) !== false) {
             $tokens[] = new SassColour($match);
         } elseif (($match = SassNumber::isa($string)) !== false) {
             $tokens[] = new SassNumber($match);
         } elseif (($match = SassString::isa($string)) !== false) {
             $stringed = new SassString($match);
             if (strlen($stringed->quote) == 0 && SassList::isa($string) !== false && !preg_match("/^\\-\\w+\\-\\w+\$/", $stringed->value)) {
                 $tokens[] = new SassList($string);
             } else {
                 $tokens[] = $stringed;
             }
         } elseif ($string == '()') {
             $match = $string;
             $tokens[] = new SassList($match);
         } elseif (($match = SassScriptOperation::isa($string)) !== false) {
             $tokens[] = new SassScriptOperation($match);
         } elseif (($match = SassScriptVariable::isa($string)) !== false) {
             $tokens[] = new SassScriptVariable($match);
         } else {
             $_string = $string;
             $match = '';
             while (strlen($_string) && !$this->isWhitespace($_string)) {
                 foreach (SassScriptOperation::$inStrOperators as $operator) {
                     if (substr($_string, 0, strlen($operator)) == $operator) {
                         break 2;
                     }
                 }
                 $match .= $_string[0];
                 $_string = substr($_string, 1);
             }
             $tokens[] = new SassString($match);
         }
         $string = substr($string, strlen($match));
     }
     return $tokens;
 }
 /**
  * SassImportNode.
  *
  * @param object source token
  *
  * @return SassImportNode
  */
 public function __construct($token, $parent)
 {
     parent::__construct($token, $parent);
     preg_match(self::MATCH, $token->source, $matches);
     foreach (SassList::_build_list($matches[self::FILES]) as $file) {
         $this->files[] = trim($file, '"\'; ');
     }
 }
 /**
  * Parse this node.
  * @param SassContext the context in which this node is parsed
  * @return array parsed child nodes
  */
 public function parse($context)
 {
     $children = array();
     if ($this->variable && $this->in) {
         $context = new SassContext($context);
         list($in, $sep) = SassList::_parse_list($this->in, 'auto', true, $context);
         foreach ($in as $var) {
             $context->setVariable($this->variable, $var);
             $children = array_merge($children, $this->parseChildren($context));
         }
     }
     $context->merge();
     return $children;
 }
Пример #4
0
 public static function extractArgs($string, $include_null = TRUE, $context)
 {
     $args = array();
     $arg = '';
     $paren = 0;
     $strpos = 0;
     $strlen = strlen($string);
     $list = SassList::_build_list($string, ',');
     $return = array();
     foreach ($list as $k => $value) {
         if (substr($value, -3, 3) == '...' && preg_match(SassVariableNode::MATCH, substr($value, 0, -3) . ':', $match)) {
             $list = new SassList($context->getVariable($match[SassVariableNode::NAME]));
             if (count($list->value) > 1) {
                 $return = array_merge($return, $list->value);
                 continue;
             }
         }
         if (strpos($value, ':') !== false && preg_match(SassVariableNode::MATCH, $value, $match)) {
             $return[$match[SassVariableNode::NAME]] = $match[SassVariableNode::VALUE];
         } else {
             if (substr($value, 0, 1) == '$' && $include_null) {
                 $return[str_replace('$', '', $value)] = NULL;
             } elseif ($include_null || $value !== NULL) {
                 $return[] = $value;
             }
         }
     }
     return $return;
 }
Пример #5
0
 /**
  * Resolves selectors.
  * Interpolates SassScript in selectors and resolves any parent references or
  * appends the parent selectors.
  * @param SassContext the context in which this node is parsed
  *
  * Change: 7/Dec/11 - change to make selector ordering conform to Ruby compiler.
  */
 public function resolveSelectors($context)
 {
     $resolvedSelectors = $normalSelectors = array();
     $this->parentSelectors = $this->getParentSelectors($context);
     foreach ($this->selectors as $key => $selector) {
         $selector = $this->interpolate($selector, $context);
         $selectors = SassList::_build_list($selector);
         foreach ($selectors as $selector) {
             $selector = trim($selector, ' \'"');
             // strip whitespace and quotes, just-in-case.
             if ($this->hasParentReference($selector)) {
                 $resolvedSelectors = array_merge($resolvedSelectors, $this->resolveParentReferences($selector, $context));
             } else {
                 $normalSelectors[] = $selector;
             }
         }
     }
     // foreach
     // merge with parent selectors
     if ($this->parentSelectors) {
         $return = array();
         foreach ($this->parentSelectors as $parent) {
             foreach ($normalSelectors as $selector) {
                 $spacer = substr($selector, 0, 1) == '[' ? '' : ' ';
                 $return[] = $parent . $spacer . $selector;
             }
         }
         $normalSelectors = $return;
     }
     return array_merge($normalSelectors, $resolvedSelectors);
 }
Пример #6
0
 public function getTypeOf()
 {
     if (SassList::isa($this->toString())) {
         return 'list';
     }
     return 'string';
 }
Пример #7
0
 public static function index($list, $value)
 {
     if (!$list instanceof SassList) {
         $list = new SassList($list->toString());
     }
     return $list->index($value);
 }
 public static function extractArgs($string, $include_null = TRUE)
 {
     $args = array();
     $arg = '';
     $paren = 0;
     $strpos = 0;
     $strlen = strlen($string);
     $list = SassList::_build_list($string, ',');
     $return = array();
     foreach ($list as $k => $value) {
         if (strpos($value, ':') !== false && preg_match(SassVariableNode::MATCH, $value, $match)) {
             $return[$match[SassVariableNode::NAME]] = $match[SassVariableNode::VALUE];
         } else {
             if (substr($value, 0, 1) == '$' && $include_null) {
                 $return[str_replace('$', '', $value)] = NULL;
             } elseif ($include_null || $value !== NULL) {
                 $return[] = $value;
             }
         }
     }
     return $return;
 }
 public static function append($list, $val, $sep = ', ')
 {
     if ($list instanceof SassString) {
         $list = new SassList($list->toString());
     }
     $list->append($val, $sep);
     return $list;
 }