Lines Matching +full:g +full:- +full:guard

84 		foreach ((array)$this->importDir as $dir) {
85 $full = $dir . (substr($dir, -1) != '/' ? '/' : '') . $url;
86 if ($this->fileExists($file = $full . '.less') || $this->fileExists($file = $full)) {
113 $importPath = $this->flattenList($importPath[2]);
116 $str = $this->coerceString($importPath);
119 $url = $this->compileValue($this->lib_e($str));
122 if (substr_compare($url, '.css', -4, 4) === 0) return false;
124 $realPath = $this->findImport($url);
128 if ($this->importDisabled) {
132 if (isset($this->allParsedFiles[realpath($realPath)])) {
136 $this->addParsedFile($realPath);
137 $parser = $this->makeParser($realPath);
138 $root = $parser->parse(file_get_contents($realPath));
141 foreach ($root->props as $prop) {
143 $prop[1]->parent = $parentBlock;
150 foreach ($root->children as $childName => $child) {
151 if (isset($parentBlock->children[$childName])) {
152 $parentBlock->children[$childName] = array_merge(
153 $parentBlock->children[$childName],
157 $parentBlock->children[$childName] = $child;
164 [$top, $bottom] = $this->sortProps($root->props, true);
165 $this->compileImportedProps($top, $parentBlock, $out, $parser, $dir);
172 $oldSourceParser = $this->sourceParser;
174 $oldImport = $this->importDir;
177 $this->importDir = (array)$this->importDir;
178 array_unshift($this->importDir, $importDir);
181 $this->compileProp($prop, $block, $out);
184 $this->importDir = $oldImport;
185 $this->sourceParser = $oldSourceParser;
211 switch ($block->type) {
213 $this->compileRoot($block);
216 $this->compileCSSBlock($block);
219 $this->compileMedia($block);
222 $name = "@" . $block->name;
223 if (!empty($block->value)) {
224 $name .= " " . $this->compileValue($this->reduce($block->value));
227 $this->compileNestedBlock($block, array($name));
230 $block->parser->throwError("unknown block type: $block->type\n", $block->count);
236 $env = $this->pushEnv();
238 $selectors = $this->compileSelectors($block->tags);
239 $env->selectors = $this->multiplySelectors($selectors);
240 $out = $this->makeOutputBlock(null, $env->selectors);
242 $this->scope->children[] = $out;
243 $this->compileProps($block, $out);
245 $block->scope = $env; // mixins carry scope with them!
246 $this->popEnv();
251 $env = $this->pushEnv($media);
252 $parentScope = $this->mediaParent($this->scope);
254 $query = $this->compileMediaQuery($this->multiplyMedia($env));
256 $this->scope = $this->makeOutputBlock($media->type, array($query));
257 $parentScope->children[] = $this->scope;
259 $this->compileProps($media, $this->scope);
261 if (count($this->scope->lines) > 0) {
262 $orphanSelelectors = $this->findClosestSelectors();
264 $orphan = $this->makeOutputBlock(null, $orphanSelelectors);
265 $orphan->lines = $this->scope->lines;
266 array_unshift($this->scope->children, $orphan);
267 $this->scope->lines = array();
271 $this->scope = $this->scope->parent;
272 $this->popEnv();
277 while (!empty($scope->parent)) {
278 if (!empty($scope->type) && $scope->type != "media") {
281 $scope = $scope->parent;
289 $this->pushEnv($block);
290 $this->scope = $this->makeOutputBlock($block->type, $selectors);
291 $this->scope->parent->children[] = $this->scope;
293 $this->compileProps($block, $this->scope);
295 $this->scope = $this->scope->parent;
296 $this->popEnv();
301 $this->pushEnv();
302 $this->scope = $this->makeOutputBlock($root->type);
303 $this->compileProps($root, $this->scope);
304 $this->popEnv();
309 foreach ($this->sortProps($block->props) as $prop) {
310 $this->compileProp($prop, $block, $out);
312 $out->lines = $this->deduplicate($out->lines);
353 if (isset($prop[1][0]) && $prop[1][0] == $this->vPrefix) {
397 $this->compileValue($this->reduce($q[2])) . ")";
403 $parts[] = $this->compileValue($this->reduce($q));
416 implode($this->formatter->selectorSeparator, $compiledQueries);
425 !empty($env->block->type) && $env->block->type != "media"
431 if (empty($env->block->type)) {
432 return $this->multiplyMedia($env->parent, $childQueries);
436 $queries = $env->block->queries;
447 return $this->multiplyMedia($env->parent, $out);
455 $part = str_replace($this->parentSelector, $replace, $part, $c);
458 $tag = implode($this->parentSelector, $parts);
464 $env = $this->env;
467 if (isset($env->selectors)) {
468 $selectors = $env->selectors;
471 $env = $env->parent;
483 $parentSelectors = $this->findClosestSelectors();
487 $this->expandParentSelectors($s, "");
496 $count = $this->expandParentSelectors($child, $parent);
518 $out[] = trim($this->compileValue($this->reduce($value)));
536 if (!empty($block->guards)) {
538 foreach ($block->guards as $guardGroup) {
539 foreach ($guardGroup as $guard) {
540 $this->pushEnv();
541 $this->zipSetArgs($block->args, $orderedArgs, $keywordArgs);
544 if ($guard[0] == "negate") {
545 $guard = $guard[1];
549 $passed = $this->reduce($guard) == self::$TRUE;
552 $this->popEnv();
570 if (empty($block->args)) {
571 return $block->isVararg || empty($orderedArgs) && empty($keywordArgs);
574 $remainingArgs = $block->args;
577 foreach ($block->args as $arg) {
586 $i = -1; // no args
591 if (empty($orderedArgs[$i]) || !$this->eq($arg[1], $orderedArgs[$i])) {
602 $i--; // rest can be empty
607 if ($block->isVararg) {
621 if (isset($skip[$block->id]) && !isset($block->args)) {
625 if ($this->patternMatch($block, $orderedArgs, $keywordArgs)) {
637 if (isset($seen[$searchIn->id])) return null;
638 $seen[$searchIn->id] = true;
642 if (isset($searchIn->children[$name])) {
643 $blocks = $searchIn->children[$name];
645 $matches = $this->patternMatchAll($blocks, $orderedArgs, $keywordArgs, $seen);
654 $subMatches = $this->findBlocks(
672 if ($searchIn->parent === $searchIn) return null;
673 return $this->findBlocks($searchIn->parent, $path, $orderedArgs, $keywordArgs, $seen);
696 $this->throwError("Failed to assign arg " . $a[1]);
700 $value = $this->reduce($value);
701 $this->set($a[1], $value);
712 $rest = array_slice($orderedValues, count($args) - 1);
713 $this->set($last[1], $this->reduce(array("list", " ", $rest)));
717 $this->env->arguments = $assignedValues + $orderedValues;
724 $this->sourceLoc = isset($prop[-1]) ? $prop[-1] : -1;
729 if ($name[0] == $this->vPrefix) {
730 $this->set($name, $value);
732 $out->lines[] = $this->formatter->property(
734 $this->compileValue($this->reduce($value))
740 $this->compileBlock($child);
753 $orderedArgs[] = $this->reduce(array("variable", $arg[1]));
755 $keywordArgs[$arg[1]] = $this->reduce($arg[2]);
760 $orderedArgs[] = $this->reduce($arg[1]);
763 $this->throwError("Unknown arg type: " . $arg[0]);
767 $mixins = $this->findBlocks($block, $path, $orderedArgs, $keywordArgs);
770 $block->parser->throwError("{$prop[1][0]} is undefined", $block->count);
774 //Use Ruleset Logic - Only last element
784 if (isset($mixin->parent->scope)) {
786 $mixinParentEnv = $this->pushEnv();
787 $mixinParentEnv->storeParent = $mixin->parent->scope;
791 if (isset($mixin->args)) {
793 $this->pushEnv();
794 $this->zipSetArgs($mixin->args, $orderedArgs, $keywordArgs);
797 $oldParent = $mixin->parent;
798 if ($mixin != $block) $mixin->parent = $block;
800 foreach ($this->sortProps($mixin->props) as $subProp) {
805 $subProp[1][0] != $this->vPrefix
814 $this->compileProp($subProp, $mixin, $out);
817 $mixin->parent = $oldParent;
819 if ($haveArgs) $this->popEnv();
820 if ($haveScope) $this->popEnv();
825 $out->lines[] = $prop[1];
829 $out->lines[] = "@$name " . $this->compileValue($this->reduce($value)) . ';';
832 $out->lines[] = $prop[1];
836 $importPath = $this->reduce($importPath);
838 if (!isset($this->env->imports)) {
839 $this->env->imports = array();
842 $result = $this->tryImport($importPath, $block, $out);
844 $this->env->imports[$importId] = $result === false ?
845 array(false, "@import " . $this->compileValue($importPath) . ";") :
851 $import = $this->env->imports[$importId];
854 $out->lines[] = $import[1];
858 $this->compileImportedProps($bottom, $block, $out, $parser, $importDir);
863 $block->parser->throwError("unknown op: {$prop[0]}\n", $block->count);
883 // [1] - delimiter
884 // [2] - array of values
887 if (!empty($this->formatter->compressColors)) {
888 return $this->compileValue($this->coerceColor($value));
892 // [1] - the keyword
896 // [1] - the number
897 // [2] - the unit
898 if ($this->numberPrecision !== null) {
899 $num = round($num, $this->numberPrecision);
903 // [1] - contents of string (includes quotes)
907 $part = $this->compileValue($part);
912 // [1] - red component (either number or a %)
913 // [2] - green component
914 // [3] - blue component
915 // [4] - optional alpha component
916 [, $r, $g, $b] = $value;
918 $g = round($g);
922 return 'rgba(' . $r . ',' . $g . ',' . $b . ',' . $value[4] . ')';
925 $h = sprintf("#%02x%02x%02x", $r, $g, $b);
927 if (!empty($this->formatter->compressColors)) {
928 // Converting hex color to short notation (e.g. #003399 to #039)
938 return $name . '(' . $this->compileValue($args) . ')';
940 $this->throwError("unknown value type: $value[0]");
946 [$base, $exp] = $this->assertArgs($args, 2, "pow");
947 …return array("number", pow($this->assertNumber($base), $this->assertNumber($exp)), $args[2][0][2]);
957 [$a, $b] = $this->assertArgs($args, 2, "mod");
958 return array("number", $this->assertNumber($a) % $this->assertNumber($b), $args[2][0][2]);
963 [$value, $to] = $this->assertArgs($args, 2, "convert");
969 return $this->convert($value, $to);
974 return array("number", abs($this->assertNumber($num)), $num[2]);
979 $values = $this->assertMinArgs($args, 1, "min");
987 $converted = $this->convert($values[$a], $first_format);
1000 $values = $this->assertMinArgs($args, 1, "max");
1008 $converted = $this->convert($values[$a], $first_format);
1021 return tan($this->assertNumber($num));
1026 return sin($this->assertNumber($num));
1031 return cos($this->assertNumber($num));
1036 $num = atan($this->assertNumber($num));
1042 $num = asin($this->assertNumber($num));
1048 $num = acos($this->assertNumber($num));
1054 return sqrt($this->assertNumber($num));
1059 [$list, $idx] = $this->assertArgs($value, 2, "extract");
1060 $idx = $this->assertNumber($idx);
1062 if ($list[0] == "list" && isset($list[2][$idx - 1])) {
1063 return $list[2][$idx - 1];
1069 return $this->toBool($value[0] == "number");
1074 return $this->toBool($value[0] == "string");
1079 return $this->toBool($this->coerceColor($value));
1084 return $this->toBool($value[0] == "keyword");
1089 return $this->toBool($value[0] == "number" && $value[2] == "px");
1094 return $this->toBool($value[0] == "number" && $value[2] == "%");
1099 return $this->toBool($value[0] == "number" && $value[2] == "em");
1104 return $this->toBool($value[0] == "number" && $value[2] == "rem");
1109 $color = $this->coerceColor($color);
1111 $this->throwError("color expected for rgbahex");
1124 return $this->lib_rgbahex($color);
1128 * Given an url, decide whether to output a regular link or the base64-encoded contents of the file
1131 * @return string formatted url(), either as a link or base64-encoded
1138 $fullpath = $this->findImport($url);
1146 $mime = explode('; ', $finfo->file($fullpath));
1168 return $this->lib_e($items[0]);
1170 $this->throwError("unrecognised input");
1177 return array("keyword", $this->compileValue($arg));
1186 $template = $this->compileValue($this->lib_e($string));
1192 $this->reduce($values[$i]) : array('keyword', '');
1195 if ($color = $this->coerceColor($val)) {
1200 $rep = $this->compileValue($this->lib_e($val));
1216 $value = $this->assertNumber($arg);
1222 $value = $this->assertNumber($arg);
1229 $value = $this->assertNumber($arg);
1232 $value = $this->assertNumber($arg[2][0]);
1233 $precision = $this->assertNumber($arg[2][1]);
1244 $this->assertNumber($number),
1245 $this->compileValue($this->lib_e($newUnit))
1248 return array("number", $this->assertNumber($arg), "");
1262 $color = $this->assertColor($color);
1270 [$color, $delta] = $this->colorArgs($args);
1272 $hsl = $this->toHSL($color);
1273 $hsl[3] = $this->clamp($hsl[3] - $delta, 100);
1274 return $this->toRGB($hsl);
1279 [$color, $delta] = $this->colorArgs($args);
1281 $hsl = $this->toHSL($color);
1282 $hsl[3] = $this->clamp($hsl[3] + $delta, 100);
1283 return $this->toRGB($hsl);
1288 [$color, $delta] = $this->colorArgs($args);
1290 $hsl = $this->toHSL($color);
1291 $hsl[2] = $this->clamp($hsl[2] + $delta, 100);
1292 return $this->toRGB($hsl);
1297 [$color, $delta] = $this->colorArgs($args);
1299 $hsl = $this->toHSL($color);
1300 $hsl[2] = $this->clamp($hsl[2] - $delta, 100);
1301 return $this->toRGB($hsl);
1306 [$color, $delta] = $this->colorArgs($args);
1308 $hsl = $this->toHSL($color);
1313 return $this->toRGB($hsl);
1318 [$color, $delta] = $this->colorArgs($args);
1319 $color[4] = $this->clamp((isset($color[4]) ? $color[4] : 1) - $delta / 100);
1325 [$color, $delta] = $this->colorArgs($args);
1326 $color[4] = $this->clamp((isset($color[4]) ? $color[4] : 1) + $delta / 100);
1332 $hsl = $this->toHSL($this->assertColor($color));
1338 $hsl = $this->toHSL($this->assertColor($color));
1344 $hsl = $this->toHSL($this->assertColor($color));
1349 // defaults to 1 for non-colors or colors without an alpha
1352 if (!is_null($color = $this->coerceColor($value))) {
1360 [$color, $alpha] = $this->colorArgs($args);
1361 $color[4] = $this->clamp($alpha / 100.0);
1367 $num = $this->assertNumber($arg);
1373 // http://sass-lang.com/docs/yardoc/Sass/Script/Functions.html#mix-instance_method
1377 $this->throwError("mix expects (color1, color2, weight)");
1380 $first = $this->assertColor($first);
1381 $second = $this->assertColor($second);
1383 $first_a = $this->lib_alpha($first);
1384 $second_a = $this->lib_alpha($second);
1392 $w = $weight * 2 - 1;
1393 $a = $first_a - $second_a;
1395 $w1 = (($w * $a == -1 ? $w : ($w + $a) / (1 + $w * $a)) + 1) / 2.0;
1396 $w2 = 1.0 - $w1;
1406 $new[] = $first_a * $weight + $second_a * ($weight - 1);
1409 return $this->fixColor($new);
1419 $inputColor = (isset($args[2][0])) ? $this->assertColor($args[2][0]) : $lightColor;
1420 $darkColor = (isset($args[2][1])) ? $this->assertColor($args[2][1]) : $darkColor;
1421 $lightColor = (isset($args[2][2])) ? $this->assertColor($args[2][2]) : $lightColor;
1427 $threshold = $this->assertNumber($args[2][3]);
1430 $inputColor = $this->assertColor($args);
1433 $inputColor = $this->coerceColor($inputColor);
1434 $darkColor = $this->coerceColor($darkColor);
1435 $lightColor = $this->coerceColor($lightColor);
1438 if ($this->lib_luma($darkColor) > $this->lib_luma($lightColor)) {
1444 $inputColor_alpha = $this->lib_alpha($inputColor);
1445 if (($this->lib_luma($inputColor) * $inputColor_alpha) < $threshold) {
1453 $color = $this->coerceColor($color);
1460 $color = $this->coerceColor($value);
1461 if (is_null($color)) $this->throwError($error);
1468 $this->throwError($error);
1476 if ($value[0] !== "list" || $value[1] != ",") $this->throwError("expecting list");
1484 $this->throwError("{$name}expecting $expectedArgs arguments, got $numValues");
1493 if ($value[0] !== "list" || $value[1] != ",") $this->throwError("expecting list");
1501 $this->throwError("{$name}expecting at least $expectedMinArgs arguments, got $numValues");
1512 $g = $color[2] / 255;
1515 $min = min($r, $g, $b);
1516 $max = max($r, $g, $b);
1523 $S = ($max - $min) / ($max + $min);
1525 $S = ($max - $min) / (2.0 - $max - $min);
1527 if ($r == $max) $H = ($g - $b) / ($max - $min);
1528 elseif ($g == $max) $H = 2.0 + ($b - $r) / ($max - $min);
1529 elseif ($b == $max) $H = 4.0 + ($r - $g) / ($max - $min);
1546 elseif ($comp > 1) $comp -= 1.0;
1548 if (6 * $comp < 1) return $temp1 + ($temp2 - $temp1) * 6 * $comp;
1550 if (3 * $comp < 2) return $temp1 + ($temp2 - $temp1) * ((2 / 3) - $comp) * 6;
1568 $r = $g = $b = $L;
1572 $L + $S - $L * $S;
1574 $temp1 = 2.0 * $L - $temp2;
1576 $r = $this->toRGB_helper($H + 1 / 3, $temp1, $temp2);
1577 $g = $this->toRGB_helper($H, $temp1, $temp2);
1578 $b = $this->toRGB_helper($H - 1 / 3, $temp1, $temp2);
1581 // $out = array('color', round($r*255), round($g*255), round($b*255));
1582 $out = array('color', $r * 255, $g * 255, $b * 255);
1606 $val = $this->reduce($c);
1613 $hsl[] = $this->clamp($val, $clamp);
1618 return $this->toRGB($hsl);
1623 $c = $this->reduce($c);
1642 return $this->fixColor($components);
1652 $reduced = $this->reduce($value[1]);
1653 $var = $this->compileValue($reduced);
1654 $res = $this->reduce(array("variable", $this->vPrefix . $var));
1657 $res = $this->coerceColor($res);
1660 if (empty($value[2])) $res = $this->lib_e($res);
1666 $key = $this->reduce($key);
1667 $key = $this->vPrefix . $this->compileValue($this->lib_e($key));
1670 $seen = &$this->env->seenNames;
1673 $this->throwError("infinite loop detected: $key");
1677 $out = $this->reduce($this->get($key));
1682 $item = $this->reduce($item, $forExpression);
1686 return $this->evaluate($value);
1691 $part = $this->reduce($part);
1692 if ($strip) $part = $this->lib_e($part);
1698 return $this->lib_e($this->reduce($inner));
1700 $color = $this->funcToColor($value);
1706 $f = isset($this->libFunctions[$name]) ?
1707 $this->libFunctions[$name] : array($this, 'lib_' . str_replace('-', '_', $name));
1713 $ret = call_user_func($f, $this->reduce($args, true), $this);
1732 $value[2] = $this->reduce($value[2]);
1736 $exp = $this->reduce($exp);
1742 case "-":
1743 $exp[1] *= -1;
1753 if ($color = $this->coerceColor($value)) {
1758 return $this->coerceColor($value);
1778 for ($i = 3; $i > 0; $i--) { // 3 2 1
1816 return $this->flattenList($value[2][0]);
1832 $left = $this->reduce($left, true);
1833 $right = $this->reduce($right, true);
1835 if ($leftColor = $this->coerceColor($left)) {
1839 if ($rightColor = $this->coerceColor($right)) {
1848 return $this->toBool($left == self::$TRUE && $right == self::$TRUE);
1852 return $this->toBool($this->eq($left, $right));
1855 if ($op == "+" && !is_null($str = $this->stringConcatenate($left, $right))) {
1862 $out = $this->$fname($op, $left, $right);
1876 if ($strLeft = $this->coerceString($left)) {
1884 if ($strRight = $this->coerceString($right)) {
1892 $value = $this->assertNumber($number);
1960 $this->throwError("Cannot convert {$from} to {$to}");
1977 return $this->op_color_number($op, $rgt, $lft);
1985 return $this->op_color_color(
1988 array_fill(1, count($lft) - 1, $rgt[1])
1996 foreach (range(1, $max - 1) as $i) {
2003 case '-':
2004 $out[] = $lval - $rval;
2013 if ($rval == 0) $this->throwError("evaluate error: can't divide by zero");
2017 $this->throwError('evaluate error: color op number failed on op ' . $op);
2020 return $this->fixColor($out);
2025 $color = $this->coerceColor($color);
2027 $this->throwError('color expected for red()');
2035 $color = $this->coerceColor($color);
2037 $this->throwError('color expected for green()');
2045 $color = $this->coerceColor($color);
2047 $this->throwError('color expected for blue()');
2067 case '-':
2068 $value = $left[1] - $right[1];
2074 if ($right[1] == 0) $this->throwError('parse error: divide by zero');
2078 return $this->toBool($left[1] < $right[1]);
2080 return $this->toBool($left[1] > $right[1]);
2082 return $this->toBool($left[1] >= $right[1]);
2084 return $this->toBool($left[1] <= $right[1]);
2086 $this->throwError('parse error: unknown number operator: ' . $op);
2098 $b->lines = array();
2099 $b->children = array();
2100 $b->selectors = $selectors;
2101 $b->type = $type;
2102 $b->parent = $this->scope;
2110 $e->parent = $this->env;
2111 $e->store = array();
2112 $e->block = $block;
2114 $this->env = $e;
2121 $old = $this->env;
2122 $this->env = $this->env->parent;
2129 $this->env->store[$name] = $value;
2136 $current = $this->env;
2141 $isArguments = $name == $this->vPrefix . 'arguments';
2143 if ($isArguments && isset($current->arguments)) {
2144 return array('list', ' ', $current->arguments);
2147 if (isset($current->store[$name]))
2148 return $current->store[$name];
2150 if (isset($current->storeParent))
2151 $scope_secondary[] = $current->storeParent;
2153 if (isset($current->parent))
2154 $current = $current->parent;
2163 if ($isArguments && isset($current->arguments)) {
2164 return array('list', ' ', $current->arguments);
2167 if (isset($current->store[$name])) {
2168 return $current->store[$name];
2172 if (isset($current->storeParent)) {
2173 $scope_secondary[] = $current->storeParent;
2176 if (isset($current->parent)) {
2177 $current = $current->parent;
2184 $this->throwError("variable $name is undefined");
2190 $this->pushEnv();
2194 $parser->count = 0;
2195 $parser->buffer = (string)$strValue;
2196 if (!$parser->propertyValue($value)) {
2200 $this->set($name, $value);
2212 $this->_parseFile = $fname;
2221 $this->parser = $this->makeParser($name);
2222 $root = $this->parser->parse($string);
2224 $this->env = null;
2225 $this->scope = null;
2226 $this->allParsedFiles = array();
2228 $this->formatter = $this->newFormatter();
2230 if (!empty($this->registeredVars)) {
2231 $this->injectVariables($this->registeredVars);
2234 $this->sourceParser = $this->parser; // used for error messages
2235 $this->compileBlock($root);
2238 $this->formatter->block($this->scope);
2252 $oldImport = $this->importDir;
2254 $this->importDir = (array)$this->importDir;
2255 $this->importDir[] = $pi['dirname'] . '/';
2257 $this->addParsedFile($fname);
2259 $out = $this->compile(file_get_contents($fname), $fname);
2261 $this->importDir = $oldImport;
2294 $output = $this->cachedCompile($metadata ? $metadata : $in);
2312 $this->compileFile($in, $out);
2331 * The cache structure is a plain-ol' PHP associative array and can
2371 $out['compiled'] = $this->compileFile($root);
2372 $out['files'] = $this->allParsedFiles();
2391 $oldVars = $this->registeredVars;
2393 $this->setVariables($initialVariables);
2397 if (empty($this->_parseFile)) {
2401 $out = $this->compileFile($this->_parseFile);
2403 $out = $this->compile($str);
2406 $this->registeredVars = $oldVars;
2413 $parser->writeComments = $this->preserveComments;
2420 $this->formatterName = $name;
2426 if (!empty($this->formatterName)) {
2427 if (!is_string($this->formatterName))
2428 return $this->formatterName;
2429 $className = "lessc_formatter_$this->formatterName";
2437 $this->preserveComments = $preserve;
2442 $this->libFunctions[$name] = $func;
2447 unset($this->libFunctions[$name]);
2452 $this->registeredVars = array_merge($this->registeredVars, $variables);
2457 unset($this->registeredVars[$name]);
2462 $this->importDir = (array)$dirs;
2467 $this->importDir = (array)$this->importDir;
2468 $this->importDir[] = $dir;
2473 return $this->allParsedFiles;
2478 $this->allParsedFiles[realpath($file)] = filemtime($file);
2482 * Uses the current value of $this->count to show line and line number
2486 if ($this->sourceLoc >= 0) {
2487 $this->sourceParser->throwError($msg, $this->sourceLoc);
2499 return $less->checkedCompile($in, $out);
2507 return $less->cachedCompile($in, $force);
2676 '-' => 1,
2694 array('/border-radius$/i', '/^font$/i');
2696 …blockDirectives = array("font-face", "keyframes", "page", "-moz-document", "viewport", "-moz-viewp…
2705 * property1: 10 -5; // is two numbers, 10 and -5
2706 * property2: (10 -5); // should evaluate to 5
2727 $this->eatWhiteDefault = true;
2729 $this->lessc = $lessc;
2731 $this->sourceName = $sourceName; // name used for error messages
2733 $this->writeComments = false;
2753 $this->count = 0;
2754 $this->line = 1;
2756 $this->env = null; // block stack
2757 $this->buffer = $this->writeComments ? $buffer : $this->removeComments($buffer);
2758 $this->pushSpecialBlock("root");
2759 $this->eatWhiteDefault = true;
2760 $this->seenComments = array();
2763 // if (preg_match('/^\s+/', $this->buffer, $m)) {
2764 // $this->line += substr_count($m[0], "\n");
2765 // $this->buffer = ltrim($this->buffer);
2767 $this->whitespace();
2770 while (false !== $this->parseChunk());
2772 if ($this->count != strlen($this->buffer))
2773 $this->throwError();
2776 if (!property_exists($this->env, 'parent') || !is_null($this->env->parent))
2779 return $this->env;
2814 * Before parsing a chain, use $s = $this->seek() to remember the current
2815 * position into $s. Then if a chain fails, use $this->seek($s) to
2820 if (empty($this->buffer)) return false;
2821 $s = $this->seek();
2823 if ($this->whitespace()) {
2829 $this->keyword($key) && $this->assign() &&
2830 $this->propertyValue($value, $key) && $this->end()
2832 $this->append(array('assign', $key, $value), $s);
2835 $this->seek($s);
2840 if ($this->literal('@', false)) {
2841 $this->count--;
2844 if ($this->literal('@media')) {
2845 if (($this->mediaQueryList($mediaQueries) || true)
2846 && $this->literal('{')
2848 $media = $this->pushSpecialBlock("media");
2849 $media->queries = is_null($mediaQueries) ? array() : $mediaQueries;
2852 $this->seek($s);
2857 if ($this->literal("@", false) && $this->keyword($dirName)) {
2858 if ($this->isDirective($dirName, $this->blockDirectives)) {
2859 if (($this->openString("{", $dirValue, null, array(";")) || true) &&
2860 $this->literal("{")
2862 $dir = $this->pushSpecialBlock("directive");
2863 $dir->name = $dirName;
2864 if (isset($dirValue)) $dir->value = $dirValue;
2867 } elseif ($this->isDirective($dirName, $this->lineDirectives)) {
2868 if ($this->propertyValue($dirValue) && $this->end()) {
2869 $this->append(array("directive", $dirName, $dirValue));
2872 } elseif ($this->literal(":", true)) {
2874 if (($this->openString("{", $dirValue, null, array(";")) || true) &&
2875 $this->literal("{")
2877 $dir = $this->pushBlock($this->fixTags(array("@" . $dirName)));
2878 $dir->name = $dirName;
2879 if (isset($dirValue)) $dir->value = $dirValue;
2885 $this->seek($s);
2890 $this->variable($var) && $this->assign() &&
2891 $this->propertyValue($value) && $this->end()
2893 $this->append(array('assign', $var, $value), $s);
2896 $this->seek($s);
2899 if ($this->import($importValue)) {
2900 $this->append($importValue, $s);
2906 $this->tag($tag, true) && $this->argumentDef($args, $isVararg) &&
2907 ($this->guards($guards) || true) &&
2908 $this->literal('{')
2910 $block = $this->pushBlock($this->fixTags(array($tag)));
2911 $block->args = $args;
2912 $block->isVararg = $isVararg;
2913 if (!empty($guards)) $block->guards = $guards;
2916 $this->seek($s);
2920 if ($this->tags($tags) && $this->literal('{', false)) {
2921 $tags = $this->fixTags($tags);
2922 $this->pushBlock($tags);
2925 $this->seek($s);
2929 if ($this->literal('}', false)) {
2931 $block = $this->pop();
2933 $this->seek($s);
2934 $this->throwError($e->getMessage());
2938 if (is_null($block->type)) {
2940 if (!isset($block->args)) {
2941 foreach ($block->tags as $tag) {
2942 if (!is_string($tag) || $tag[0] != $this->lessc->mPrefix) {
2949 foreach ($block->tags as $tag) {
2951 $this->env->children[$tag][] = $block;
2957 $this->append(array('block', $block), $s);
2962 $this->whitespace();
2968 $this->mixinTags($tags) &&
2969 ($this->argumentDef($argv, $isVararg) || true) &&
2970 ($this->keyword($suffix) || true) && $this->end()
2972 $tags = $this->fixTags($tags);
2973 $this->append(array('mixin', $tags, $argv, $suffix), $s);
2976 $this->seek($s);
2980 if ($this->literal(';')) return true;
2992 $pattern = '/^(-[a-z-]+-)?(' . $pattern . ')$/i';
3001 if ($tag[0] == $this->lessc->vPrefix)
3002 $tag[0] = $this->lessc->mPrefix;
3012 while ($this->expression($exp)) {
3024 * @link http://en.wikipedia.org/wiki/Operator-precedence_parser#Pseudo-code
3028 if ($this->value($lhs)) {
3029 $out = $this->expHelper($lhs, 0);
3032 if (!empty($this->env->supressedDivision)) {
3033 unset($this->env->supressedDivision);
3034 $s = $this->seek();
3035 if ($this->literal("/") && $this->value($rhs)) {
3042 $this->seek($s);
3056 $this->inExp = true;
3057 $ss = $this->seek();
3060 $whiteBefore = isset($this->buffer[$this->count - 1]) &&
3061 ctype_space($this->buffer[$this->count - 1]);
3065 $needWhite = $whiteBefore && !$this->inParens;
3067 …if ($this->match(self::$operatorString . ($needWhite ? '\s' : ''), $m) && self::$precedence[$m[1]]…
3068 …if (!$this->inParens && isset($this->env->currentProperty) && $m[1] == "/" && empty($this->env->su…
3070 if (preg_match($pattern, $this->env->currentProperty)) {
3071 $this->env->supressedDivision = true;
3078 $whiteAfter = isset($this->buffer[$this->count - 1]) &&
3079 ctype_space($this->buffer[$this->count - 1]);
3081 if (!$this->value($rhs)) break;
3084 …if ($this->peek(self::$operatorString, $next) && self::$precedence[$next[1]] > self::$precedence[$…
3085 $rhs = $this->expHelper($rhs, self::$precedence[$next[1]]);
3089 $ss = $this->seek();
3097 $this->seek($ss);
3107 if ($keyName !== null) $this->env->currentProperty = $keyName;
3110 while ($this->expressionList($v)) {
3112 $s = $this->seek();
3113 if (!$this->literal(',')) break;
3116 if ($s) $this->seek($s);
3118 if ($keyName !== null) unset($this->env->currentProperty);
3128 $s = $this->seek();
3131 if (isset($this->buffer[$this->count]) && $this->buffer[$this->count] != "(") {
3135 $inParens = $this->inParens;
3137 $this->literal("(") &&
3138 ($this->inParens = true) && $this->expression($exp) &&
3139 $this->literal(")")
3142 $this->inParens = $inParens;
3145 $this->inParens = $inParens;
3146 $this->seek($s);
3155 $s = $this->seek();
3158 if (isset($this->buffer[$this->count]) && $this->buffer[$this->count] == "-") {
3161 $this->literal("-", false) &&
3162 (($this->variable($inner) && $inner = array("variable", $inner)) ||
3163 $this->unit($inner) ||
3164 $this->parenValue($inner))
3166 $value = array("unary", "-", $inner);
3169 $this->seek($s);
3173 if ($this->parenValue($value)) return true;
3174 if ($this->unit($value)) return true;
3175 if ($this->color($value)) return true;
3176 if ($this->func($value)) return true;
3177 if ($this->stringValue($value)) return true;
3179 if ($this->keyword($word)) {
3185 if ($this->variable($var)) {
3191 if ($this->literal("~") && $this->stringValue($str)) {
3195 $this->seek($s);
3199 if ($this->literal('\\') && $this->match('([0-9]+)', $m)) {
3203 $this->seek($s);
3212 if (!$this->literal('@import')) return false;
3218 if ($this->propertyValue($value)) {
3226 if ($this->genericList($list, "mediaQuery", ",", false)) {
3235 $s = $this->seek();
3240 …if (($this->literal("only") && ($only = true) || $this->literal("not") && ($not = true) || true) &…
3247 $this->seek($s);
3251 if (!empty($mediaType) && !$this->literal("and")) {
3254 $this->genericList($expressions, "mediaExpression", "and", false);
3259 $this->seek($s);
3269 $s = $this->seek();
3272 $this->literal("(") &&
3273 $this->keyword($feature) &&
3274 ($this->literal(":") && $this->expression($value) || true) &&
3275 $this->literal(")")
3280 } elseif ($this->variable($variable)) {
3285 $this->seek($s);
3292 $oldWhite = $this->eatWhiteDefault;
3293 $this->eatWhiteDefault = false;
3308 while ($this->match($patt, $m, false)) {
3318 $this->count -= strlen($tok);
3323 $nestingLevel--;
3327 if (($tok == "'" || $tok == '"') && $this->stringValue($str)) {
3332 if ($tok == "@{" && $this->interpolation($inter)) {
3342 $this->count += strlen($tok);
3345 $this->eatWhiteDefault = $oldWhite;
3351 $content[count($content) - 1] = rtrim(end($content));
3360 $s = $this->seek();
3361 if ($this->literal('"', false)) {
3363 } elseif ($this->literal("'", false)) {
3375 $oldWhite = $this->eatWhiteDefault;
3376 $this->eatWhiteDefault = false;
3378 while ($this->match($patt, $m, false)) {
3381 $this->count -= strlen($m[2]);
3382 if ($this->interpolation($inter, false)) {
3385 $this->count += strlen($m[2]);
3390 if ($this->literal($delim, false)) {
3394 $this->count -= strlen($delim);
3399 $this->eatWhiteDefault = $oldWhite;
3401 if ($this->literal($delim)) {
3406 $this->seek($s);
3412 $oldWhite = $this->eatWhiteDefault;
3413 $this->eatWhiteDefault = true;
3415 $s = $this->seek();
3417 $this->literal("@{") &&
3418 $this->openString("}", $interp, null, array("'", '"', ";")) &&
3419 $this->literal("}", false)
3422 $this->eatWhiteDefault = $oldWhite;
3423 if ($this->eatWhiteDefault) $this->whitespace();
3427 $this->eatWhiteDefault = $oldWhite;
3428 $this->seek($s);
3435 if (isset($this->buffer[$this->count])) {
3436 $char = $this->buffer[$this->count];
3440 if ($this->match('([0-9]+(?:\.[0-9]*)?|\.[0-9]+)([%a-zA-Z]+)?', $m)) {
3450 if ($this->match('(#(?:[0-9a-f]{8}|[0-9a-f]{6}|[0-9a-f]{3}))', $m)) {
3469 $s = $this->seek();
3470 if (!$this->literal('(')) return false;
3478 if ($this->literal("...")) {
3483 if ($this->$method($value)) {
3486 $ss = $this->seek();
3488 if ($this->assign() && $this->$method($rhs)) {
3491 $this->seek($ss);
3492 if ($this->literal("...")) {
3507 if (!$this->literal($delim)) {
3508 if ($delim == "," && $this->literal(";")) {
3520 $this->throwError("Cannot mix ; and , as delimiter types");
3528 $this->throwError("Unexpected rest before semicolon");
3555 if (!$this->literal(')')) {
3556 $this->seek($s);
3570 while ($this->tag($tt, $simple)) {
3572 if (!$this->literal($delim)) break;
3584 while ($this->tag($tt, true)) {
3586 $this->literal(">");
3598 if (isset($this->buffer[$this->count]) && $this->buffer[$this->count] != "[") {
3602 $s = $this->seek();
3606 if ($this->literal("[", false)) {
3610 if ($this->literal("]", false)) {
3611 $this->count--;
3615 if ($this->match('\s+', $m)) {
3619 if ($this->stringValue($str)) {
3623 $chunk = str_replace($this->lessc->parentSelector, "$&$", $chunk);
3632 if ($this->keyword($word)) {
3637 if ($this->interpolation($inter, false)) {
3644 if ($this->match('[|-~\$\*\^=]+', $m)) {
3652 if ($this->literal("]", false)) {
3660 $this->seek($s);
3663 $this->seek($s);
3675 $s = $this->seek();
3679 while ($this->tagBracket($parts, $hasExpression));
3681 $oldWhite = $this->eatWhiteDefault;
3682 $this->eatWhiteDefault = false;
3685 if ($this->match('([' . $chars . '0-9][' . $chars . ']*)', $m)) {
3689 while ($this->tagBracket($parts, $hasExpression));
3693 if (isset($this->buffer[$this->count]) && $this->buffer[$this->count] == "@") {
3694 if ($this->interpolation($interp)) {
3701 if ($this->literal("@")) {
3707 if ($this->unit($unit)) { // for keyframes
3716 $this->eatWhiteDefault = $oldWhite;
3718 $this->seek($s);
3728 $this->whitespace();
3735 $s = $this->seek();
3737 if ($this->match('(%|[\w\-_][\w\-_:\.]+|[\w_])', $m) && $this->literal('(')) {
3740 $sPreArgs = $this->seek();
3744 $ss = $this->seek();
3746 if ($this->keyword($name) && $this->literal('=') && $this->expressionList($value)) {
3749 $this->seek($ss);
3750 if ($this->expressionList($value)) {
3755 if (!$this->literal(',')) break;
3759 if ($this->literal(')')) {
3764 $this->seek($sPreArgs);
3765 if ($this->openString(")", $string) && $this->literal(")")) {
3772 $this->seek($s);
3779 $s = $this->seek();
3781 $this->literal($this->lessc->vPrefix, false) &&
3782 ($this->variable($sub) || $this->keyword($name))
3787 $name = $this->lessc->vPrefix . $name;
3793 $this->seek($s);
3803 if ($name) $this->currentProperty = $name;
3804 return $this->literal(':') || $this->literal('=');
3810 if ($this->match('([\w_\-\*!"][\w\-_"]*)', $m)) {
3820 if ($this->literal(';', false)) {
3822 } elseif ($this->count == strlen($this->buffer) || $this->buffer[$this->count] == '}') {
3831 $s = $this->seek();
3833 if (!$this->literal("when")) {
3834 $this->seek($s);
3840 while ($this->guardGroup($g)) {
3841 $guards[] = $g;
3842 if (!$this->literal(",")) break;
3847 $this->seek($s);
3858 $s = $this->seek();
3860 while ($this->guard($guard)) {
3861 $guardGroup[] = $guard;
3862 if (!$this->literal("and")) break;
3867 $this->seek($s);
3874 protected function guard(&$guard) function in lessc_parser
3876 $s = $this->seek();
3877 $negate = $this->literal("not");
3879 if ($this->literal("(") && $this->expression($exp) && $this->literal(")")) {
3880 $guard = $exp;
3881 if ($negate) $guard = array("negate", $guard);
3885 $this->seek($s);
3893 if ($eatWhitespace === null) $eatWhitespace = $this->eatWhiteDefault;
3896 if (!isset($what[1]) && isset($this->buffer[$this->count])) {
3897 if ($this->buffer[$this->count] == $what) {
3899 $this->count++;
3912 return $this->match(self::$literalCache[$what], $m, $eatWhitespace);
3917 $s = $this->seek();
3919 while ($this->$parseItem($value)) {
3922 if (!$this->literal($delim)) break;
3927 $this->seek($s);
3942 // $until - don't include $what in advance
3951 …if (!$this->match('(' . $validChars . '*?)' . lessc::preg_quote($what), $m, !$until)) return false;
3952 if ($until) $this->count -= strlen($what); // give back $what
3960 if ($eatWhitespace === null) $eatWhitespace = $this->eatWhiteDefault;
3962 $r = '/' . $regex . ($eatWhitespace && !$this->writeComments ? '\s*' : '') . '/Ais';
3963 if (preg_match($r, $this->buffer, $out, 0, $this->count)) {
3964 $this->count += strlen($out[0]);
3965 if ($eatWhitespace && $this->writeComments) $this->whitespace();
3974 if ($this->writeComments) {
3976 while (preg_match(self::$whitePattern, $this->buffer, $m, 0, $this->count)) {
3977 if (isset($m[1]) && empty($this->seenComments[$this->count])) {
3978 $this->append(array("comment", $m[1]));
3979 $this->seenComments[$this->count] = true;
3981 $this->count += strlen($m[0]);
3986 $this->match("", $m);
3994 if (is_null($from)) $from = $this->count;
3996 $result = preg_match($r, $this->buffer, $out, 0, $from);
4004 if ($where === null) return $this->count;
4005 else $this->count = $where;
4013 $count = is_null($count) ? $this->count : $count;
4015 $line = $this->line +
4016 substr_count(substr($this->buffer, 0, $count), "\n");
4018 if (!empty($this->sourceName)) {
4019 $loc = "$this->sourceName on line $line";
4024 // TODO this depends on $this->count
4025 if ($this->peek("(.*?)(\n|$)", $m, $count)) {
4035 $b->parent = $this->env;
4037 $b->type = $type;
4038 $b->id = self::$nextBlockId++;
4040 $b->isVararg = false; // TODO: kill me from here
4041 $b->tags = $selectors;
4043 $b->props = array();
4044 $b->children = array();
4049 $b->parser = $this;
4052 $b->count = $this->count;
4054 $this->env = $b;
4061 return $this->pushBlock(null, $type);
4067 if ($pos !== null) $prop[-1] = $pos;
4068 $this->env->props[] = $prop;
4074 $old = $this->env;
4075 $this->env = $this->env->parent;
4110 $count += strlen($m[0]) - strlen($min[0]);
4115 $count += strlen($m[0]) - 1;
4119 if ($skip === false) $skip = strlen($text) - $count;
4120 else $skip -= $count;
4162 $this->indentLevel = 0;
4167 return str_repeat($this->indentChar, max($this->indentLevel + $n, 0));
4172 return $name . $this->assignSeparator . $value . ";";
4177 if (empty($block->lines)) {
4178 foreach ($block->children as $child) {
4179 if (!$this->isEmpty($child)) return false;
4189 if ($this->isEmpty($block)) return;
4191 $inner = $pre = $this->indentStr();
4193 $isSingle = !$this->disableSingle &&
4194 is_null($block->type) && count($block->lines) == 1;
4196 if (!empty($block->selectors)) {
4197 $this->indentLevel++;
4199 if ($this->breakSelectors) {
4200 $selectorSeparator = $this->selectorSeparator . $this->break . $pre;
4202 $selectorSeparator = $this->selectorSeparator;
4206 implode($selectorSeparator, $block->selectors);
4208 echo $this->openSingle;
4211 echo $this->open . $this->break;
4212 $inner = $this->indentStr();
4216 if (!empty($block->lines)) {
4217 $glue = $this->break . $inner;
4218 echo $inner . implode($glue, $block->lines);
4219 if (!$isSingle && !empty($block->children)) {
4220 echo $this->break;
4224 foreach ($block->children as $child) {
4225 $this->block($child);
4228 if (!empty($block->selectors)) {
4229 if (!$isSingle && empty($block->children)) echo $this->break;
4232 echo $this->closeSingle . $this->break;
4234 echo $pre . $this->close . $this->break;
4237 $this->indentLevel--;