summaryrefslogtreecommitdiff
path: root/src/ste/ParseCompileError.php
blob: 33fd6125bd958475e4c7ea00060b3d92c9dfe4dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php

namespace kch42\ste;

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;
        $this->message = "$msg (Template $tpl, Offset $offset)";
    }

    public function rewrite($code) {
        $line = substr_count(str_replace("\r\n", "\n", substr($code, 0, $this->off)), "\n") + 1;
        $this->message = "{$this->msg} (Template {$this->tpl}, Line $line)";
        $this->is_rewritten = true;
    }
}