Skip to content

Commit

Permalink
TokenStream: $tokens is readonly
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Apr 28, 2024
1 parent 4cca7ad commit e70439a
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/Neon/Parser.php
Expand Up @@ -254,7 +254,7 @@ private function initLines(): void
{
$this->posToLine = [];
$line = 1;
foreach ($this->tokens->getTokens() as $token) {
foreach ($this->tokens->tokens as $token) {
$this->posToLine[] = $line;
$line += substr_count($token->value, "\n");
}
Expand Down
9 changes: 1 addition & 8 deletions src/Neon/TokenStream.php
Expand Up @@ -18,7 +18,7 @@ final class TokenStream

public function __construct(
/** @var Token[] */
public array $tokens,
public /*readonly*/ array $tokens,
) {
}

Expand All @@ -35,13 +35,6 @@ public function seek(int $index): void
}


/** @return Token[] */
public function getTokens(): array
{
return $this->tokens;
}


public function is(int|string ...$types): bool
{
while (in_array($this->tokens[$this->index]->type ?? null, [Token::Comment, Token::Whitespace], strict: true)) {
Expand Down
2 changes: 1 addition & 1 deletion tests/Neon/Parser.nodes.phpt
Expand Up @@ -57,7 +57,7 @@ Assert::matchFile(
$traverser = new Traverser;
$traverser->traverse($node, function (Node $node) use ($stream) {
@$node->code = ''; // dynamic property is deprecated
foreach (array_slice($stream->getTokens(), $node->startTokenPos, $node->endTokenPos - $node->startTokenPos + 1) as $token) {
foreach (array_slice($stream->tokens, $node->startTokenPos, $node->endTokenPos - $node->startTokenPos + 1) as $token) {
$node->code .= $token->value;
}

Expand Down

0 comments on commit e70439a

Please sign in to comment.