private function lessc::readChunk in Less CSS Preprocessor 6
1 call to lessc::readChunk()
- lessc::parse in ./lessc.inc.php
File
- ./lessc.inc.php, line 106
Class
- lessc
Code
private function readChunk() {
if ($this->buffer == '') {
return false;
}
try {
$this
->keyword($name)
->literal(':')
->propertyValue($value)
->end()
->advance();
$this
->append($name, $value);
if ($this->level > 1) {
return true;
}
else {
return $this
->compileProperty($name, array(
$this
->getVal($name),
)) . "\n";
}
} catch (exception $ex) {
$this
->undo();
}
try {
$this
->tags($tags);
if (count($tags) == 1) {
try {
$save = $this->count;
$this
->argumentDef($args);
} catch (exception $ex) {
$this->count = $save;
}
}
$this
->literal('{')
->advance();
$this
->push();
foreach ($tags as &$tag) {
if ($tag[0] == "@") {
$tag[0] = "%";
}
}
$this
->set('__tags', $tags);
if (isset($args)) {
$this
->set('__args', $args);
}
return true;
} catch (exception $ex) {
$this
->undo();
}
try {
$this
->literal('}')
->advance();
$tags = $this
->multiplyTags();
$env = end($this->env);
$ctags = $env['__tags'];
unset($env['__tags']);
if (isset($env['__args'])) {
foreach ($env['__args'] as $arg) {
if (isset($arg[1])) {
$this
->prepend('@' . $arg[0], $arg[1]);
}
}
}
if (!empty($tags)) {
$out = $this
->compileBlock($tags, $env);
}
$this
->pop();
foreach ($ctags as $t) {
if ($this
->get($t, array(
end($this->env),
))) {
$this
->merge($t, $env);
}
else {
$this
->set($t, $env);
}
}
return isset($out) ? $out : true;
} catch (exception $ex) {
$this
->undo();
}
try {
$this
->import($url, $media)
->advance();
if ($this->importDisabled) {
return "/* import is disabled */\n";
}
$full = $this->importDir . $url;
if (file_exists($file = $full) || file_exists($file = $full . '.less')) {
$this->buffer = $this
->removeComments(file_get_contents($file) . ";\n" . $this->buffer);
return true;
}
return '@import url("' . $url . '")' . ($media ? ' ' . $media : '') . ";\n";
} catch (exception $ex) {
$this
->undo();
}
try {
$this
->variable($name)
->literal(':')
->propertyValue($value)
->end()
->advance();
$this
->append('@' . $name, $value);
return true;
} catch (exception $ex) {
$this
->undo();
}
try {
$this
->tags($tags, true, '>');
foreach ($tags as &$tag) {
if ($tag[0] == "@") {
$tag[0] = "%";
}
}
$save = $this->count;
try {
$this
->argumentValues($argv);
} catch (exception $ex) {
$this->count = $save;
}
$this
->end()
->advance();
$env = $this
->get(array_shift($tags));
while ($sub = array_shift($tags)) {
if (isset($env[$sub])) {
$env = $env[$sub];
}
else {
$env = null;
break;
}
}
if ($env == null) {
return true;
}
if (!empty($env['__args'])) {
foreach ($env['__args'] as $arg) {
$name = $arg[0];
$value = is_array($argv) ? array_shift($argv) : null;
if ($value == null && isset($arg[1])) {
$value = $arg[1];
}
if (isset($env['@' . $name])) {
array_unshift($env['@' . $name], $value);
}
else {
$env['@' . $name] = array(
$value,
);
}
}
}
ob_start();
foreach ($env as $name => $value) {
if (!isset($value[0])) {
$rtags = $this
->multiplyTags(array(
$name,
));
echo $this
->compileBlock($rtags, $value);
}
if (!preg_match('/^__/', $name)) {
if ($this
->get($name, array(
end($this->env),
))) {
while ($tval = array_shift($value)) {
$this
->append($name, $tval);
}
}
else {
$this
->set($name, $value);
}
}
}
return ob_get_clean();
} catch (exception $ex) {
$this
->undo();
}
try {
$this
->literal(';')
->advance();
return true;
} catch (exception $ex) {
$this
->undo();
}
$this
->match("(.*?)(\n|\$)", $m);
throw new exception('Failed to parse line ' . $this->line . "\nOffending line: " . $m[1]);
}