1 | <?php |
||
29 | class TokenStream implements Countable, SeekableIterator |
||
30 | { |
||
31 | /** @type array $tokens set of tokens */ |
||
32 | public $tokens = []; |
||
33 | /** @type int $position */ |
||
34 | public $position = 0; |
||
35 | |||
36 | |||
37 | /** |
||
38 | * Creates a new tokenstream instance from a code piece |
||
39 | * |
||
40 | * @param string $uCode the string consists of codes to turned into tokens |
||
41 | * |
||
42 | * @return TokenStream the new instance |
||
43 | */ |
||
44 | public static function fromString($uCode) |
||
48 | |||
49 | /** |
||
50 | * Initializes a token stream |
||
51 | * |
||
52 | * @param array $uTokens set of tokens |
||
53 | * |
||
54 | * @return TokenStream |
||
|
|||
55 | */ |
||
56 | public function __construct(array $uTokens = []) |
||
66 | |||
67 | /** |
||
68 | * Count elements of an object |
||
69 | * |
||
70 | * @return int the count as an integer |
||
71 | */ |
||
72 | public function count() |
||
76 | |||
77 | /** |
||
78 | * Seeks to a position |
||
79 | * |
||
80 | * @param int $uPosition the position to seek to |
||
81 | * |
||
82 | * @throws OutOfBoundsException |
||
83 | * @return void |
||
84 | */ |
||
85 | public function seek($uPosition) |
||
93 | |||
94 | /** |
||
95 | * Rewind the Iterator to the first element |
||
96 | * |
||
97 | * @return void |
||
98 | */ |
||
99 | public function rewind() |
||
103 | |||
104 | /** |
||
105 | * Return the current element |
||
106 | * |
||
107 | * @return mixed |
||
108 | */ |
||
109 | public function current() |
||
113 | |||
114 | /** |
||
115 | * Return the key of the current element |
||
116 | * |
||
117 | * @return int |
||
118 | */ |
||
119 | public function key() |
||
123 | |||
124 | /** |
||
125 | * Move forward to next element |
||
126 | * |
||
127 | * @return void |
||
128 | */ |
||
129 | public function next() |
||
133 | |||
134 | /** |
||
135 | * Checks if current position is valid |
||
136 | * |
||
137 | * @return bool true on success or false on failure |
||
138 | */ |
||
139 | public function valid() |
||
143 | |||
144 | /** |
||
145 | * Move back to previous element |
||
146 | * |
||
147 | * @return mixed |
||
148 | */ |
||
149 | public function prev() |
||
153 | |||
154 | /** |
||
155 | * Gets next token if condition is true |
||
156 | * |
||
157 | * @param array|integer $uType |
||
158 | * @param array|string|null $uValue |
||
159 | * |
||
160 | * @return bool |
||
161 | */ |
||
162 | public function nextIf($uType, $uValue = null) |
||
171 | |||
172 | /** |
||
173 | * Advances until a token with the given type is found |
||
174 | * |
||
175 | * @param array|integer $uType |
||
176 | * @param array|string|null $uValue |
||
177 | * |
||
178 | * @return mixed |
||
179 | */ |
||
180 | public function nextUntil($uType, $uValue = null) |
||
192 | |||
193 | /** |
||
194 | * Tests the current token for a condition |
||
195 | * |
||
196 | * @param array|integer $uType |
||
197 | * @param array|string|null $uValue |
||
198 | * |
||
199 | * @return mixed |
||
200 | */ |
||
201 | public function test($uType, $uValue = null) |
||
221 | |||
222 | /** |
||
223 | * Tests the current token for a condition or throws an exception otherwise |
||
224 | * |
||
225 | * @param array|integer $uType |
||
226 | * @param array|string|null $uValue |
||
227 | * @param string|null $uMessage |
||
228 | * |
||
229 | * @throws UnexpectedValueException |
||
230 | * @return void |
||
231 | */ |
||
232 | public function expect($uType, $uValue = null, $uMessage = null) |
||
247 | } |
||
248 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.