Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 32 additions & 6 deletions lessc.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ class lessc {

protected $allParsedFiles = array();

// formatter name or object, assigned by setFormatter()
public $formatterName;

// file set by the deprecated constructor path, used by parse()
public $_parseFile;

// compile state, assigned in compile()
public $parser;
public $env;
public $scope;
public $formatter;
Comment thread
Copilot marked this conversation as resolved.
Resolved
// set to the parser that generated the current line when compiling
// so we know how to create error messages
protected $sourceParser = null;
Expand Down Expand Up @@ -1363,7 +1374,7 @@ public function assertArgs($value, $expectedArgs, $name="") {
$name = $name . ": ";
}

$this->throwError("${name}expecting $expectedArgs arguments, got $numValues");
$this->throwError("{$name}expecting $expectedArgs arguments, got $numValues");
}

return $values;
Expand Down Expand Up @@ -1669,7 +1680,7 @@ protected function coerceColor($value) {
$width = strlen($colorStr) == 3 ? 16 : 256;

for ($i = 3; $i > 0; $i--) { // 3 2 1
$t = $num % $width;
$t = (int)$num % $width;
$num /= $width;

$c[$i] = $t * (256/$width) + $t * floor(16/$width);
Expand Down Expand Up @@ -1745,7 +1756,7 @@ protected function evaluate($exp) {
}

// type based operators
$fname = "op_${ltype}_${rtype}";
$fname = "op_{$ltype}_{$rtype}";
if (is_callable(array($this, $fname))) {
$out = $this->$fname($op, $left, $right);
if (!is_null($out)) return $out;
Expand Down Expand Up @@ -2422,6 +2433,19 @@ class lessc_parser {
*/
protected $inParens = false;

// state assigned in the constructor / during parsing
public $eatWhiteDefault;
public $lessc;
public $sourceName;
public $writeComments;
public $seenComments;
public $line;
public $inExp;
public $env;
public $count;
public $buffer;
Comment thread
Copilot marked this conversation as resolved.
Resolved
public $currentProperty;

// caches preg escaped literals
static protected $literalCache = array();

Expand Down Expand Up @@ -3605,7 +3629,7 @@ protected function match($regex, &$out, $eatWhitespace = null) {
if ($eatWhitespace === null) $eatWhitespace = $this->eatWhiteDefault;

$r = '/'.$regex.($eatWhitespace && !$this->writeComments ? '\s*' : '').'/Ais';
if (preg_match($r, $this->buffer, $out, null, $this->count)) {
if (preg_match($r, $this->buffer, $out, 0, $this->count)) {
$this->count += strlen($out[0]);
if ($eatWhitespace && $this->writeComments) $this->whitespace();
return true;
Expand All @@ -3617,7 +3641,7 @@ protected function match($regex, &$out, $eatWhitespace = null) {
protected function whitespace() {
if ($this->writeComments) {
$gotWhite = false;
while (preg_match(self::$whitePattern, $this->buffer, $m, null, $this->count)) {
while (preg_match(self::$whitePattern, $this->buffer, $m, 0, $this->count)) {
if (isset($m[1]) && empty($this->seenComments[$this->count])) {
$this->append(array("comment", $m[1]));
$this->seenComments[$this->count] = true;
Expand All @@ -3636,7 +3660,7 @@ protected function whitespace() {
protected function peek($regex, &$out = null, $from=null) {
if (is_null($from)) $from = $this->count;
$r = '/'.$regex.'/Ais';
$result = preg_match($r, $this->buffer, $out, null, $from);
$result = preg_match($r, $this->buffer, $out, 0, $from);

return $result;
}
Expand Down Expand Up @@ -3781,6 +3805,8 @@ class lessc_formatter_classic {

public $compressColors = false;

public $indentLevel;

public function __construct() {
$this->indentLevel = 0;
}
Expand Down
6 changes: 3 additions & 3 deletions lessify.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function preg_quote($what) {

public function match($regex, &$out, $eatWhitespace = true) {
$r = '/'.$regex.($eatWhitespace ? '\s*' : '').'/Ais';
if (preg_match($r, $this->buffer, $out, null, $this->count)) {
if (preg_match($r, $this->buffer, $out, 0, $this->count)) {
Comment thread
Copilot marked this conversation as resolved.
Resolved
$this->count += strlen($out[0]);
return true;
}
Expand All @@ -56,7 +56,7 @@ public function literal($what, $eatWhitespace = true) {

// shortcut on single letter
if (!$eatWhitespace and strlen($what) === 1) {
if ($this->buffer{$this->count} == $what) {
if ($this->buffer[$this->count] == $what) {
$this->count++;
return true;
}
Expand Down Expand Up @@ -367,7 +367,7 @@ public function dump() {
print_r($this->env);
}

public function parse($str = null) {
public function parse($str = null, $initialVariables = null) {
$this->prepareParser($str ? $str : $this->buffer);
while (false !== $this->parseChunk());

Expand Down
Loading