SassScriptFunction::extractArgs PHP Method

extractArgs() public static method

public static extractArgs ( $string, $include_null = TRUE, $context )
    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];
            } elseif (substr($value, 0, 1) == '$' && $include_null) {
                $return[str_replace('$', '', $value)] = NULL;
            } elseif ($include_null || $value !== NULL) {
                $return[] = $value;
            }
        }
        return $return;
    }

Usage Example

Exemplo n.º 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;
 }
All Usage Examples Of SassScriptFunction::extractArgs