I spent last week in Denver with the Statamic team to attend Laracon and hang out. It was a great time, and a much-needed change of pace from my basement office staring into glowing rectangles.
Much fun was had, as well as many discussions surrounding Statamic, neither of which I will go into detail here: some memories are best kept with the few that experienced them, and it is not my place to divulge any upcoming awesome Statamic news. Here is a picture of us all at Red Rocks Park and Amphitheatre, though:
They are a great group of people, and I am honored to call them friends.
It was my first in-person Laracon, and it's not just hype - it's an epic experience. I got to meet quite a few people in person I've talked with over the years (some going back over ten years!), as well as meet a ton of new people. It was a blast!
I could talk more about Laracon itself, and I may another day. However, I am primarily writing this blog post to continue the many conversations I had at Laracon, many of which centered on some variation of the question, "What are you doing next with Blade?"
#Adventures in Blade
Over the years, I've experimented a lot with Blade. Most of those experiments have remained private little adventures, but some have become public. The most popular recently being:
- Dagger: An alternative component framework for Blade, focusing on performance and expanding the feature set of components at the same time.
- Blade Parser: A standalone Blade parser and document system, allowing developers to build crazy things.
- Blade Prettier Plugin: A Blade prettier plugin that obsessively focuses on compatibility with other tools within the ecosystem, like Pint and Alpine.js.
I'm proud of all three of these projects, and don't see them going anywhere anytime soon; some of them are just getting started! Over the past year, as I've given thought to these projects and others, all the ideas have converged around a more central and powerful idea.
Which begs the question: What am I going to do next with Blade?
#Introducing Forte
All good projects need a great name, so I'd like to introduce you to Forte. From Merriam-Webster:
the part of a sword or foil blade that is between the middle and the hilt and that is the strongest part of the blade
A short, punchy word that is fun to say, and it relates to blades? Come on, that's nice. But it also correlates with what I want to do: build a strong backbone and foundation for Blade that others can stand on top of, without risking breaking changes within the core framework.
It also hints at where I want Forte to operate: between you and the framework's Blade compiler. I want Forte to be the best Blade extensibility model and framework possible, bar none.
My long-term goals for this project are to develop a set of libraries, parsers, and utilities that make it incredibly simple for people to extend and supercharge Blade in exciting, powerful, and predictable ways, without resorting to a tangled mess of regular expressions obtained through source diving.
Long-term goals are great, but they aren't achieved without laying some groundwork.
#What I'm Working on Now
Currently, my core focus with Forte is on the lexer and parser. Forte's parser will differ from my existing Blade Parser library, which excels at extracting Blade from templates, in that it will not only parse Blade but also all of the HTML, producing a traversable AST that represents the entire template.
Blade is an inheritenly structureless language: the structure and order is imposed by the compiled output, not necessarily by Blade itself. This can make things slightly tricky to parse accurately; I want Forte to hide all of that nuance within Forte, freeing up mind space to focus on building cool things.
Additionally, real-world templates solve real-world problems, and sometimes they are not the friendliest to parse.
Let's take this template as an example:
1@if ($condition)
2 <div>
3@endif
4
5 <p>Some content here.</p>
6
7@if ($condition)
8 </div>
9@endif
My existing Blade parser library can parse this, but doesn't produce anything worthwhile if you wanted to also work with the HTML. The prettier formatter also chokes on this, as we have unclosed HTML elements.
Let's take a look at what the Forte parser currently produces, however:
That's much better! A parser than understands the real-world, and manages to produce a useful AST!
Remember how I said Blade itself doesn't really have a structure? As an example, the following compiles to perfectly valid PHP code (I'm not endorsing this - I see you):
1@can ('update', $post)
2 <!-- First Branch -->
3@elseif ($somethingElse)
4 <!-- Second Branch -->
5@else
6 <!-- Third Branch -->
7@endunless
parsing that is not straightforward, but Forte can handle it:
For a friendlier, more familiar example, here is the AST produced from the Laravel 12 welcome page:
#What Comes Next
Forte will remain closed-sourced for now while I continue working through the core lexer and parser. There's just too much movement, and it allows me the freedom to scrap things and rewrite it a few dozen times as I go. Despite that, I'd like to talk about a few of the exciting things this will unlock and my current goal posts.
The first goal is to be able to refactor Blaze, an incredible code-folding engine by Caleb Porzio, to use Forte's lexer, parser and AST.
The second immediate goal is to make it possible to bring incredible Blade formatting back home to PHP. Enabling some of the cool tricks my current formatter is capable of requires some nuance, however.
After that? I don't know, and that's the exciting part.
∎