Abstract syntax tree library used for Compile-time metaprogramming.
Register transformations to be used by the XP Compiler. This can be done in your library's module.xp, for instance.
use lang\ast\transform\Transformations;
use lang\ast\nodes\Method;
use lang\ast\nodes\Signature;
use lang\ast\Code;
Transformations::register('class', function($class) {
if ($class->value->annotation('getters')) {
foreach ($class->value->properties() as $property) {
$class->value->inject(new Method(
['public'],
$property->name,
new Signature([], $property->type),
[new Code('return $this->'.$property->name.';')]
));
}
}
yield $class;
});When compiling the following sourcecode, getters for the id and name members will automatically be added.
<?php
<<getters>>
class Person {
private int $id;
private string $name;
public function __construct(int $id, string $name) {
$this->id= $id;
$this->name= $name;
}
}




