A pure PHP substitute for nikic/php-ast, using nikic/php-parser. Can also be used to generate php-ast trees, even for files with some types of syntax errors.
This converts ASTs(Abstract Syntax Trees) from PHP-Parser to php-ast. It can be used as a PHP-only implementation of php-ast. It can alternatively be used as a best-effort parser for syntactically valid PHP code.
Also see https://github.com/TysonAndre/tolerant-php-parser-to-php-ast (in progress, may have better results)
Supported php-ast AST versions: 40, 45, 50
No tests are failing
- Need to normalize namespaces (Mostly done)
- The test suite this is based off of covers common cases for Phan, but edge cases still remain. See https://github.com/TysonAndre/php-parser-to-php-ast/issues/4
- See https://github.com/nikic/php-ast/issues/78
- Translate PhpParser exception to a
Using it as a slow substitute for php-ast
Using it as an error-tolerant substitute for php-ast: (e.g. for use in IDEs)
- There are currently two modes: omitting errors and adding placeholders (e.g.
- Omitting errors only handles some common cases that come up while editing a file.
- Placeholders may change in the future.
- If performance is an issue, cache previous results for a file's contents (in combination with the version used to generate the file
To run unit tests, you must install nikic/php-ast. A version supporting AST versions 40 and/or 50 should be installed (
~0.1.5 is preferred)
- Then run
- https://github.com/Microsoft/tolerant-php-parser/issues/113 See https://github.com/tysonandre/tolerant-php-parser-to-php-ast (The library to convert between AST formats is broken(not finished implementing) and inefficient, waiting for stable API for tolerant-php-parser)