phug/lexer
A fast, extensible PHP lexer for Pug (Jade) templates and the Phug ecosystem. It converts template source into structured tokens for parsing, supporting indentation, tags, attributes, interpolation, code, and comments with configurable scanners.
Bottom line: phug/lexer is a low-level tokenizer for the Pug template language, extracted from the Phug rendering stack. It is not an application-facing library, and the 3 stars / 0 dependents profile confirms almost nobody consumes it directly — teams consume phug/phug or the renderer. Adopting it is only defensible if we are building Pug tooling (linter, formatter, static analyzer, IDE integration, custom AST transformation), not if we want template rendering.
Architecture fit
phug/token stream consumed by phug/parser. It is not a general-purpose lexer and offers no value outside Pug.Integration feasibility
composer require phug/lexer), but that is where the ease ends.phug/laravel (or equivalent view adapter) wires the renderer, not this package. There is no Blade-analogous path.Technical risk
phug/token or phug/lexer can alter token shapes without the API guarantees we would expect from a standalone library. We must pin exact versions and treat upgrades as change-managed events.pug-lexer; divergence on indentation-sensitive constructs, interpolation, unbuffered code blocks, or malformed input is plausible. We will be discovering bugs the community is not reporting.Key questions
phug/phug/phug/renderer?pug-lexer in a Node build step instead?phug/token breaks the token shape?Stack fit
Migration path
Compatibility
phug/lexer and phug/token to exact or ~-level constraints with a committed composer.lock. Floating constraints on an internal component of a compiler chain is the single most likely cause of a surprise outage.Sequencing
pug-lexer for feature parity on our corpus.PugTokenizer or similar) with our own DTOs. Nothing outside one module may import Phug\Lexer\*. This is the exit hatch.require-dev, excluded from production autoload, executed in CI.Maintenance
composer update.Support
Scaling
Failure modes
| Mode | Likelihood | Impact | Mitigation |
|---|---|---|---|
| Token shape changes on minor upgrade | Medium | High — silent wrong output | Exact pins, golden-file tests |
| Upstream abandonment | Low–Medium | Medium | Isolated wrapper, fork option |
Divergence from JS pug-lexer on edge cases |
Medium | Medium | Corpus-based parity testing |
| Cryptic lexer exceptions surface to users | High | Low–Medium | Catch and re-wrap with our own messages |
| Inline code execution via Pug in a request path | Low if architected correctly | Critical (RCE) | Dev-only, never lex untrusted input |
| Composer resolution conflict with other Phug packages | Low–Medium | Medium | Single Phug version line across the estate |
Ramp-up
phug/lexer source than writing integration code. That knowledge is concentrated and non-transferable — document it or lose it.Recommendation: Do not adopt phug/lexer as an application dependency. Approve it only for a bounded, dev-time Pug tooling use case, behind an internal wrapper, on exact version pins, with a spike as a hard gate and a fork-or-replace exit strategy documented before the first line of integration code is merged.
How can I help you explore Laravel packages today?