blade-syntax 0.1.1

Lossless parser for Laravel Blade templates
Documentation
  • Coverage
  • 72.55%
    37 out of 51 items documented1 out of 3 items with examples
  • Size
  • Source code size: 104.7 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 777.8 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 2s Average build duration of successful builds.
  • all releases: 3s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • roderio/blade-rs
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • roderio

blade-syntax

A lossless parser for Laravel Blade templates, written in Rust.

let parse = blade_syntax::parse("@if($user) Hi {{ $user->name }} @endif");
assert!(parse.errors().is_empty());

// The tree reproduces the input exactly, byte for byte.
assert_eq!(parse.syntax().to_string(), "@if($user) Hi {{ $user->name }} @endif");

// Walk it like any rowan tree.
for node in parse.syntax().descendants() {
    println!("{:?} {:?}", node.kind(), node.text_range());
}
  • 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 @if or {{ become ParseErrors with a byte range, and the tree is still built.
  • Follows Blade's real rules: directive pairing (including @forelse/@empty, @section/@show, custom Blade::if conditionals), @verbatim and @php raw blocks, escaped @{{ }} and @@, and {{{ }}}.
  • Understands HTML structure: tags, attributes, <x-components>, <livewire:...>, Alpine @click attributes, <script>/<style> raw text, and tags split across @if branches.
  • 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.