From d4b8b5037bbbbfe265f65dbef31354c7f8fff337 Mon Sep 17 00:00:00 2001 From: Andrea Marco Sartori Date: Fri, 2 Dec 2022 22:27:49 +1000 Subject: [PATCH] Traverse key before buffering token --- src/Tokens/ScalarString.php | 8 +------- src/Tokens/Token.php | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/Tokens/ScalarString.php b/src/Tokens/ScalarString.php index f12cdc7..302abe6 100644 --- a/src/Tokens/ScalarString.php +++ b/src/Tokens/ScalarString.php @@ -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(); } } diff --git a/src/Tokens/Token.php b/src/Tokens/Token.php index dab84a9..bb6797d 100644 --- a/src/Tokens/Token.php +++ b/src/Tokens/Token.php @@ -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); }