1 | <?php |
||
8 | class TokenTracker implements TokenVisitorInterface { |
||
9 | |||
10 | private $tokens; |
||
11 | private $context; |
||
12 | |||
13 | private $next; |
||
14 | private $prev; |
||
15 | |||
16 | 10 | public function __construct(TokenCollection $tokens, Context $contextManager) { |
|
21 | |||
22 | 10 | public function visitToken(Token $token) { |
|
27 | |||
28 | 3 | public function getNextToken() { |
|
31 | |||
32 | 10 | public function getPrevToken() { |
|
35 | |||
36 | 10 | public function nextToken(Token $token, $offset = 1) { |
|
37 | 10 | $index = $this->tokens->indexOf($token); |
|
38 | 10 | $index += $offset; |
|
39 | 10 | $token = $this->tokens->get($index); |
|
40 | |||
41 | 10 | if ($token === null) { |
|
42 | 10 | $token = new Token(); |
|
43 | } |
||
44 | |||
45 | 10 | return $token; |
|
46 | } |
||
47 | |||
48 | 10 | public function prevToken($token, $offset = 1) { |
|
49 | 10 | $index = $this->tokens->indexOf($token); |
|
50 | 10 | $index -= $offset; |
|
51 | 10 | $token = $this->tokens->get($index); |
|
52 | |||
53 | 10 | if ($token === null) { |
|
54 | 10 | $token = new Token(); |
|
55 | } |
||
56 | |||
57 | 10 | return $token; |
|
58 | } |
||
59 | |||
60 | 10 | public function isLastToken(Token $token) { |
|
63 | |||
64 | } |
||
65 |