1 | <?php |
||
12 | class TokenStream |
||
13 | { |
||
14 | protected $ptr = 0; |
||
15 | |||
16 | /** |
||
17 | * Create the tokenstream with the specified list of tokens. |
||
18 | * |
||
19 | * @param Token[] $tokenList |
||
20 | * @param bool $skipWhitespace |
||
21 | */ |
||
22 | 13 | public function __construct($tokenList, $skipWhitespace = true) |
|
33 | |||
34 | |||
35 | /** |
||
36 | * Advances the internal pointer |
||
37 | * |
||
38 | * @return void |
||
39 | */ |
||
40 | 12 | public function next() |
|
44 | |||
45 | /** |
||
46 | * Checks if there is a next token |
||
47 | * |
||
48 | * @return bool |
||
49 | */ |
||
50 | public function hasNext() |
||
54 | |||
55 | |||
56 | /** |
||
57 | * Checks if there is a current token |
||
58 | * |
||
59 | * @return bool |
||
60 | */ |
||
61 | 13 | public function valid() |
|
65 | |||
66 | |||
67 | /** |
||
68 | * Returns the current token |
||
69 | * |
||
70 | * @return Token |
||
71 | * @throws \UnexpectedValueException |
||
72 | */ |
||
73 | 12 | public function current() |
|
80 | |||
81 | |||
82 | /** |
||
83 | * Returns the pointer in the stream |
||
84 | * |
||
85 | * @return int |
||
86 | */ |
||
87 | public function key() |
||
91 | |||
92 | |||
93 | /** |
||
94 | * Checks if the current token matches the specified type and/or value |
||
95 | * |
||
96 | * @param string $type |
||
97 | * @param string $value |
||
98 | * @return boolean |
||
99 | */ |
||
100 | 12 | public function match($type, $value = null) |
|
104 | |||
105 | |||
106 | /** |
||
107 | * Asserts the current token matches the specified value and/or type. Throws an exception if it doesn't |
||
108 | * |
||
109 | * @param string $type |
||
110 | * @param string $value |
||
111 | * @return Token |
||
112 | * |
||
113 | * @throws \UnexpectedValueException |
||
114 | */ |
||
115 | 11 | public function expect($type, $value = null) |
|
125 | } |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: