Skip to content

[CLEANUP] Avoid Hungarian notation for *stack* #1064

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 4, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions src/Value/Value.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,69 +43,69 @@ public function __construct($lineNumber = 0)
*/
public static function parseValue(ParserState $parserState, array $aListDelimiters = [])
{
/** @var array<int, Value|string> $aStack */
$aStack = [];
/** @var array<int, Value|string> $stack */
$stack = [];
$parserState->consumeWhiteSpace();
//Build a list of delimiters and parsed values
while (
!($parserState->comes('}') || $parserState->comes(';') || $parserState->comes('!')
|| $parserState->comes(')')
|| $parserState->isEnd())
) {
if (\count($aStack) > 0) {
if (\count($stack) > 0) {
$bFoundDelimiter = false;
foreach ($aListDelimiters as $sDelimiter) {
if ($parserState->comes($sDelimiter)) {
\array_push($aStack, $parserState->consume($sDelimiter));
\array_push($stack, $parserState->consume($sDelimiter));
$parserState->consumeWhiteSpace();
$bFoundDelimiter = true;
break;
}
}
if (!$bFoundDelimiter) {
//Whitespace was the list delimiter
\array_push($aStack, ' ');
\array_push($stack, ' ');
}
}
\array_push($aStack, self::parsePrimitiveValue($parserState));
\array_push($stack, self::parsePrimitiveValue($parserState));
$parserState->consumeWhiteSpace();
}
// Convert the list to list objects
foreach ($aListDelimiters as $sDelimiter) {
$iStackLength = \count($aStack);
if ($iStackLength === 1) {
return $aStack[0];
$stackSize = \count($stack);
if ($stackSize === 1) {
return $stack[0];
}
$aNewStack = [];
for ($offset = 0; $offset < $iStackLength; ++$offset) {
if ($offset === ($iStackLength - 1) || $sDelimiter !== $aStack[$offset + 1]) {
$aNewStack[] = $aStack[$offset];
$newStack = [];
for ($offset = 0; $offset < $stackSize; ++$offset) {
if ($offset === ($stackSize - 1) || $sDelimiter !== $stack[$offset + 1]) {
$newStack[] = $stack[$offset];
continue;
}
$length = 2; //Number of elements to be joined
for ($i = $offset + 3; $i < $iStackLength; $i += 2, ++$length) {
if ($sDelimiter !== $aStack[$i]) {
for ($i = $offset + 3; $i < $stackSize; $i += 2, ++$length) {
if ($sDelimiter !== $stack[$i]) {
break;
}
}
$list = new RuleValueList($sDelimiter, $parserState->currentLine());
for ($i = $offset; $i - $offset < $length * 2; $i += 2) {
$list->addListComponent($aStack[$i]);
$list->addListComponent($stack[$i]);
}
$aNewStack[] = $list;
$newStack[] = $list;
$offset += $length * 2 - 2;
}
$aStack = $aNewStack;
$stack = $newStack;
}
if (!isset($aStack[0])) {
if (!isset($stack[0])) {
throw new UnexpectedTokenException(
" {$parserState->peek()} ",
$parserState->peek(1, -1) . $parserState->peek(2),
'literal',
$parserState->currentLine()
);
}
return $aStack[0];
return $stack[0];
}

/**
Expand Down