1 | <?php |
||
11 | class Lexer { |
||
12 | |||
13 | private $tokens; |
||
14 | |||
15 | 10 | public function repair(TokenCollection $tokens) { |
|
16 | 10 | $fixedTokens = new TokenCollection(); |
|
17 | |||
18 | 10 | for ($i = 0, $n = $tokens->size(); $i < $n; $i++) { |
|
19 | 10 | $token = $tokens->get($i); |
|
20 | |||
21 | // fix ELSEIF |
||
22 | 10 | if ($token->type == T_ELSE) { |
|
23 | 5 | $nextToken = $tokens->get($i + 1); |
|
24 | |||
25 | 5 | if ($nextToken->type == T_IF) { |
|
26 | $i++; |
||
27 | $fixedTokens->add(new Token([T_ELSEIF, 'else if'])); |
||
28 | } else { |
||
29 | 5 | $fixedTokens->add($token); |
|
30 | } |
||
31 | |||
32 | 5 | continue; |
|
33 | } |
||
34 | |||
35 | 10 | $fixedTokens->add($token); |
|
36 | } |
||
37 | 10 | return $fixedTokens; |
|
38 | } |
||
39 | |||
40 | /** |
||
41 | * |
||
42 | * @param TokenCollection $tokens |
||
43 | * @return TokenCollection |
||
44 | */ |
||
45 | public function filterTokens(TokenCollection $tokens) { |
||
50 | } |
||
51 |