-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b6fba9e
commit 5e2405f
Showing
20 changed files
with
944 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Eventjet\Ausdruck; | ||
|
||
use Eventjet\Ausdruck\Parser\Span; | ||
|
||
use function get_debug_type; | ||
use function is_object; | ||
use function property_exists; | ||
use function sprintf; | ||
|
||
/** | ||
* @internal | ||
* @psalm-internal Eventjet\Ausdruck | ||
*/ | ||
final class FieldAccess extends Expression | ||
{ | ||
public function __construct( | ||
public readonly Expression $struct, | ||
public readonly string $field, | ||
private readonly Span $location, | ||
) { | ||
} | ||
|
||
public function __toString(): string | ||
{ | ||
return sprintf('%s.%s', $this->struct, $this->field); | ||
} | ||
|
||
public function location(): Span | ||
{ | ||
return $this->location; | ||
} | ||
|
||
public function evaluate(Scope $scope): mixed | ||
{ | ||
$struct = $this->struct->evaluate($scope); | ||
if (!is_object($struct)) { | ||
throw new EvaluationError(sprintf('Expected object, got %s', get_debug_type($struct))); | ||
} | ||
if (!property_exists($struct, $this->field)) { | ||
throw new EvaluationError(sprintf('Unknown field "%s"', $this->field)); | ||
} | ||
/** @phpstan-ignore-next-line property.dynamicName */ | ||
return $struct->{$this->field}; | ||
} | ||
|
||
public function equals(Expression $other): bool | ||
{ | ||
return $other instanceof self | ||
&& $this->struct->equals($other->struct) | ||
&& $this->field === $other->field; | ||
} | ||
|
||
public function getType(): Type | ||
{ | ||
return $this->struct->getType()->fields[$this->field]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Eventjet\Ausdruck\Parser; | ||
|
||
/** | ||
* @psalm-internal Eventjet\Ausdruck\Parser | ||
*/ | ||
enum Delimiters | ||
{ | ||
case CurlyBraces; | ||
case AngleBrackets; | ||
|
||
public function start(): string | ||
{ | ||
return match ($this) { | ||
self::CurlyBraces => '{ ', | ||
self::AngleBrackets => '<', | ||
}; | ||
} | ||
|
||
public function end(): string | ||
{ | ||
return match ($this) { | ||
self::CurlyBraces => ' }', | ||
self::AngleBrackets => '>', | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.