PHPackages                             xp-framework/ast - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. xp-framework/ast

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

xp-framework/ast
================

AST for the XP Framework

v12.0.0(3mo ago)3340.5k↓34.3%[4 PRs](https://github.com/xp-framework/ast/pulls)3BSD-3-ClausePHPPHP &gt;=7.4.0CI passing

Since Nov 6Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/xp-framework/ast)[ Packagist](https://packagist.org/packages/xp-framework/ast)[ Docs](http://xp-framework.net/)[ RSS](/packages/xp-framework-ast/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (2)Versions (80)Used By (3)

XP AST
======

[](#xp-ast)

[![Build status on GitHub](https://github.com/xp-framework/ast/workflows/Tests/badge.svg)](https://github.com/xp-framework/ast/actions)[![XP Framework Module](https://raw.githubusercontent.com/xp-framework/web/master/static/xp-framework-badge.png)](https://github.com/xp-framework/core)[![BSD Licence](https://raw.githubusercontent.com/xp-framework/web/master/static/licence-bsd.png)](https://github.com/xp-framework/core/blob/master/LICENCE.md)[![Requires PHP 7.4+](https://raw.githubusercontent.com/xp-framework/web/master/static/php-7_4plus.svg)](http://php.net/)[![Supports PHP 8.0+](https://raw.githubusercontent.com/xp-framework/web/master/static/php-8_0plus.svg)](http://php.net/)[![Latest Stable Version](https://camo.githubusercontent.com/d6124873b0b69446892695f6d5cdefd63dfd86361b620b11376955b4db450158/68747470733a2f2f706f7365722e707567782e6f72672f78702d6672616d65776f726b2f6173742f76657273696f6e2e737667)](https://packagist.org/packages/xp-framework/ast)

Abstract syntax tree library used for [XP Compiler](https://github.com/xp-framework/compiler).

Example
-------

[](#example)

```
use lang\ast\{Language, Tokens};

$tree= Language::named('PHP')->parse(new Tokens('echo PHP_VERSION;'))->tree();

// lang.ast.ParseTree(source: (string))@{
//   scope => lang.ast.Scope {
//     parent => null
//     package => null
//     imports => []
//     types => []
//   }
//   children => [lang.ast.nodes.EchoStatement {
//     kind => "echo"
//     expressions => [lang.ast.nodes.Literal {
//       kind => "literal"
//       expression => "PHP_VERSION"
//       line => 1
//     }]
//     line => 1
//   }]
// }
```

Compile-time metaprogramming
----------------------------

[](#compile-time-metaprogramming)

Register transformations by creating classes inside the `lang.ast.syntax.php` package - see [xp-framework/rfc#327](https://github.com/xp-framework/rfc/issues/327)

```
namespace lang\ast\syntax\php;

use lang\ast\Code;
use lang\ast\nodes\{Method, Signature};
use lang\ast\syntax\Extension;
use codegen\Getters;

class CreateGetters implements Extension {

  public function setup($language, $emitter) {
    $emitter->transform('class', function($codegen, $class) {
      if ($class->annotation(Getters::class)) {
        foreach ($class->properties() as $property) {
          $class->declare(new Method(
            ['public'],
            $property->name,
            new Signature([], $property->type),
            [new Code('return $this->'.$property->name)]
          ));
        }
      }
      return $class;
    });
  }
}
```

When compiling the following sourcecode, getters for the `id` and `name` members will automatically be added.

```
use codegen\Getters;

#[Getters]
class Person {
  private int $id;
  private string $name;

  public function __construct(int $id, string $name) {
    $this->id= $id;
    $this->name= $name;
  }
}
```

###  Health Score

56

—

FairBetter than 98% of packages

Maintenance82

Actively maintained with recent releases

Popularity35

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity78

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~42 days

Recently: every ~65 days

Total

73

Last Release

93d ago

Major Versions

v7.7.2 → v8.0.02022-01-06

v8.2.0 → v9.0.02022-11-06

v9.2.7 → v10.0.02023-04-08

v10.3.1 → v11.0.02024-03-23

v11.8.0 → v12.0.02026-02-14

PHP version history (3 changes)v1.0.0PHP &gt;=5.6.0

v4.0.0PHP &gt;=7.0.0

v11.0.0PHP &gt;=7.4.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/07d18d882c8b4aaf3466432f64018214f2771eda333202175431ee7233795376?d=identicon)[thekid](/maintainers/thekid)

---

Top Contributors

[![thekid](https://avatars.githubusercontent.com/u/696742?v=4)](https://github.com/thekid "thekid (510 commits)")

---

Tags

astcode-generationcompilermetaprogrammingphpphp-parserphp7php8php8-featuresxp-frameworkmodulexp

### Embed Badge

![Health badge](/badges/xp-framework-ast/health.svg)

```
[![Health](https://phpackages.com/badges/xp-framework-ast/health.svg)](https://phpackages.com/packages/xp-framework-ast)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
