Skip to content

Commit

Permalink
Chore
Browse files Browse the repository at this point in the history
  • Loading branch information
KennedyTedesco committed Dec 14, 2024
1 parent b67ec5d commit 086c1b1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
4 changes: 3 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ parameters:
- src
level: max
inferPrivatePropertyTypeFromConstructor: true
checkUninitializedProperties: true
checkUninitializedProperties: true
ignoreErrors:
- '#Binary operation .* between mixed and mixed results in an error\.#'
3 changes: 1 addition & 2 deletions src/Evaluator/EvalCallExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -57,6 +56,7 @@ public function applyFunction(
}

if ($monkeyObject instanceof BuiltinFunctionObject) {
/** @phpstan-ignore-next-line */
return call_user_func($monkeyObject->value, ...$args);
}

Expand All @@ -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]);
}
Expand Down
19 changes: 14 additions & 5 deletions src/Lexer/Lexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),

Expand Down
4 changes: 2 additions & 2 deletions src/Object/NullObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 086c1b1

Please sign in to comment.