From 328b2700cf501a40c2cf7816bea9e4fccf349bbb Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Fri, 2 Jul 2021 11:26:01 +0200 Subject: [PATCH] Add type annotations for `ParserState` --- src/Parsing/ParserState.php | 151 +++++++++++++++++++++++++++++++++++- 1 file changed, 150 insertions(+), 1 deletion(-) diff --git a/src/Parsing/ParserState.php b/src/Parsing/ParserState.php index 306a317e..2dda8c84 100644 --- a/src/Parsing/ParserState.php +++ b/src/Parsing/ParserState.php @@ -7,22 +7,50 @@ class ParserState { + /** + * @var null + */ const EOF = null; + /** + * @var Settings + */ private $oParserSettings; + /** + * @var string + */ private $sText; + /** + * @var array + */ private $aText; + /** + * @var int + */ private $iCurrentPosition; + /** + * @var string + */ private $sCharset; + /** + * @var int + */ private $iLength; + /** + * @var int + */ private $iLineNo; + /** + * @param string $sText + * @param int $iLineNo + */ public function __construct($sText, Settings $oParserSettings, $iLineNo = 1) { $this->oParserSettings = $oParserSettings; @@ -32,6 +60,11 @@ public function __construct($sText, Settings $oParserSettings, $iLineNo = 1) $this->setCharset($this->oParserSettings->sDefaultCharset); } + /** + * @param string $sCharset + * + * @return void + */ public function setCharset($sCharset) { $this->sCharset = $sCharset; @@ -41,26 +74,45 @@ public function setCharset($sCharset) } } + /** + * @return string + */ public function getCharset() { return $this->sCharset; } + /** + * @return int + */ public function currentLine() { return $this->iLineNo; } + /** + * @return int + */ public function currentColumn() { return $this->iCurrentPosition; } + /** + * @return Settings + */ public function getSettings() { return $this->oParserSettings; } + /** + * @param bool $bIgnoreCase + * + * @return string + * + * @throws UnexpectedTokenException + */ public function parseIdentifier($bIgnoreCase = true) { $sResult = $this->parseCharacter(true); @@ -81,6 +133,14 @@ public function parseIdentifier($bIgnoreCase = true) return $sResult; } + /** + * @param bool $bIsForIdentifier + * + * @return string|null + * + * @throws UnexpectedEOFException + * @throws UnexpectedTokenException + */ public function parseCharacter($bIsForIdentifier) { if ($this->peek() === '\\') { @@ -136,6 +196,12 @@ public function parseCharacter($bIsForIdentifier) return null; } + /** + * @return array|void + * + * @throws UnexpectedEOFException + * @throws UnexpectedTokenException + */ public function consumeWhiteSpace() { $comments = []; @@ -160,6 +226,12 @@ public function consumeWhiteSpace() return $comments; } + /** + * @param string $sString + * @param bool $bCaseInsensitive + * + * @return bool + */ public function comes($sString, $bCaseInsensitive = false) { $sPeek = $this->peek(strlen($sString)); @@ -168,6 +240,12 @@ public function comes($sString, $bCaseInsensitive = false) : $this->streql($sPeek, $sString, $bCaseInsensitive); } + /** + * @param int $iLength + * @param int $iOffset + * + * @return string + */ public function peek($iLength = 1, $iOffset = 0) { $iOffset += $this->iCurrentPosition; @@ -177,6 +255,14 @@ public function peek($iLength = 1, $iOffset = 0) return $this->substr($iOffset, $iLength); } + /** + * @param int $mValue + * + * @return string + * + * @throws UnexpectedEOFException + * @throws UnexpectedTokenException + */ public function consume($mValue = 1) { if (is_string($mValue)) { @@ -200,6 +286,15 @@ public function consume($mValue = 1) } } + /** + * @param string $mExpression + * @param int|null $iMaxLength + * + * @return string + * + * @throws UnexpectedEOFException + * @throws UnexpectedTokenException + */ public function consumeExpression($mExpression, $iMaxLength = null) { $aMatches = null; @@ -211,7 +306,7 @@ public function consumeExpression($mExpression, $iMaxLength = null) } /** - * @return false|Comment + * @return Comment|false */ public function consumeComment() { @@ -237,6 +332,9 @@ public function consumeComment() return $mComment; } + /** + * @return bool + */ public function isEnd() { return $this->iCurrentPosition >= $this->iLength; @@ -244,6 +342,14 @@ public function isEnd() /** * @param array|string $aEnd + * @param string $bIncludeEnd + * @param string $consumeEnd + * @param array $comments + * + * @return string + * + * @throws UnexpectedEOFException + * @throws UnexpectedTokenException */ public function consumeUntil($aEnd, $bIncludeEnd = false, $consumeEnd = false, array &$comments = []) { @@ -280,11 +386,21 @@ public function consumeUntil($aEnd, $bIncludeEnd = false, $consumeEnd = false, a ); } + /** + * @return string + */ private function inputLeft() { return $this->substr($this->iCurrentPosition, -1); } + /** + * @param string $sString1 + * @param string $sString2 + * @param bool $bCaseInsensitive + * + * @return bool + */ public function streql($sString1, $sString2, $bCaseInsensitive = true) { if ($bCaseInsensitive) { @@ -294,11 +410,21 @@ public function streql($sString1, $sString2, $bCaseInsensitive = true) } } + /** + * @param int $iAmount + * + * @return void + */ public function backtrack($iAmount) { $this->iCurrentPosition -= $iAmount; } + /** + * @param string $sString + * + * @return int + */ public function strlen($sString) { if ($this->oParserSettings->bMultibyteSupport) { @@ -308,6 +434,12 @@ public function strlen($sString) } } + /** + * @param int $iStart + * @param int $iLength + * + * @return string + */ private function substr($iStart, $iLength) { if ($iLength < 0) { @@ -325,6 +457,11 @@ private function substr($iStart, $iLength) return $sResult; } + /** + * @param string $sString + * + * @return string + */ private function strtolower($sString) { if ($this->oParserSettings->bMultibyteSupport) { @@ -334,6 +471,11 @@ private function strtolower($sString) } } + /** + * @param string $sString + * + * @return array + */ private function strsplit($sString) { if ($this->oParserSettings->bMultibyteSupport) { @@ -356,6 +498,13 @@ private function strsplit($sString) } } + /** + * @param string $sString + * @param string $sNeedle + * @param int $iOffset + * + * @return int|false + */ private function strpos($sString, $sNeedle, $iOffset) { if ($this->oParserSettings->bMultibyteSupport) {