forked from WalterWoshid/php-dissect
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TokenStream.php
66 lines (56 loc) · 1.51 KB
/
TokenStream.php
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
declare(strict_types=1);
namespace Dissect\Lexer\TokenStream;
use Countable;
use Dissect\Lexer\Token;
use IteratorAggregate;
use OutOfBoundsException;
/**
* A common contract for all token stream classes.
*
* @author Jakub Lédl <[email protected]>
*/
interface TokenStream extends Countable, IteratorAggregate
{
/**
* Returns the current position in the stream.
*/
public function getPosition(): int;
/**
* Retrieves the current token.
*
* @return Token The current token.
*/
public function getCurrentToken(): Token;
/**
* Returns a look-ahead token. Negative values are allowed
* and serve as look-behind.
*
* @throws OutOfBoundsException If current position + $n is out of range.
*/
public function lookAhead(int $n): Token;
/**
* Returns the token at absolute position $n.
*
* @throws OutOfBoundsException If $n is out of range.
*/
public function get(int $n): Token;
/**
* Moves the cursor to the absolute position $n.
*
* @throws OutOfBoundsException If $n is out of range.
*/
public function move(int $n): void;
/**
* Moves the cursor by $n, relative to the current position.
*
* @throws OutOfBoundsException If current position + $n is out of range.
*/
public function seek(int $n): void;
/**
* Moves the cursor to the next token.
*
* @throws OutOfBoundsException If at the end of the stream.
*/
public function next(): void;
}