Skip to content

Commit 39cfd71

Browse files
authored
Merge pull request #297 from oliverklee/task/types/parserstate
Add type annotations for `ParserState`
2 parents 4f802f4 + 328b270 commit 39cfd71

File tree

1 file changed

+150
-1
lines changed

1 file changed

+150
-1
lines changed

src/Parsing/ParserState.php

Lines changed: 150 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,50 @@
77

88
class ParserState
99
{
10+
/**
11+
* @var null
12+
*/
1013
const EOF = null;
1114

15+
/**
16+
* @var Settings
17+
*/
1218
private $oParserSettings;
1319

20+
/**
21+
* @var string
22+
*/
1423
private $sText;
1524

25+
/**
26+
* @var array<int, string>
27+
*/
1628
private $aText;
1729

30+
/**
31+
* @var int
32+
*/
1833
private $iCurrentPosition;
1934

35+
/**
36+
* @var string
37+
*/
2038
private $sCharset;
2139

40+
/**
41+
* @var int
42+
*/
2243
private $iLength;
2344

45+
/**
46+
* @var int
47+
*/
2448
private $iLineNo;
2549

50+
/**
51+
* @param string $sText
52+
* @param int $iLineNo
53+
*/
2654
public function __construct($sText, Settings $oParserSettings, $iLineNo = 1)
2755
{
2856
$this->oParserSettings = $oParserSettings;
@@ -32,6 +60,11 @@ public function __construct($sText, Settings $oParserSettings, $iLineNo = 1)
3260
$this->setCharset($this->oParserSettings->sDefaultCharset);
3361
}
3462

63+
/**
64+
* @param string $sCharset
65+
*
66+
* @return void
67+
*/
3568
public function setCharset($sCharset)
3669
{
3770
$this->sCharset = $sCharset;
@@ -41,26 +74,45 @@ public function setCharset($sCharset)
4174
}
4275
}
4376

77+
/**
78+
* @return string
79+
*/
4480
public function getCharset()
4581
{
4682
return $this->sCharset;
4783
}
4884

85+
/**
86+
* @return int
87+
*/
4988
public function currentLine()
5089
{
5190
return $this->iLineNo;
5291
}
5392

93+
/**
94+
* @return int
95+
*/
5496
public function currentColumn()
5597
{
5698
return $this->iCurrentPosition;
5799
}
58100

101+
/**
102+
* @return Settings
103+
*/
59104
public function getSettings()
60105
{
61106
return $this->oParserSettings;
62107
}
63108

109+
/**
110+
* @param bool $bIgnoreCase
111+
*
112+
* @return string
113+
*
114+
* @throws UnexpectedTokenException
115+
*/
64116
public function parseIdentifier($bIgnoreCase = true)
65117
{
66118
$sResult = $this->parseCharacter(true);
@@ -81,6 +133,14 @@ public function parseIdentifier($bIgnoreCase = true)
81133
return $sResult;
82134
}
83135

