Weave 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

Lexer Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

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

  • Purpose-built for one grammar: Pug/Jade. It converts Pug source into a phug/token stream consumed by phug/parser. It is not a general-purpose lexer and offers no value outside Pug.
  • Tightly coupled to its sibling packages. The token model is an internal contract shared with parser/compiler; it is versioned but not designed as a public API. Any integration we build sits on an unstable seam.
  • Well-factored in the narrow sense: a hand-written state-machine scanner, PSR-4 autoloaded, minimal transitive dependency surface. If our goal is a Pug token stream in PHP, it is the correct and essentially only option.
  • It does not belong anywhere in a request/response path. Its natural home is a dev dependency executed at build time or in CI.

Integration feasibility

  • Trivially installable (composer require phug/lexer), but that is where the ease ends.
  • The real cost is API discovery: public documentation for Phug covers the renderer and Laravel view adapter, not the lexer's token API. Expect to read source to learn the scanner entry point, token types, and error behavior.
  • Laravel itself offers no integration point for a lexer. phug/laravel (or equivalent view adapter) wires the renderer, not this package. There is no Blade-analogous path.
  • Feasible as a contained, single-module dependency; infeasible as something we expose broadly across the codebase.

Technical risk

  • Vendor concentration (high). Tiny maintainer pool, tiny user base. The 7.47 composite score is carried by recent releases and a permissive license, not by adoption; the 25.73 opportunity score reads as "nobody is asking for this." Bus factor is effectively one or two people.
  • Semantic-versioning risk (high). Internals of a multi-package compiler chain churn. A minor bump in 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.
  • Edge-case fidelity (medium). The scanner is a reimplementation of the JS 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.
  • Error ergonomics (medium). Lexer-level exceptions surface before the compiler's friendlier diagnostics. If we expose this to end users, we own message quality.
  • License risk (low). MIT, clean.
  • Release-date signal (positive but unverified). A 2026-03-15 release indicates the package is not abandoned; verify the version number and changelog before relying on that signal.

Key questions

  1. Are we actually rendering Pug, or do we need to analyze Pug? If rendering, why are we at the lexer and not at phug/phug/phug/renderer?
  2. What is the smallest deliverable that justifies this dependency, and can it be satisfied by the JS pug-lexer in a Node build step instead?
  3. Who owns upgrades? What is our policy when phug/token breaks the token shape?
  4. Do we need custom tokens or grammar extensions? If yes, we are forking, and the maintenance estimate changes by an order of magnitude.
  5. Have we validated the token API against our actual template corpus, including the ugly ones (deep nesting, mixed interpolation, inline code)?
  6. What is the exit cost if Phug goes dark — can we swap to a Node-based toolchain behind the same internal interface?

Integration Approach

Stack fit

  • Poor fit for a standard Laravel application. Laravel's view layer expects a Blade-style compiler; Phug's adapter path bypasses this package entirely.
  • Good fit for one narrow shape: a PHP-native developer tool — a Pug linter, formatter, codemod, or template static analyzer — distributed as a Composer binary and run in CI or pre-commit.
  • If the requirement is "process Pug templates inside a PHP service," this is the right building block. If the requirement is "let users write Pug instead of Blade," this is the wrong layer and the wrong ecosystem.

Migration path

  • No migration from Blade is warranted. Blade is maintained, documented, and Laravel-native; Phug is a niche port of a JS template engine with a fragile dependency chain. The switching cost is not justified by the feature delta.
  • If legacy Pug/Jade templates exist in the estate, migrate them out to Twig or Blade rather than deepening investment in the Phug chain. Use the lexer, if at all, as a one-time parsing aid for a conversion script — a bounded, disposable use.
  • For greenfield tooling, there is no migration; there is only a spike.

Compatibility

  • Constrain the PHP runtime explicitly (Phug's recent lines target PHP 8.x; confirm the floor against our matrix).
  • Pin 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.
  • Verify PHPStan/Psalm compatibility early; an undocumented token API plus static analysis is where integration time disappears.

Sequencing

  1. Spike (1–3 days). Install into a throwaway branch, lex a representative sample of real templates, document the token API we depend on, and benchmark against the JS pug-lexer for feature parity on our corpus.
  2. Decision gate. If the spike shows the API is sufficient and the output matches expectations, proceed. If it shows gaps, stop — do not "fix forward" into a fork.
  3. Isolate. Wrap the dependency behind a single internal interface (PugTokenizer or similar) with our own DTOs. Nothing outside one module may import Phug\Lexer\*. This is the exit hatch.
  4. Pin and test. Exact version constraints, a golden-file test suite over our template corpus to catch token-shape drift on upgrade.
  5. Ship as dev-only. require-dev, excluded from production autoload, executed in CI.
  6. Monitor. Watch upstream releases; treat any minor bump as a reviewed change with the golden files as the gate.

Operational Impact

Maintenance

  • Low ongoing code maintenance, high ongoing vigilance. The package itself changes rarely; the risk is that when it does, it changes without warning or migration notes.
  • Budget for a named owner who reads Phug changelogs. Unattended, this dependency will break silently on a composer update.
  • Our wrapper layer is the actual maintenance surface, and it is ours to keep healthy — which is the point of the wrapper.

Support

  • No commercial support, no SLA, no vendor relationship. Community support only via GitHub issues, and given 0 dependents the issue queue is unlikely to be a fast path.
  • We are effectively self-supporting: reading source, writing our own tests, diagnosing our own edge cases. Staff accordingly — assume a PHP developer with Pug familiarity can unblock themselves, and nobody else can.
  • Escalation path is "fork it," which is a credible option precisely because the package is small.

Scaling

  • CPU-bound and single-template-scoped. Throughput is a function of template size and nesting depth, not concurrency. For CI and CLI use this is a non-issue.
  • Do not place it in a request path. Per-request lexing of user-supplied templates is an injection surface (Pug's inline code execution) and a latency cost with no benefit — precompile instead.
  • Memory is proportional to token stream length; pathological templates with extreme nesting will produce large token arrays. Cap input size if templates are ever untrusted.

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

  • Days, not hours, for a competent PHP developer. Two learning curves stack: Pug syntax (indentation-sensitive, with embedded code) and the lexer's undocumented token API.
  • Expect the first engineer to spend more time reading phug/lexer source than writing integration code. That knowledge is concentrated and non-transferable — document it or lose it.
  • If the team has no Pug experience, add a full week and question the premise again. The cheapest time to abandon this dependency is before the first commit.

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.

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.
elmogy/larafast
xeviant/laravel-paystack
gorilladash/laravel-website-sdk
martialbe/flysystem-oss
chondal/3312client
jeroen-g/flickr
opscale-co/nova-genbi
itsjustvita/laravel-retention
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log
gregsphotography/site-builder-components
io-digital/clickatell
snowsoft/laravel-admin
oxygen/auth
relicsoftware/barakah-payment-gateway
tobya/work-with-composer
equipc/laravel-email-validator
equipc/laravel-email-database-log
adedsec/nova-translated-labels