Traverse key before buffering token

This commit is contained in:
Andrea Marco Sartori 2022-12-02 22:27:49 +10:00
parent fa4e71f111
commit d4b8b5037b
2 changed files with 15 additions and 7 deletions

View File

@ -37,13 +37,7 @@ class ScalarString extends Token
{
parent::mutateState($state);
$this->isKey = $state->expectsKey();
if ($this->isKey && $state->shouldTrackTree()) {
$state->traverseKey($this);
}
if ($this->isKey) {
if ($this->isKey = $state->expectsKey()) {
$state->doNotExpectKey();
}
}

View File

@ -58,6 +58,16 @@ abstract class Token implements Stringable
return ($this->type() | Tokens::VALUE_SCALAR) == Tokens::VALUE_SCALAR;
}
/**
* Determine whether the token is a string
*
* @return bool
*/
public function isString(): bool
{
return ($this->type() | Tokens::SCALAR_STRING) == Tokens::SCALAR_STRING;
}
/**
* Mutate the given state
*
@ -72,6 +82,10 @@ abstract class Token implements Stringable
$state->traverseArray();
}
if ($this->isString() && $state->expectsKey() && $state->shouldTrackTree()) {
$state->traverseKey($this);
}
if ($state->inRoot() && $state->shouldBufferToken($this)) {
$state->bufferToken($this);
}