136+
/**
137+
* @param bool $bIsForIdentifier
138+
*
139+
* @return string|null
140+
*
141+
* @throws UnexpectedEOFException
142+
* @throws UnexpectedTokenException
143+
*/
84144
public function parseCharacter($bIsForIdentifier)
85145
{
86146
if ($this->peek() === '\\') {
@@ -136,6 +196,12 @@ public function parseCharacter($bIsForIdentifier)
136196
return null;
137197
}
138198

199+
/**
200+
* @return array<int, Comment>|void
201+
*
202+
* @throws UnexpectedEOFException
203+
* @throws UnexpectedTokenException
204+
*/
139205
public function consumeWhiteSpace()
140206
{
141207
$comments = [];
@@ -160,6 +226,12 @@ public function consumeWhiteSpace()
160226
return $comments;
161227
}
162228

229+
/**
230+
* @param string $sString
231+
* @param bool $bCaseInsensitive
232+
*
233+
* @return bool
234+
*/
163235
public function comes($sString, $bCaseInsensitive = false)
164236
{
165237
$sPeek = $this->peek(strlen($sString));
@@ -168,6 +240,12 @@ public function comes($sString, $bCaseInsensitive = false)
168240
: $this->streql($sPeek, $sString, $bCaseInsensitive);
169241
}
170242

243+
/**
244+
* @param int $iLength
245+
* @param int $iOffset
246+
*
247+
* @return string
248+
*/
171249
public function peek($iLength = 1, $iOffset = 0)
172250
{
173251
$iOffset += $this->iCurrentPosition;
@@ -177,6 +255,14 @@ public function peek($iLength = 1, $iOffset = 0)
177255
return $this->substr($iOffset, $iLength);
178256
}
179257

258+
/**
259+
* @param int $mValue
260+
*
261+
* @return string
262+
*
263+
* @throws UnexpectedEOFException
264+
* @throws UnexpectedTokenException
265+
*/
180266
public function consume($mValue = 1)
181267
{
182268
if (is_string($mValue)) {
@@ -200,6 +286,15 @@ public function consume($mValue = 1)
200286
}
201287
}
202288

289+
/**
290+
* @param string $mExpression
291+
* @param int|null $iMaxLength
292+
*
293+
* @return string
294+
*
295+
* @throws UnexpectedEOFException
296+
* @throws UnexpectedTokenException
297+
*/
203298
public function consumeExpression($mExpression, $iMaxLength = null)
204299
{
205300
$aMatches = null;
@@ -211,7 +306,7 @@ public function consumeExpression($mExpression, $iMaxLength = null)
211306
}
212307

213308
/**
214-
* @return false|Comment
309+
* @return Comment|false
215310
*/
216311
public function consumeComment()
217312
{
@@ -237,13 +332,24 @@ public function consumeComment()
237332
return $mComment;
238333
}
239334

335+
/**
336+
* @return bool
337+
*/
240338
public function isEnd()
241339
{
242340
return $this->iCurrentPosition >= $this->iLength;
243341
}
244342

245343
/**
246344
* @param array<array-key, string>|string $aEnd
345+
* @param string $bIncludeEnd
346+
* @param string $consumeEnd
347+
* @param array<int, Comment> $comments
348+
*
349+
* @return string
350+
*
351+
* @throws UnexpectedEOFException
352+
* @throws UnexpectedTokenException
247353
*/
248354
public function consumeUntil($aEnd, $bIncludeEnd = false, $consumeEnd = false, array &$comments = [])
249355
{
@@ -280,11 +386,21 @@ public function consumeUntil($aEnd, $bIncludeEnd = false, $consumeEnd = false, a
280386
);
281387
}
282388

389+
/**
390+
* @return string
391+
*/
283392
private function inputLeft()
284393
{
285394
return $this->substr($this->iCurrentPosition, -1);
286395
}
287396

397+
/**
398+
* @param string $sString1
399+
* @param string $sString2
400+
* @param bool $bCaseInsensitive
401+
*
402+
* @return bool
403+
*/
288404
public function streql($sString1, $sString2, $bCaseInsensitive = true)
289405
{
290406
if ($bCaseInsensitive) {
@@ -294,11 +410,21 @@ public function streql($sString1, $sString2, $bCaseInsensitive = true)
294410
}
295411
}
296412

413+
/**
414+
* @param int $iAmount
415+
*
416+
* @return void
417+
*/
297418
public function backtrack($iAmount)
298419
{
299420
$this->iCurrentPosition -= $iAmount;
300421
}
301422

423+
/**
424+
* @param string $sString
425+
*
426+
* @return int
427+
*/
302428
public function strlen($sString)
303429
{
304430
if ($this->oParserSettings->bMultibyteSupport) {
@@ -308,6 +434,12 @@ public function strlen($sString)
308434
}
309435
}
310436

437+
/**
438+
* @param int $iStart
439+
* @param int $iLength
440+
*
441+
* @return string
442+
*/
311443
private function substr($iStart, $iLength)
312444
{
313445
if ($iLength < 0) {
@@ -325,6 +457,11 @@ private function substr($iStart, $iLength)
325457
return $sResult;
326458
}
327459

460+
/**
461+
* @param string $sString
462+
*
463+
* @return string
464+
*/
328465
private function strtolower($sString)
329466
{
330467
if ($this->oParserSettings->bMultibyteSupport) {
@@ -334,6 +471,11 @@ private function strtolower($sString)
334471
}
335472
}
336473

474+
/**
475+
* @param string $sString
476+
*
477+
* @return array<int, string>
478+
*/
337479
private function strsplit($sString)
338480
{
339481
if ($this->oParserSettings->bMultibyteSupport) {
@@ -356,6 +498,13 @@ private function strsplit($sString)
356498
}
357499
}
358500

501+
/**
502+
* @param string $sString
503+
* @param string $sNeedle
504+
* @param int $iOffset
505+
*
506+
* @return int|false
507+
*/
359508
private function strpos($sString, $sNeedle, $iOffset)
360509
{
361510
if ($this->oParserSettings->bMultibyteSupport) {

0 commit comments

Comments
 (0)