PHPackages                             goaop/dissect - 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. goaop/dissect

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

goaop/dissect
=============

A set of tools for lexical and syntactical analysis written in pure PHP

3.0.0(2y ago)275.1k—2.3%1MITPHPPHP ^8.2.0CI passing

Since Feb 19Pushed 1mo agoCompare

[ Source](https://github.com/goaop/dissect)[ Packagist](https://packagist.org/packages/goaop/dissect)[ Docs](https://github.com/goaop/dissect)[ GitHub Sponsors](https://github.com/lisachenko)[ RSS](/packages/goaop-dissect/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (3)Versions (6)Used By (0)

🔬 Dissect
=========

[](#-dissect)

> A pure-PHP toolkit for building custom **lexers** and **LALR(1) parsers** — fast, type-safe, and dependency-free.

[![GitHub Actions Workflow Status](https://camo.githubusercontent.com/fc89e428e5de35411a6fc6bb5e4193d9238a9b0cb6979c425e4b39b0d7d774e4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f676f616f702f646973736563742f7068702d74657374732e796d6c3f6272616e63683d6d6173746572)](https://camo.githubusercontent.com/fc89e428e5de35411a6fc6bb5e4193d9238a9b0cb6979c425e4b39b0d7d774e4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f676f616f702f646973736563742f7068702d74657374732e796d6c3f6272616e63683d6d6173746572)[![PHPStan Badge](https://camo.githubusercontent.com/3a6d38fc5ef50cf5af3f711e5e857a2ce964a35205fd11bbfacc1add9559a748/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d6c6576656c25323031302d627269676874677265656e2e7376673f7374796c653d666c6174266c696e6b3d68747470732533412532462532467068707374616e2e6f7267253246757365722d677569646525324672756c652d6c6576656c73)](https://camo.githubusercontent.com/3a6d38fc5ef50cf5af3f711e5e857a2ce964a35205fd11bbfacc1add9559a748/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d6c6576656c25323031302d627269676874677265656e2e7376673f7374796c653d666c6174266c696e6b3d68747470732533412532462532467068707374616e2e6f7267253246757365722d677569646525324672756c652d6c6576656c73)[![Total Downloads](https://camo.githubusercontent.com/2bf19b29e9f4183fae89766cac923d70207ae9574ca5bc67ca6c0adcebe04019/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f676f616f702f646973736563742e737667)](https://packagist.org/packages/goaop/dissect)[![Daily Downloads](https://camo.githubusercontent.com/d344db8883ea34c3e3752eb9bb9c8499ab35c200977e95e50d07a5d477c92744/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64642f676f616f702f646973736563742e737667)](https://packagist.org/packages/goaop/dissect)[![PHP Version](https://camo.githubusercontent.com/db2abc4c99337a799d57b191c749e512b551eaebf6ce7c37e0ea9eac2eb1b9f6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344253230382e342d3838393242462e737667)](https://php.net/)[![GitHub License](https://camo.githubusercontent.com/483ab6d49d7ae3cedc81a2eace4b3bbbd58d97c3f1d12188f1f1edf78ed71286/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f676f616f702f64697373656374)](https://camo.githubusercontent.com/483ab6d49d7ae3cedc81a2eace4b3bbbd58d97c3f1d12188f1f1edf78ed71286/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f676f616f702f64697373656374)[![Sponsor](https://camo.githubusercontent.com/bb12d9dc1322843f286cc097e773f46484771b3a0c3980fa8aebed6cb736e447/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f53706f6e736f722d2545322539442541342545462542382538462d6c69676874677261793f7374796c653d666c6174266c6f676f3d676974687562)](https://github.com/sponsors/lisachenko)

---

✨ What is Dissect?
------------------

[](#-what-is-dissect)

Dissect is a pure-PHP library for **lexical and syntactical analysis** — the foundational building blocks for any language tooling: expression evaluators, template engines, DSL interpreters, query parsers, and more.

It powers the [GoAOP framework](https://github.com/goaop/framework), where it parses pointcut DSL expressions into an AST for aspect-oriented programming.

### Data flow

[](#data-flow)

```
Input String
    │
    ▼
┌─────────┐      ┌──────────────┐      ┌──────────────────┐
│  Lexer  │ ───▶ │ TokenStream  │ ───▶ │  LALR(1) Parser  │ ───▶ Result / AST
└─────────┘      └──────────────┘      └──────────────────┘
                                               ▲
                                         Grammar (rules
                                          + callbacks)

```

---

🚀 Key Features
--------------

[](#-key-features)

### 🔤 Flexible Lexers

[](#-flexible-lexers)

LexerDescription**`SimpleLexer`**Fluent builder API — define tokens with strings or regex, mark skippable tokens**`StatefulLexer`**Context-aware tokenization with explicit state transitions (e.g. for string interpolation)**`RegexLexer`**Abstract base class adapted from Doctrine — ultra-fast single-pass regex lexing### 📐 LALR(1) Parser

[](#-lalr1-parser)

- **Full LALR(1) grammar support** — handles the vast majority of real-world grammars
- **Fluent grammar API** — define productions and semantic actions with readable PHP closures
- **Operator precedence &amp; associativity** — built-in `left()`, `right()`, `nonassoc()` declarations
- **Conflict resolution** — configurable strategies: shift-wins, longer-reduce, earlier-reduce
- **Precomputed parse tables** — analyze once, serialize to PHP file, load instantly in production

### 🌳 AST Construction

[](#-ast-construction)

- **`CommonNode`** — ready-to-use tree node with named children and arbitrary attributes
- **Countable &amp; iterable** — traverse subtrees with standard PHP constructs

### 🛠 Developer Experience

[](#-developer-experience)

- **Zero runtime dependencies** — only Symfony Console as an optional CLI dep
- **PHPStan level 10** — fully typed with generics, array shapes, and readonly properties
- **CLI tool** — dump parse tables and visualize automaton states as Graphviz graphs

---

📦 Installation
--------------

[](#-installation)

```
composer require goaop/dissect
```

---

⚡ Quick Example
---------------

[](#-quick-example)

```
use Dissect\Lexer\SimpleLexer;
use Dissect\Parser\Grammar;
use Dissect\Parser\LALR1\Parser;

// 1. Define a lexer
$lexer = new SimpleLexer();
$lexer->regex('INT',   '/[0-9]+/')
      ->token('PLUS',  '+')
      ->token('MINUS', '-')
      ->regex('WS',    '/\s+/')
      ->skip('WS');

// 2. Define a grammar
$grammar = new Grammar();
$grammar('Expr')
    ->is('Expr', 'PLUS', 'Expr')
    ->call(fn($l, $_, $r) => $l + $r)

    ->is('Expr', 'MINUS', 'Expr')
    ->call(fn($l, $_, $r) => $l - $r)

    ->is('INT')
    ->call(fn($t) => (int) $t->getValue());

$grammar->operators('PLUS', 'MINUS')->left()->prec(1);
$grammar->start('Expr');

// 3. Parse!
$parser = new Parser($grammar);
$result = $parser->parse($lexer->lex('3 + 5 - 2')); // → 6
```

---

📖 Documentation
---------------

[](#-documentation)

TopicDescription[Lexical analysis](docs/lexing.md)`SimpleLexer`, `StatefulLexer`, `RegexLexer`, performance tips[Writing a grammar](docs/parsing.md)Productions, callbacks, operator precedence, conflict resolution[Building an AST](docs/ast.md)`CommonNode`, tree traversal[Common patterns](docs/common.md)Lists, comma-separated sequences, expression grammars[CLI tool](docs/cli.md)Precomputing parse tables, exporting automaton graphs---

🧪 Testing &amp; Quality
-----------------------

[](#-testing--quality)

```
# Run tests
composer test

# Run tests with coverage
composer test-coverage

# Static analysis (PHPStan level 10)
composer phpstan
```

---

🙏 Credits
---------

[](#-credits)

Originally created by [@jakubledl](https://github.com/jakubledl), extended by [@WalterWoshid](https://github.com/WalterWoshid), maintained by the [GoAOP](https://github.com/goaop) team.

Give a ⭐ if Dissect saved you from writing a parser by hand!

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance59

Moderate activity, may be stable

Popularity35

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 71.7% 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 ~0 days

Total

2

Last Release

819d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/640114?v=4)[Alexander Lisachenko](/maintainers/lisachenko)[@lisachenko](https://github.com/lisachenko)

---

Top Contributors

[![lisachenko](https://avatars.githubusercontent.com/u/640114?v=4)](https://github.com/lisachenko "lisachenko (38 commits)")[![WalterWoshid](https://avatars.githubusercontent.com/u/36635504?v=4)](https://github.com/WalterWoshid "WalterWoshid (14 commits)")[![samsonasik](https://avatars.githubusercontent.com/u/459648?v=4)](https://github.com/samsonasik "samsonasik (1 commits)")

---

Tags

parserastparsinglexing

###  Code Quality

TestsPHPUnit

Static AnalysisRector

### Embed Badge

![Health badge](/badges/goaop-dissect/health.svg)

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

###  Alternatives

[jakubledl/dissect

Lexing and parsing in pure PHP

2244.6M11](/packages/jakubledl-dissect)[parsica-php/parsica

The easiest way to build robust parsers in PHP.

412140.4k4](/packages/parsica-php-parsica)[jejik/mt940

An MT940 bank statement parser for PHP

911.2M2](/packages/jejik-mt940)[denissimon/formula-parser

Parsing and evaluating mathematical formulas given as strings.

81306.8k3](/packages/denissimon-formula-parser)[tmilos/scim-filter-parser

System for Cross-domain Identity Management SCIM AST filter parser PHP library

111.7M6](/packages/tmilos-scim-filter-parser)[atanamo/php-codeshift

A PHP code transformation toolkit based on 'PHP-Parser'

32158.4k1](/packages/atanamo-php-codeshift)

PHPackages © 2026

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