https://github.com/loophp/phptree-ast-generator
Generates Abstrax Syntax Tree (AST) of a PHP script in DOT (Graphviz) or Image (PNG, JPG, SVG) formats.
https://github.com/loophp/phptree-ast-generator
abstract-syntax-tree ast graph tree
Last synced: 8 months ago
JSON representation
Generates Abstrax Syntax Tree (AST) of a PHP script in DOT (Graphviz) or Image (PNG, JPG, SVG) formats.
- Host: GitHub
- URL: https://github.com/loophp/phptree-ast-generator
- Owner: loophp
- License: mit
- Created: 2020-03-02T19:49:11.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2024-10-09T14:19:41.000Z (over 1 year ago)
- Last Synced: 2025-04-18T21:27:28.914Z (9 months ago)
- Topics: abstract-syntax-tree, ast, graph, tree
- Language: PHP
- Size: 416 KB
- Stars: 9
- Watchers: 2
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
[](https://packagist.org/packages/loophp/phptree-ast-generator)
[](https://packagist.org/packages/loophp/phptree-ast-generator)
[](https://packagist.org/packages/loophp/phptree-ast-generator)
[](https://github.com/loophp/phptree-ast-generator/actions)
[](https://scrutinizer-ci.com/g/loophp/phptree-ast-generator/?branch=master)
[](https://scrutinizer-ci.com/g/loophp/phptree-ast-generator/?branch=master)
[](https://stryker-mutator.github.io)
[](https://packagist.org/packages/loophp/phptree-ast-generator)
[](https://paypal.me/loophp)
# PHPTree AST Generator
## Description
An AST generator based on [loophp/phptree](https://packagist.org/packages/loophp/phptree).

## Requirements
* PHP >= 7.1
* A PHP Parser:
* [nikic/php-ast](https://github.com/nikic/php-ast)
* [nikic/php-parser](https://github.com/nikic/php-parser)
* [microsoft/tolerant-php-parser](https://github.com/microsoft/tolerant-php-parser)
## Installation
```composer require loophp/phptree-ast-generator```
## Usage
Very basic usage
```shell script
./path/to/bin/ast generate /path/to/php/file.php
```
To generate the `dot` script for Graphviz
```shell script
./path/to/bin/ast generate src/Command/Generator.php
```
Use the `-c` option to generate a fancy export, user-friendly and less verbose.
```shell script
./path/to/bin/ast generate -c src/Command/Generator.php
```
To generate an image
```shell script
./path/to/bin/ast generate -c -t image -f png -d graph.png src/Command/Generator.php
```
The generator supports 3 PHP parsers:
* [nikic/php-ast](https://github.com/nikic/php-ast)
* [nikic/php-parser](https://github.com/nikic/php-parser)
* [microsoft/tolerant-php-parser](https://github.com/microsoft/tolerant-php-parser)
Use the `-p` option to change it, default is `nikic`.
```shell script
./path/to/bin/ast generate -p microsoft -t image -d graph.svg src/Command/Generator.php
```
You will find more documentation within the help of the command:
```shell script
./path/to/bin/ast generate -h
```
## Contributing
Feel free to contribute to this library by sending Github pull requests. I'm quite reactive :-)