<?php
require_once('CSS/Parser/Exception.php');
class CSS_Parser_Exception_Syntax extends CSS_Parser_Exception
{
public $mode = 'text';
public $line = null;
public $column = null;
public $lastTokenLength = null;
public $contextual = null;
public function __construct($line = null, $column = null, $lastTokenLength = null, $contextual = null)
{
parent::__construct('Syntax error while parsing');
$this->line = $line;
$this->column = $column;
$this->lastTokenLength = $lastTokenLength;
$this->contextual = $contextual;
}
public function __toString()
{
if (is_null($this->line)) return parent::toString();
$result = sprintf('Parsing error on line %d column %d', $this->line, $this->column);
if ($this->mode == 'text') {
$result .= "\nContext\n----------------------\n";
$result .= $this->contextual[0] . "\n";
$result .= $this->contextual[1] . "\n";
for ($i=0; $i<$this->column - 1; $i++) $result .= ' ';
for ($i=0; $i<$this->lastTokenLength; $i++) $result .= '^';
$result .= "\n" . $this->contextual[2] . "\n----------------------\n";
} else {
$result .= '<br/>Context<br/>';
$result .= $this->contextual[0] . '<br/>';
$result .= substr($this->contextual[1], 0, $this->column - 1) .
'<span class="squiggle">' .
substr($this->contextual[1], $this->column - 1, $this->lastTokenLength) .
'</span>' .
substr($this->contextual[1], $this->column - 1 + $this->lastTokenLength);
}
return $result;
}
}
?>