doctrine

doctrine/lexer

PHP MIT

Base library for a lexer that can be used in Top-Down, Recursive Descent Parsers.

11.2k stars
62 forks
recent
GitHub

11.2k

Stars

62

Forks

2

Open issues

5

Contributors

3.0.1 05 Feb 2024

AI Analysis

A lightweight PHP library providing a base lexer implementation for building Top-Down Recursive Descent Parsers. It is actively used by Doctrine Annotations and Doctrine ORM for parsing DQL queries and annotations. Developers building custom parsers and domain-specific languages benefit from this foundational parsing component.

Documentation 7/10
Activity 9/10
Community 8/10
Code quality 8/10

Inferred from signals mentioned in the README (tests, CI, type safety) — not a review of the actual code.

Overall score 8/10

AI's overall editorial judgment — not an average of the bars above, can weigh other factors too.

lexer parser php parsing doctrine
Actively maintained MIT licensed Popular Production ready
Deep Analysis · Based on README and public signals
2w ago

Doctrine Lexer: The PHP tokenization foundation powering ORM and annotations parsing

Doctrine Lexer is a base library providing foundational lexer/tokenizer infrastructure for building Top-Down, Recursive Descent Parsers in PHP. Its primary consumers are Doctrine Annotations and Doctrine ORM's DQL (Doctrine Query Language) parser — two of the most widely deployed PHP packages in the ecosystem. The library itself is intentionally minimal: it is not a general-purpose parser toolkit but rather a reusable tokenization layer meant to be extended. Its audience is largely other library/framework authors, not application developers directly.

Origin

Created in January 2013 as part of the Doctrine Project to extract shared lexer logic from ORM and Annotations. It has evolved slowly and deliberately over 13 years, reflecting its role as stable infrastructure rather than an actively extended feature set.

Growth

Star growth is almost entirely passive, driven by developers exploring the Doctrine ecosystem and encountering the library as a dependency. It does not market itself independently. Its 11k stars almost certainly reflect transitive discovery from doctrine/orm and doctrine/annotations rather than direct intent to use the lexer. The 0 stars in the last 7 days confirms it is no longer in an active discovery phase — it is an established, stable dependency.

In production

Highly verifiable indirect adoption: doctrine/orm (10k+ stars, used in millions of Symfony and Laravel applications) and doctrine/annotations (formerly ubiquitous in PHP DI/serialization) both depend on this library. Packagist download counts for doctrine/lexer have historically been in the hundreds of millions, placing it among the most-downloaded PHP packages. This is one of the strongest indirect adoption signals available in the PHP ecosystem.

Code analysis
Architecture

Appears to provide an abstract base class or trait that handles input scanning, token peeking, and cursor advancement, leaving token definition and grammar rules to subclasses. Likely follows a classical lexer pattern with a position-based string scanner. Based on README, it is intentionally minimal and designed for extension rather than standalone use.

Tests

A Continuous Integration badge is present linking to GitHub Actions, indicating automated testing is in place. Specific coverage percentage is not documented in README.

Maintenance

Last push was June 14, 2026 — approximately 12 days before the evaluation date. This indicates active, recent maintenance. The low fork count (62) relative to stars is consistent with a stable, rarely-forked infrastructure library. CI is active. Maintenance cadence appears healthy for a mature low-churn library.

Honest verdict

ADOPT IF: you are building a PHP library or framework that needs to tokenize a custom DSL or query language and want a well-tested, battle-proven base rather than rolling your own. AVOID IF: you need a full parser framework, AST generation, or grammar file support — this is deliberately minimal tokenizer infrastructure only. MONITOR IF: you maintain software that transitively depends on doctrine/orm or doctrine/annotations and need to track breaking changes across major versions.

Independent dimensions

Mainstream potential

2/10

Technical importance

7/10

Adoption evidence

9/10

Risks
  • Extremely narrow scope limits discoverability and direct adoption — most users will never import it deliberately.
  • Dependency risk is low but non-zero: any breaking change propagates through doctrine/orm and affects a massive PHP install base.
  • PHP ecosystem shift away from annotations (toward PHP 8 native attributes) may reduce doctrine/annotations usage, potentially shrinking one key consumer over time.
  • Documentation is sparse by design, which may discourage authors who could benefit from using it as a base but don't know it exists.
  • Low fork count means external contributors are few; stewardship remains concentrated in the Doctrine core team.
Prediction

Doctrine Lexer will continue as stable, low-churn infrastructure for the foreseeable future. DQL parsing ensures ongoing relevance as long as Doctrine ORM remains a major PHP ORM, which appears likely through at least the late 2020s.

0 found this helpful

Newsletter

Get analyses like this every Monday

Free weekly digest of the most interesting open-source discoveries.

Languages

PHP
100%

Information

Language
PHP
License
MIT
Last updated
4w ago
Created
164mo ago
Analyzed with
anthropic/claude-haiku-4-5

Stars over time

Loading…

Contributors over time

Top 100 contributors only — repos with more will plateau at 100.

Loading…

Similar repos

doctrine

doctrine/inflector

Doctrine Inflector is a focused PHP library for string manipulation operations,...

11.3k PHP Dev Tools
doctrine

doctrine/orm

Doctrine ORM is a mature object-relational mapper for PHP 8.1+ that provides...

10.2k PHP Web Dev
doctrine

doctrine/cache

Doctrine Cache is a caching component extracted from Doctrine Common that...

7.9k PHP
doctrine

doctrine/instantiator

Doctrine Instantiator enables creation of PHP class instances without invoking...

11k PHP
nikic

nikic/PHP-Parser

PHP Parser is a mature PHP parser written in PHP that converts PHP source code...

17.4k PHP Dev Tools
vs. alternatives
nikic/PHP-Parser

A full AST-based PHP source code parser. Solves a different problem (parsing PHP itself) and is not a general lexer base. More featureful but also more opinionated and heavy for embedding in domain-specific parsers like DQL.

doctrine/annotations

A consumer of doctrine/lexer, not a competitor. Illustrates the intended upstream role of this library.

custom hand-rolled lexers

The alternative most library authors would otherwise use. Doctrine Lexer offers tested, reusable infrastructure that reduces boilerplate, though some authors prefer zero dependencies.

league/pipeline / parser combinator libs

PHP parser combinator libraries exist but are less mature and less battle-tested in production PHP frameworks than the Doctrine toolchain.

ANTLR (PHP target)

A grammar-driven parser generator targeting multiple languages. Far more complex to integrate and not idiomatic PHP; doctrine/lexer is far lighter for small DSLs.