protected static function compile($stream) { $regex = self::$regex; // Reset properties for current process self::$tokenUID = 0; self::$storage = new stdClass(); self::$storage->tokens = (object) array('strings' => array(), 'comments' => array(), 'rules' => array(), 'parens' => array()); self::$storage->variables = array(); // Load in aliases and macros if (!self::$assetsLoaded) { self::loadAssets(); self::$assetsLoaded = true; } // Set the custom function regular expression $css_functions = CssCrush_Function::getFunctions(); $regex->function->custom = str_replace('<functions>', implode('|', $css_functions), $regex->function->custom); // Extract comments $stream = preg_replace_callback($regex->comment, array('self', 'cb_extractComments'), $stream); // Extract strings $stream = preg_replace_callback($regex->string, array('self', 'cb_extractStrings'), $stream); // Parse variables $stream = preg_replace_callback($regex->variables, array('self', 'cb_extractVariables'), $stream); // Calculate the variable stack self::calculateVariables(); self::log(self::$storage->variables); // Place the variables $stream = self::placeVariables($stream); // Normalize whitespace $stream = self::normalize($stream); // Adjust the stream so we can extract the rules cleanly $map = array('@' => "\n@", '}' => "}\n", '{' => "{\n", ';' => ";\n"); $stream = "\n" . str_replace(array_keys($map), array_values($map), $stream); // Extract rules $stream = preg_replace_callback($regex->rule, array('self', 'cb_extractRules'), $stream); // Alias at-rules (if there are any) $stream = self::aliasAtRules($stream); // print it all back $stream = self::display($stream); // self::log( self::$storage->tokens->rules ); // self::log( self::$storage->tokens ); self::log(self::$config->data); // Release memory self::$storage = null; return $stream; }