blade-syntax
A lossless parser for Laravel Blade templates, written in Rust.
let parse = parse;
assert!;
// The tree reproduces the input exactly, byte for byte.
assert_eq!;
// Walk it like any rowan tree.
for node in parse.syntax.descendants
- Lossless: whitespace, comments, CRLF, a BOM and broken input all round-trip. Formatters and linters can share one tree.
- Never fails: problems such as an unclosed
@ifor{{becomeParseErrors with a byte range, and the tree is still built. - Follows Blade's real rules: directive pairing (including
@forelse/@empty,@section/@show, customBlade::ifconditionals),@verbatimand@phpraw blocks, escaped@{{ }}and@@, and{{{ }}}. - Understands HTML structure: tags, attributes,
<x-components>,<livewire:...>, Alpine@clickattributes,<script>/<style>raw text, and tags split across@ifbranches. - Tested on real code: 879 templates from Laravel, Filament, Livewire, Breeze, Jetstream, Pulse, BookStack and laravel.io, plus property tests and fuzzing.
The tree is built on rowan, the library behind rust-analyzer.
How it works: docs/how-it-works.
License
MIT or Apache-2.0, at your option.