Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/Ast/Assignment.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@
namespace PhpScript\Ast;

use PhpScript\Contracts\Node;
use PhpScript\Core\Token;

final readonly class Assignment implements Node
final readonly class Assignment extends BaseNode
{
public function __construct(
public Variable $variable,
public Node $expression,
) {}
?Token $token = null,
) {
parent::__construct($token);
}

public function toArray(): array
{
Expand Down
18 changes: 18 additions & 0 deletions src/Ast/BaseNode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace PhpScript\Ast;

use PhpScript\Contracts\Node;
use PhpScript\Core\Token;

abstract readonly class BaseNode implements Node
{
public function __construct(private ?Token $token = null) {}

public function getToken(): ?Token
{
return $this->token;
}
}
8 changes: 6 additions & 2 deletions src/Ast/BinaryOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@
namespace PhpScript\Ast;

use PhpScript\Contracts\Node;
use PhpScript\Core\Token;
use PhpScript\Core\TokenType;

final readonly class BinaryOperation implements Node
final readonly class BinaryOperation extends BaseNode
{
public function __construct(
public Node $left,
public TokenType $operator,
public Node $right,
) {}
?Token $token = null,
) {
parent::__construct($token);
}

public function toArray(): array
{
Expand Down
8 changes: 6 additions & 2 deletions src/Ast/EchoStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@
namespace PhpScript\Ast;

use PhpScript\Contracts\Node;
use PhpScript\Core\Token;

final readonly class EchoStatement implements Node
final readonly class EchoStatement extends BaseNode
{
public function __construct(
public Node $expression,
) {}
?Token $token = null,
) {
parent::__construct($token);
}

public function toArray(): array
{
Expand Down
9 changes: 6 additions & 3 deletions src/Ast/Identifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@

namespace PhpScript\Ast;

use PhpScript\Contracts\Node;
use PhpScript\Core\Token;

final readonly class Identifier implements Node
final readonly class Identifier extends BaseNode
{
public function __construct(
public string $name,
) {}
?Token $token = null,
) {
parent::__construct($token);
}

public function toArray(): array
{
Expand Down
9 changes: 6 additions & 3 deletions src/Ast/Literal.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@

namespace PhpScript\Ast;

use PhpScript\Contracts\Node;
use PhpScript\Core\Token;

final readonly class Literal implements Node
final readonly class Literal extends BaseNode
{
public function __construct(
public mixed $value,
) {}
?Token $token = null,
) {
parent::__construct($token);
}

public function toArray(): array
{
Expand Down
8 changes: 6 additions & 2 deletions src/Ast/MemberAccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@
namespace PhpScript\Ast;

use PhpScript\Contracts\Node;
use PhpScript\Core\Token;

final readonly class MemberAccess implements Node
final readonly class MemberAccess extends BaseNode
{
public function __construct(
public Node $object,
public Identifier $property,
) {}
?Token $token = null,
) {
parent::__construct($token);
}

public function toArray(): array
{
Expand Down
9 changes: 7 additions & 2 deletions src/Ast/NoOp.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@

namespace PhpScript\Ast;

use PhpScript\Contracts\Node;
use PhpScript\Core\Token;

/**
* Represents a no-operation statement (e.g., an empty statement ';').
*/
final readonly class NoOp implements Node
final readonly class NoOp extends BaseNode
{
public function __construct(?Token $token = null)
{
parent::__construct($token);
}

public function toArray(): array
{
return [
Expand Down
6 changes: 4 additions & 2 deletions src/Ast/Program.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@

use PhpScript\Contracts\Node;

final readonly class Program implements Node
final readonly class Program extends BaseNode
{
/**
* @param Node[] $statements
*/
public function __construct(
public array $statements,
) {}
) {
parent::__construct();
}

public function toArray(): array
{
Expand Down
9 changes: 6 additions & 3 deletions src/Ast/Variable.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@

namespace PhpScript\Ast;

use PhpScript\Contracts\Node;
use PhpScript\Core\Token;

final readonly class Variable implements Node
final readonly class Variable extends BaseNode
{
public function __construct(
public string $name,
) {}
?Token $token = null,
) {
parent::__construct($token);
}

public function toArray(): array
{
Expand Down
4 changes: 4 additions & 0 deletions src/Contracts/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@

namespace PhpScript\Contracts;

use PhpScript\Core\Token;

interface Node
{
public function getToken(): ?Token;

/**
* @return array<string, mixed>
*/
Expand Down
Loading