From 086c1b1c66edbd4cba3a2167c38aaaf950496998 Mon Sep 17 00:00:00 2001 From: Kennedy Tedesco Date: Sat, 14 Dec 2024 19:20:29 -0300 Subject: [PATCH] Chore --- phpstan.neon | 4 +++- src/Evaluator/EvalCallExpression.php | 3 +-- src/Lexer/Lexer.php | 19 ++++++++++++++----- src/Object/NullObject.php | 4 ++-- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index d7ffb98..9cfc87c 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -5,4 +5,6 @@ parameters: - src level: max inferPrivatePropertyTypeFromConstructor: true - checkUninitializedProperties: true \ No newline at end of file + checkUninitializedProperties: true + ignoreErrors: + - '#Binary operation .* between mixed and mixed results in an error\.#' \ No newline at end of file diff --git a/src/Evaluator/EvalCallExpression.php b/src/Evaluator/EvalCallExpression.php index e9c1bd1..4632f10 100644 --- a/src/Evaluator/EvalCallExpression.php +++ b/src/Evaluator/EvalCallExpression.php @@ -5,7 +5,6 @@ namespace Monkey\Evaluator; use Monkey\Ast\Expressions\CallExpression; -use Monkey\Ast\Expressions\IdentifierExpression; use Monkey\Object\BuiltinFunctionObject; use Monkey\Object\ErrorObject; use Monkey\Object\FunctionObject; @@ -57,6 +56,7 @@ public function applyFunction( } if ($monkeyObject instanceof BuiltinFunctionObject) { + /** @phpstan-ignore-next-line */ return call_user_func($monkeyObject->value, ...$args); } @@ -70,7 +70,6 @@ public function extendFunctionEnv(FunctionObject $functionObject, array $args): { $environment = new Environment($functionObject->environment); - /** @var IdentifierExpression $identifierExpression */ foreach ($functionObject->parameters as $index => $identifierExpression) { $environment->set($identifierExpression->value, $args[$index]); } diff --git a/src/Lexer/Lexer.php b/src/Lexer/Lexer.php index 5af8dfc..d4616c3 100644 --- a/src/Lexer/Lexer.php +++ b/src/Lexer/Lexer.php @@ -58,12 +58,21 @@ public function nextToken(): Token $this->curChar->is('"') => $this->makeTokenAndAdvance(TokenType::STRING, $this->readString()), - $this->curChar->isLetter() => Token::from( - TokenType::fromChar($identifier = $this->readIdentifier()) ?? TokenType::IDENT, - $identifier, - ), + $this->curChar->isLetter() => (function (): Token { + $identifier = $this->readIdentifier(); + + $type = TokenType::fromChar($identifier) ?? TokenType::IDENT; + + return Token::from($type, $identifier); + })(), + + $this->curChar->isDigit() => (function (): Token { + $number = $this->readNumber(); + + $type = ctype_digit($number) ? TokenType::INT : TokenType::FLOAT; - $this->curChar->isDigit() => Token::from(ctype_digit($number = $this->readNumber()) ? TokenType::INT : TokenType::FLOAT, $number), + return Token::from($type, $number); + })(), $this->curChar->is(self::EOF) => Token::from(TokenType::EOF, self::EOF), diff --git a/src/Object/NullObject.php b/src/Object/NullObject.php index 6119ea3..476592f 100644 --- a/src/Object/NullObject.php +++ b/src/Object/NullObject.php @@ -7,13 +7,13 @@ final readonly class NullObject extends MonkeyObject { public function __construct( - public null $value = null, + public null $value, ) { } public static function instance(): self { - return new self(); + return new self(null); } public function type(): int