18
18
19
19
/**
20
20
* Base class for writing simple lexers, i.e. for creating small DSLs.
21
+ *
22
+ * @psalm-type Token = array{value: int|string, type:string|int|null, position:int}
21
23
*/
22
24
abstract class AbstractLexer
23
25
{
@@ -38,7 +40,7 @@ abstract class AbstractLexer
38
40
* - 'position' : the position of the token in the input string
39
41
*
40
42
* @var mixed[][]
41
- * @psalm-var list<array{value: string, type: string|int|null, position: int} >
43
+ * @psalm-var list<Token >
42
44
*/
43
45
private $ tokens = [];
44
46
@@ -60,15 +62,15 @@ abstract class AbstractLexer
60
62
* The next token in the input.
61
63
*
62
64
* @var mixed[]|null
63
- * @psalm-var array{value: string, type: string|int|null, position: int} |null
65
+ * @psalm-var Token |null
64
66
*/
65
67
public $ lookahead ;
66
68
67
69
/**
68
70
* The last matched/seen token.
69
71
*
70
72
* @var mixed[]|null
71
- * @psalm-var array{value: string, type: string|int|null, position: int} |null
73
+ * @psalm-var Token |null
72
74
*/
73
75
public $ token ;
74
76
@@ -148,25 +150,25 @@ public function getInputUntilPosition($position)
148
150
/**
149
151
* Checks whether a given token matches the current lookahead.
150
152
*
151
- * @param int|string $token
153
+ * @param int|string $type
152
154
*
153
155
* @return bool
154
156
*/
155
- public function isNextToken ($ token )
157
+ public function isNextToken ($ type )
156
158
{
157
- return $ this ->lookahead !== null && $ this ->lookahead ['type ' ] === $ token ;
159
+ return $ this ->lookahead !== null && $ this ->lookahead ['type ' ] === $ type ;
158
160
}
159
161
160
162
/**
161
163
* Checks whether any of the given tokens matches the current lookahead.
162
164
*
163
- * @param string[] $tokens
165
+ * @param list<int| string> $types
164
166
*
165
167
* @return bool
166
168
*/
167
- public function isNextTokenAny (array $ tokens )
169
+ public function isNextTokenAny (array $ types )
168
170
{
169
- return $ this ->lookahead !== null && in_array ($ this ->lookahead ['type ' ], $ tokens , true );
171
+ return $ this ->lookahead !== null && in_array ($ this ->lookahead ['type ' ], $ types , true );
170
172
}
171
173
172
174
/**
@@ -215,7 +217,7 @@ public function isA($value, $token)
215
217
* Moves the lookahead token forward.
216
218
*
217
219
* @return mixed[]|null The next token or NULL if there are no more tokens ahead.
218
- * @psalm-return array{value: string, type: string|int|null, position: int} |null
220
+ * @psalm-return Token |null
219
221
*/
220
222
public function peek ()
221
223
{
@@ -230,7 +232,7 @@ public function peek()
230
232
* Peeks at the next token, returns it and immediately resets the peek.
231
233
*
232
234
* @return mixed[]|null The next token or NULL if there are no more tokens ahead.
233
- * @psalm-return array{value: string, type: string|int|null, position: int} |null
235
+ * @psalm-return Token |null
234
236
*/
235
237
public function glimpse ()
236
238
{
0 commit comments