PHPackages                             phptl/parser - 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. phptl/parser

Abandoned → [type-lang/parser](/?search=type-lang%2Fparser)Library[Parsing &amp; Serialization](/categories/parsing)

phptl/parser
============

Library for parsing and validating TypeLang syntax and converting it into AST nodes

1.6.0(9mo ago)511.6k2MITPHPPHP ^8.1CI passing

Since Feb 18Pushed 1mo ago2 watchersCompare

[ Source](https://github.com/php-type-language/parser)[ Packagist](https://packagist.org/packages/phptl/parser)[ RSS](/packages/phptl-parser/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (10)Dependencies (11)Versions (23)Used By (0)

[ ![](https://github.com/php-type-language/.github/raw/master/assets/dark.png?raw=true)](https://github.com/php-type-language) [![PHP 8.4+](https://camo.githubusercontent.com/af2e0a714f1a9910ed8ebb6d2915ebeb092c75ee8010fcfb2c92027ce2a01d6a/68747470733a2f2f706f7365722e707567782e6f72672f747970652d6c616e672f7061727365722f726571756972652f7068703f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/type-lang/parser) [![Latest Stable Version](https://camo.githubusercontent.com/cb1993596bdb6f4f1feb08ea630c2497d4ee8f18cd474083487ae553ce1ff8a3/68747470733a2f2f706f7365722e707567782e6f72672f747970652d6c616e672f7061727365722f76657273696f6e3f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/type-lang/parser) [![Latest Unstable Version](https://camo.githubusercontent.com/d3c82c61111c5e50c5d797c313606ee5caed89d72778e99c63b0e3d073e0ffba/68747470733a2f2f706f7365722e707567782e6f72672f747970652d6c616e672f7061727365722f762f756e737461626c653f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/type-lang/parser) [![License MIT](https://camo.githubusercontent.com/a12f170813bd021403cc6d70b62d6f2c6644d519e4d758ec3a01cac81c710a80/68747470733a2f2f706f7365722e707567782e6f72672f747970652d6c616e672f7061727365722f6c6963656e73653f7374796c653d666f722d7468652d6261646765)](https://raw.githubusercontent.com/php-type-language/parser/blob/master/LICENSE)

 [![](https://camo.githubusercontent.com/0042604e8393fe8fca9dbddc768e41b604d36b0dc349c7ba82af9400bf3f3985/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7068702d747970652d6c616e67756167652f7061727365722f74657374732e796d6c3f6c6162656c3d5465737473267374796c653d666c61742d737175617265266c6f676f3d756e706b67)](https://github.com/php-type-language/parser/actions/workflows/tests.yml)

---

The reference parser for **TypeLang** — a declarative type language inspired by static analyzers like [PHPStan](https://phpstan.org/) and [Psalm](https://psalm.dev/docs/).

It reads a type declaration string and builds an AST of `TypeLang\Type\*` nodes, checking the grammar along the way. The node classes themselves live in the separate [`type-lang/types`](https://packagist.org/packages/type-lang/types) package.

- Full documentation is [available at typelang.dev](https://typelang.dev).
- Language specification is [available here](https://typelang.dev/static/spec.html).

Installation
------------

[](#installation)

Install the package via [Composer](https://getcomposer.org):

```
composer require type-lang/parser
```

**Requirements:**

- PHP 8.4+

Usage
-----

[](#usage)

`TypeLang\Parser\TypeParser` is the entry point. Its `parse()` method turns a type declaration into a `TypeLang\Type\TypeNode`:

```
$parser = new TypeLang\Parser\TypeParser();

$type = $parser->parse('array{ key: int }');

var_dump($type);
// object(TypeLang\Type\NamedTypeNode) {
//   ["name"]   => "array"
//   ["fields"] => object(TypeLang\Type\Shape\FieldsListNode) { ... }
//   ...
// }
```

Every node exposes an `$offset` (byte offset in the source) plus a handful of properties describing its kind.

### Strict vs. Tolerant Parsing

[](#strict-vs-tolerant-parsing)

- `parse(): TypeNode` — strict mode; requires the whole input to be a valid type and throws a `ParserExceptionInterface` on the first error.
- `parseTolerant(): ParsedResult` — parses as much as it can and reports how far it consumed the source. Useful for phpdoc, where a type is followed by a free-text description.

```
$result = $parser->parseTolerant('int and some trailing description');

$result->type;   // TypeLang\Type\NamedTypeNode ("int")
$result->offset; // offset where parsing stopped
```

See the [documentation](https://typelang.dev) for feature toggling, visitors and name resolution.

###  Health Score

47

—

FairBetter than 93% of packages

Maintenance77

Regular maintenance activity

Popularity27

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 97.4% 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 ~41 days

Recently: every ~130 days

Total

22

Last Release

36d ago

Major Versions

1.6.0 → 2.0.0-beta12026-07-12

PHP version history (2 changes)1.0.0-beta1PHP ^8.1

2.0.0-beta1PHP ^8.4

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/150420?v=4)[Ruslan Sharipov](/maintainers/Serafim)[@serafim](https://github.com/serafim)

---

Top Contributors

[![SerafimArts](https://avatars.githubusercontent.com/u/2461257?v=4)](https://github.com/SerafimArts "SerafimArts (37 commits)")[![roxblnfk](https://avatars.githubusercontent.com/u/4152481?v=4)](https://github.com/roxblnfk "roxblnfk (1 commits)")

---

Tags

definitiondocblockgrammarparserphpphpdocphpdocumentorphpstanpsalmstricttagstype-systemtypesphpphpdoclanguageparser

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/phptl-parser/health.svg)

```
[![Health](https://phpackages.com/badges/phptl-parser/health.svg)](https://phpackages.com/packages/phptl-parser)
```

###  Alternatives

[doctrine/lexer

PHP Doctrine Lexer parser library that can be used in Top-Down, Recursive Descent Parsers.

11.2k980.3M171](/packages/doctrine-lexer)[type-lang/parser

Library for parsing and validating TypeLang syntax and converting it into AST nodes

5160.7k6](/packages/type-lang-parser)[simplehtmldom/simplehtmldom

A fast, simple and reliable HTML document parser for PHP.

1901.4M15](/packages/simplehtmldom-simplehtmldom)[corveda/php-sandbox

A PHP library that can be used to run PHP code in a sandboxed environment

238100.2k2](/packages/corveda-php-sandbox)[voku/simple-php-code-parser

Get a simple data structure from your php code.

487.6k8](/packages/voku-simple-php-code-parser)[leonelquinteros/php-toml

PHP parser for TOML language ( https://github.com/toml-lang/toml )

287.0k](/packages/leonelquinteros-php-toml)

PHPackages © 2026

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