A PHP parser written in PHP, handles partial/illegal input

0.1.5 2018-08-17 19:01 UTC

This package is auto-updated.

Last update: 2020-07-16 17:40:26 UTC


This is a PHP 7 parser written in PHP. It handles some partial and illegal code, producing best-effort partial syntax tree. Its purpose is to simplify static code analysis and manipulation.

It's error reporting is not complete though, i.e. it may silently accept illegal PHP input.

As this is just a parser replacement for PHP Parser, go there for actual documentation.


The preferred installation method is composer:

php composer.phar require tsufeki/php-lenient-parser


Use the factory to get an instance of parser:

$parser = (new LenientParserFactory())->create();

Or provide your own lexer and options (no options are supported at the moment though):

$parser = (new LenientParserFactory())->create(LenientParserFactory::ONLY_PHP7, $lexer, $options);

Created parser is a drop-in replacement for php-parser.

Do not instantiate LenientParser directly, use the factory.


At the moment parsing of PHP 5 is not supported, only PHP 7.

Internally, the parser is implemented as a Pratt parser (also called "Top down operator precedence parser").


Same as php-parser, BSD - see LICENCE.

Test suite and CLI script (below bin/, test/ and test_old/) are borrowed from php-parser and modified.