Skip to content

Commit

Permalink
Merge pull request #45 from xp-framework/feature/property-hooks
Browse files Browse the repository at this point in the history
Implement property hooks syntax
  • Loading branch information
thekid committed Jun 15, 2024
2 parents f5cc405 + 6bfe8c0 commit 5003111
Show file tree
Hide file tree
Showing 41 changed files with 234 additions and 75 deletions.
4 changes: 2 additions & 2 deletions src/main/php/lang/ast/nodes/Annotations.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ public function getIterator(): Traversable {
}

/** @return iterable */
public function children() {
foreach ($this->named as $annotation) {
public function &children() {
foreach ($this->named as &$annotation) {
yield $annotation;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/php/lang/ast/nodes/ArrayLiteral.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public function __construct($values, $line= -1) {
}

/** @return iterable */
public function children() {
foreach ($this->values as $pair) {
public function &children() {
foreach ($this->values as &$pair) {
if (null !== $pair[0]) yield $pair[0];
yield $pair[1];
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/php/lang/ast/nodes/Assignment.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ public function __construct($variable, $operator, $expression, $line= -1) {
}

/** @return iterable */
public function children() { return [$this->variable, $this->expression]; }
public function children() { return [&$this->variable, &$this->expression]; }
}
2 changes: 1 addition & 1 deletion src/main/php/lang/ast/nodes/BinaryExpression.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ public function __construct($left, $operator, $right, $line= -1) {
}

/** @return iterable */
public function children() { return [$this->left, $this->right]; }
public function children() { return [&$this->left, &$this->right]; }

}
2 changes: 1 addition & 1 deletion src/main/php/lang/ast/nodes/Braced.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ public function __construct($expression, $line= -1) {
}

/** @return iterable */
public function children() { return [$this->expression]; }
public function children() { return [&$this->expression]; }
}
2 changes: 1 addition & 1 deletion src/main/php/lang/ast/nodes/BreakStatement.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ public function __construct($expression= null, $line= -1) {
}

/** @return iterable */
public function children() { return $this->expression ? [$this->expression] : []; }
public function children() { return $this->expression ? [&$this->expression] : []; }
}
2 changes: 1 addition & 1 deletion src/main/php/lang/ast/nodes/CallableExpression.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ public function __construct($expression, $line= -1) {
}

/** @return iterable */
public function children() { return [$this->expression]; }
public function children() { return [&$this->expression]; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ public function __construct($type, $line= -1) {
}

/** @return iterable */
public function children() { return [$this->type]; }
public function children() { return [&$this->type]; }
}
4 changes: 2 additions & 2 deletions src/main/php/lang/ast/nodes/CaseLabel.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ public function __construct($expression, $body, $line= -1) {
}

/** @return iterable */
public function children() {
public function &children() {
if (null !== $this->expression) {
yield $this->expression;
}
foreach ($this->body as $node) {
foreach ($this->body as &$node) {
yield $node;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/php/lang/ast/nodes/CastExpression.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ public function __construct($type, $expression, $line= -1) {
}

/** @return iterable */
public function children() { return [$this->expression]; }
public function children() { return [&$this->expression]; }
}
6 changes: 1 addition & 5 deletions src/main/php/lang/ast/nodes/CatchStatement.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,5 @@ public function __construct($types, $variable, $body, $line= -1) {
}

/** @return iterable */
public function children() {
foreach ($this->body as $element) {
yield $element;
}
}
public function children() { return $this->body; }
}
4 changes: 1 addition & 3 deletions src/main/php/lang/ast/nodes/ContinueStatement.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,5 @@ public function __construct($expression= null, $line= -1) {
}

/** @return iterable */
public function children() {
return $this->expression ? [$this->expression] : [];
}
public function children() { return $this->expression ? [&$this->expression] : []; }
}
4 changes: 2 additions & 2 deletions src/main/php/lang/ast/nodes/DoLoop.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public function __construct($expression, $body, $line= -1) {
}

/** @return iterable */
public function children() {
public function &children() {
yield $this->expression;
foreach ($this->body as $element) {
foreach ($this->body as &$element) {
yield $element;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/php/lang/ast/nodes/Expression.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ public function __construct($inline, $line= -1) {
}

/** @return iterable */
public function children() { return [$this->inline]; }
public function children() { return [&$this->inline]; }
}
10 changes: 5 additions & 5 deletions src/main/php/lang/ast/nodes/ForLoop.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ public function __construct($initialization, $condition, $loop, $body, $line= -1
}

/** @return iterable */
public function children() {
foreach ($this->initialization as $element) {
public function &children() {
foreach ($this->initialization as &$element) {
yield $element;
}
foreach ($this->condition as $element) {
foreach ($this->condition as &$element) {
yield $element;
}
foreach ($this->loop as $element) {
foreach ($this->loop as &$element) {
yield $element;
}
foreach ($this->body as $element) {
foreach ($this->body as &$element) {
yield $element;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/php/lang/ast/nodes/ForeachLoop.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ public function __construct($expression, $key, $value, $body, $line= -1) {
}

/** @return iterable */
public function children() {
public function &children() {
yield $this->expression;
if ($this->key) {
yield $this->key;
}
yield $this->value;
foreach ($this->body as $element) {
foreach ($this->body as &$element) {
yield $element;
}
}
Expand Down
17 changes: 17 additions & 0 deletions src/main/php/lang/ast/nodes/Hook.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php namespace lang\ast\nodes;

use lang\ast\Node;

class Hook extends Node {
public $kind= 'hook';
public $modifiers, $type, $expression, $byref, $parameter;

public function __construct($modifiers, $type, $expression, $byref= false, $parameter= null, $line= -1) {
$this->modifiers= $modifiers;
$this->type= $type;
$this->expression= $expression;
$this->byref= $byref;
$this->parameter= $parameter;
$this->line= $line;
}
}
6 changes: 3 additions & 3 deletions src/main/php/lang/ast/nodes/IfStatement.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ public function __construct($expression, $body, $otherwise= null, $line= -1) {
}

/** @return iterable */
public function children() {
public function &children() {
yield $this->expression;
foreach ($this->body as $node) {
foreach ($this->body as &$node) {
yield $node;
}
foreach ((array)$this->otherwise as $node) {
foreach ((array)$this->otherwise as &$node) {
yield $node;
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/main/php/lang/ast/nodes/InstanceExpression.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,5 @@ public function __construct($expression, $member, $line= -1) {
}

/** @return iterable */
public function children() {
return [$this->expression, $this->member];
}
public function children() { return [&$this->expression, &$this->member]; }
}
2 changes: 1 addition & 1 deletion src/main/php/lang/ast/nodes/InstanceOfExpression.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ public function __construct($expression, $type, $line= 1) {
}

/** @return iterable */
public function children() { return [$this->expression]; }
public function children() { return [&$this->expression]; }
}
4 changes: 2 additions & 2 deletions src/main/php/lang/ast/nodes/InvokeExpression.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public function __construct($expression, $arguments, $line= -1) {
}

/** @return iterable */
public function children() {
public function &children() {
yield $this->expression;
foreach ($this->arguments as $element) {
foreach ($this->arguments as &$element) {
yield $element;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/php/lang/ast/nodes/LambdaExpression.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ public function __construct($signature, $body, $static= false, $line= -1) {

/** @return iterable */
public function children() {
return is_array($this->body) ? $this->body : [$this->body];
return is_array($this->body) ? $this->body : [&$this->body];
}
}
4 changes: 2 additions & 2 deletions src/main/php/lang/ast/nodes/MatchCondition.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public function __construct($expressions, $body, $line= -1) {
}

/** @return iterable */
public function children() {
foreach ($this->expressions as $expression) {
public function &children() {
foreach ($this->expressions as &$expression) {
yield $expression;
}
yield $this->body;
Expand Down
4 changes: 2 additions & 2 deletions src/main/php/lang/ast/nodes/MatchExpression.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ public function __construct($expression, $cases, $default, $line= -1) {
}

/** @return iterable */
public function children() {
public function &children() {
if (null !== $this->expression) yield $this->expression;
foreach ($this->cases as $element) {
foreach ($this->cases as &$element) {
yield $element;
}
if (null !== $this->default) yield $this->default;
Expand Down
2 changes: 1 addition & 1 deletion src/main/php/lang/ast/nodes/OffsetExpression.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ public function __construct($expression, $offset, $line= -1) {

/** @return iterable */
public function children() {
return $this->offset ? [$this->expression, $this->offset] : [$this->expression];
return $this->offset ? [&$this->expression, &$this->offset] : [&$this->expression];
}
}
1 change: 1 addition & 0 deletions src/main/php/lang/ast/nodes/Property.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
class Property extends Annotated implements Member {
public $kind= 'property';
public $name, $modifiers, $expression, $type;
public $hooks= null;

public function __construct($modifiers, $name, $type, $expression= null, $annotations= null, $comment= null, $line= -1) {
$this->modifiers= $modifiers;
Expand Down
4 changes: 1 addition & 3 deletions src/main/php/lang/ast/nodes/ReturnStatement.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,5 @@ public function __construct($expression= null, $line= -1) {
}

/** @return iterable */
public function children() {
return $this->expression ? [$this->expression] : [];
}
public function children() { return $this->expression ? [&$this->expression] : []; }
}
2 changes: 1 addition & 1 deletion src/main/php/lang/ast/nodes/ScopeExpression.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ public function __construct($type, $member, $line= -1) {

/** @return iterable */
public function children() {
return $this->type instanceof parent ? [$this->type, $this->member] : [$this->member];
return $this->type instanceof parent ? [&$this->type, &$this->member] : [&$this->member];
}
}
4 changes: 2 additions & 2 deletions src/main/php/lang/ast/nodes/SwitchStatement.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public function __construct($expression, $cases, $line= -1) {
}

/** @return iterable */
public function children() {
public function &children() {
yield $this->expression;
foreach ($this->cases as $element) {
foreach ($this->cases as &$element) {
yield $element;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/php/lang/ast/nodes/TernaryExpression.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function __construct($condition, $expression, $otherwise, $line= -1) {
}

/** @return iterable */
public function children() {
public function &children() {
yield $this->condition;
if ($this->expression) {
yield $this->expression;
Expand Down
4 changes: 1 addition & 3 deletions src/main/php/lang/ast/nodes/ThrowExpression.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,5 @@ public function __construct($expression, $line= -1) {
}

/** @return iterable */
public function children() {
return [$this->expression];
}
public function children() { return [&$this->expression]; }
}
4 changes: 1 addition & 3 deletions src/main/php/lang/ast/nodes/ThrowStatement.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,5 @@ public function __construct($expression, $line= -1) {
}

/** @return iterable */
public function children() {
return [$this->expression];
}
public function children() { return [&$this->expression]; }
}
6 changes: 3 additions & 3 deletions src/main/php/lang/ast/nodes/TryStatement.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ public function __construct($body, $catches, $finally, $line= -1) {
}

/** @return iterable */
public function children() {
foreach ($this->body as $element) {
public function &children() {
foreach ($this->body as &$element) {
yield $element;
}
foreach ($this->catches as $catch) {
foreach ($this->catches as &$catch) {
yield $catch;
}
if ($this->finally) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/php/lang/ast/nodes/UnaryExpression.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ public function __construct($kind, $expression, $operator, $line= -1) {
}

/** @return iterable */
public function children() { return [$this->expression]; }
public function children() { return [&$this->expression]; }
}
2 changes: 1 addition & 1 deletion src/main/php/lang/ast/nodes/UnpackExpression.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ public function __construct($expression, $line= -1) {
}

/** @return iterable */
public function children() { return [$this->expression]; }
public function children() { return [&$this->expression]; }
}
6 changes: 3 additions & 3 deletions src/main/php/lang/ast/nodes/UsingStatement.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ public function __construct($arguments, $body, $line= -1) {
}

/** @return iterable */
public function children() {
foreach ($this->arguments as $element) {
public function &children() {
foreach ($this->arguments as &$element) {
yield $element;
}
foreach ($this->body as $element) {
foreach ($this->body as &$element) {
yield $element;
}
}
Expand Down
Loading

0 comments on commit 5003111

Please sign in to comment.