blob: bc0c252879c418640ddd1accd0a3dd81ab433e1d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
<?php
namespace kch42\ste;
/**
* An exception thrown by the parser or compiler
*/
class ParseCompileError extends \Exception
{
public $msg;
public $tpl;
public $off;
public function __construct($msg, $tpl, $offset, $code = 0, $previous = null)
{
$this->msg = $msg;
$this->tpl = $tpl;
$this->off = $offset;
parent::__construct("$msg (Template $tpl, Offset $offset)", $code, $previous);
}
/**
* Update the message to include a human readable offset.
* @param string $code
*/
public function rewrite(string $code): void
{
$line = substr_count(str_replace("\r\n", "\n", substr($code, 0, $this->off)), "\n") + 1;
$this->message = "{$this->msg} (Template {$this->tpl}, Line $line)";
}
}
|