function JsonParser::performAction
Parameters
stdClass|array<mixed>|int|bool|float|string|null $currentToken:
string $yytext:
int $yyleng:
int $yylineno:
int $yystate:
Return value
array{stdClass|array<mixed>|int|bool|float|string|null, stdClass|array<mixed>|int|bool|float|string|null|Undefined}
1 call to JsonParser::performAction()
- JsonParser::parse in vendor/
seld/ jsonlint/ src/ Seld/ JsonLint/ JsonParser.php - @phpstan-param int-mask-of<self::*> $flags
File
-
vendor/
seld/ jsonlint/ src/ Seld/ JsonLint/ JsonParser.php, line 423
Class
- JsonParser
- Parser class
Namespace
Seld\JsonLintCode
private function performAction($currentToken, $yytext, $yyleng, $yylineno, $yystate) {
$token = $currentToken;
$len = \count($this->vstack) - 1;
switch ($yystate) {
case 1:
$yytext = preg_replace_callback('{(?:\\\\["bfnrt/\\\\]|\\\\u[a-fA-F0-9]{4})}', array(
$this,
'stringInterpolation',
), $yytext);
$token = $yytext;
break;
case 2:
if (strpos($yytext, 'e') !== false || strpos($yytext, 'E') !== false) {
$token = \floatval($yytext);
}
else {
$token = strpos($yytext, '.') === false ? \intval($yytext) : \floatval($yytext);
}
break;
case 3:
$token = null;
break;
case 4:
$token = true;
break;
case 5:
$token = false;
break;
case 6:
$token = $this->vstack[$len - 1];
return array(
$token,
$token,
);
case 13:
if ($this->flags & self::PARSE_TO_ASSOC) {
$token = array();
}
else {
$token = new stdClass();
}
break;
case 14:
$token = $this->vstack[$len - 1];
break;
case 15:
$token = array(
$this->vstack[$len - 2],
$this->vstack[$len],
);
break;
case 16:
assert(\is_array($this->vstack[$len]));
if (PHP_VERSION_ID < 70100) {
$property = $this->vstack[$len][0] === '' ? '_empty_' : $this->vstack[$len][0];
}
else {
$property = $this->vstack[$len][0];
}
if ($this->flags & self::PARSE_TO_ASSOC) {
$token = array();
$token[$property] = $this->vstack[$len][1];
}
else {
$token = new stdClass();
$token->{$property} = $this->vstack[$len][1];
}
break;
case 17:
assert(\is_array($this->vstack[$len]));
if ($this->flags & self::PARSE_TO_ASSOC) {
assert(\is_array($this->vstack[$len - 2]));
$token =& $this->vstack[$len - 2];
$key = $this->vstack[$len][0];
if ($this->flags & self::DETECT_KEY_CONFLICTS && isset($this->vstack[$len - 2][$key])) {
$errStr = 'Parse error on line ' . ($yylineno + 1) . ":\n";
$errStr .= $this->lexer
->showPosition() . "\n";
$errStr .= "Duplicate key: " . $this->vstack[$len][0];
throw new DuplicateKeyException($errStr, $this->vstack[$len][0], array(
'line' => $yylineno + 1,
));
}
if ($this->flags & self::ALLOW_DUPLICATE_KEYS && isset($this->vstack[$len - 2][$key])) {
$duplicateCount = 1;
do {
$duplicateKey = $key . '.' . $duplicateCount++;
} while (isset($this->vstack[$len - 2][$duplicateKey]));
$this->vstack[$len - 2][$duplicateKey] = $this->vstack[$len][1];
}
elseif ($this->flags & self::ALLOW_DUPLICATE_KEYS_TO_ARRAY && isset($this->vstack[$len - 2][$key])) {
if (!isset($this->vstack[$len - 2][$key]['__duplicates__']) || !is_array($this->vstack[$len - 2][$key]['__duplicates__'])) {
$this->vstack[$len - 2][$key] = array(
'__duplicates__' => array(
$this->vstack[$len - 2][$key],
),
);
}
$this->vstack[$len - 2][$key]['__duplicates__'][] = $this->vstack[$len][1];
}
else {
$this->vstack[$len - 2][$key] = $this->vstack[$len][1];
}
}
else {
assert($this->vstack[$len - 2] instanceof stdClass);
$token = $this->vstack[$len - 2];
if (PHP_VERSION_ID < 70100) {
$key = $this->vstack[$len][0] === '' ? '_empty_' : $this->vstack[$len][0];
}
else {
$key = $this->vstack[$len][0];
}
if ($this->flags & self::DETECT_KEY_CONFLICTS && isset($this->vstack[$len - 2]->{$key})) {
$errStr = 'Parse error on line ' . ($yylineno + 1) . ":\n";
$errStr .= $this->lexer
->showPosition() . "\n";
$errStr .= "Duplicate key: " . $this->vstack[$len][0];
throw new DuplicateKeyException($errStr, $this->vstack[$len][0], array(
'line' => $yylineno + 1,
));
}
if ($this->flags & self::ALLOW_DUPLICATE_KEYS && isset($this->vstack[$len - 2]->{$key})) {
$duplicateCount = 1;
do {
$duplicateKey = $key . '.' . $duplicateCount++;
} while (isset($this->vstack[$len - 2]->{$duplicateKey}));
$this->vstack[$len - 2]->{$duplicateKey} = $this->vstack[$len][1];
}
elseif ($this->flags & self::ALLOW_DUPLICATE_KEYS_TO_ARRAY && isset($this->vstack[$len - 2]->{$key})) {
if (!isset($this->vstack[$len - 2]->{$key}->__duplicates__)) {
$this->vstack[$len - 2]->{$key} = (object) array(
'__duplicates__' => array(
$this->vstack[$len - 2]->{$key},
),
);
}
$this->vstack[$len - 2]->{$key}->__duplicates__[] = $this->vstack[$len][1];
}
else {
$this->vstack[$len - 2]->{$key} = $this->vstack[$len][1];
}
}
break;
case 18:
$token = array();
break;
case 19:
$token = $this->vstack[$len - 1];
break;
case 20:
$token = array(
$this->vstack[$len],
);
break;
case 21:
assert(\is_array($this->vstack[$len - 2]));
$this->vstack[$len - 2][] = $this->vstack[$len];
$token = $this->vstack[$len - 2];
break;
}
return array(
$token,
new Undefined(),
);
}