1 | <?php |
||
14 | abstract class BaseToken |
||
15 | { |
||
16 | /** |
||
17 | * @var mixed |
||
18 | */ |
||
19 | protected $value; |
||
20 | |||
21 | /** |
||
22 | * @var int |
||
23 | */ |
||
24 | protected $offset = 0; |
||
25 | |||
26 | /** |
||
27 | * @var Stack |
||
28 | */ |
||
29 | protected $stack; |
||
30 | |||
31 | /** |
||
32 | * @var int |
||
33 | */ |
||
34 | protected $position = null; |
||
35 | |||
36 | /** |
||
37 | * @var int |
||
38 | */ |
||
39 | protected $line = null; |
||
40 | |||
41 | /** |
||
42 | * @param mixed $value |
||
43 | * @param int $offset |
||
44 | * @param Stack $stack |
||
45 | */ |
||
46 | 224 | public function __construct($value, int $offset = 0, Stack $stack = null) |
|
47 | { |
||
48 | 224 | $this->value = $value; |
|
49 | 224 | $this->offset = $offset; |
|
50 | 224 | $this->stack = $stack; |
|
51 | 224 | } |
|
52 | |||
53 | abstract public function getGroup() : int; |
||
54 | |||
55 | /** |
||
56 | * @return mixed |
||
57 | */ |
||
58 | 206 | public function getValue() |
|
59 | { |
||
60 | 206 | return $this->value; |
|
61 | } |
||
62 | |||
63 | /** |
||
64 | * Some tokens can be represented by different operators, |
||
65 | * so the original value is used for error reporting, |
||
66 | * while the other one is used internally. |
||
67 | * |
||
68 | * @return mixed |
||
69 | */ |
||
70 | 44 | final public function getOriginalValue() |
|
71 | { |
||
72 | 44 | return $this->value; |
|
73 | } |
||
74 | |||
75 | 146 | public function getOffset() : int |
|
79 | |||
80 | public function setOffset(int $offset = 0) |
||
81 | { |
||
82 | $this->offset = $offset; |
||
83 | } |
||
84 | |||
85 | 106 | public function getStack() : Stack |
|
89 | |||
90 | 90 | public function setStack(Stack $stack) |
|
91 | { |
||
92 | 90 | $this->stack = $stack; |
|
93 | 90 | } |
|
94 | |||
95 | 18 | public function supportsMethodCalls() : bool |
|
99 | |||
100 | 50 | public function getPosition() : int |
|
101 | { |
||
102 | 50 | if (!isset($this->position)) { |
|
103 | 48 | $this->getLineAndPosition(); |
|
104 | } |
||
105 | |||
108 | |||
109 | 50 | public function getLine() : int |
|
117 | |||
118 | 50 | private function getLineAndPosition() |
|
141 | } |
||
142 |