Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Dissect Laravel Package

goaop/dissect

View on GitHub
Deep Wiki
Context7

๐Ÿ”ฌ Dissect

A pure-PHP toolkit for building custom lexers and LALR(1) parsers โ€” fast, type-safe, and dependency-free.

GitHub Actions Workflow Status PHPStan Badge Total Downloads Daily Downloads PHP Version GitHub License Sponsor


โœจ 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, where it parses pointcut DSL expressions into an AST for aspect-oriented programming.

Data flow

Input String
    โ”‚
    โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”      โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”      โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Lexer  โ”‚ โ”€โ”€โ”€โ–ถ โ”‚ TokenStream  โ”‚ โ”€โ”€โ”€โ–ถ โ”‚  LALR(1) Parser  โ”‚ โ”€โ”€โ”€โ–ถ Result / AST
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜      โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜      โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                               โ–ฒ
                                         Grammar (rules
                                          + callbacks)

๐Ÿš€ Key Features

๐Ÿ”ค Flexible Lexers

Lexer Description
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

  • 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 & 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

  • CommonNode โ€” ready-to-use tree node with named children and arbitrary attributes
  • Countable & iterable โ€” traverse subtrees with standard PHP constructs

๐Ÿ›  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

composer require goaop/dissect

โšก 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

Topic Description
Lexical analysis SimpleLexer, StatefulLexer, RegexLexer, performance tips
Writing a grammar Productions, callbacks, operator precedence, conflict resolution
Building an AST CommonNode, tree traversal
Common patterns Lists, comma-separated sequences, expression grammars
CLI tool Precomputing parse tables, exporting automaton graphs

๐Ÿงช Testing & Quality

# Run tests
composer test

# Run tests with coverage
composer test-coverage

# Static analysis (PHPStan level 10)
composer phpstan

๐Ÿ™ Credits

Originally created by @jakubledl, extended by @WalterWoshid, maintained by the GoAOP team.

Give a โญ if Dissect saved you from writing a parser by hand!

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky