Photo by Hanna Morris on Unsplash
From Regexes to AST: STE Journey to Adulthood
This post is about updating STE to an AST-based template engine
Like in the early days of JavaScript template engines, STE used to rely on regular expressions to identify placeholders in the templates and replace them with the corresponding data. Likewise a kid builds a LEGO castle by combining blocks together. ๐งฑ
Well, our little STE (Simple Template Engine) just graduated from blocks-building kindergarten to the big leagues of Abstract Syntax Trees. ๐ด
The Glow-Up Story ๐
Picture this: STE used to process templates like a hungry kid eating a steak and fries combo - just mixing them with some ketchup and swallow the combined result. Now? It's using proper utensils! First, it takes your template and breaks it into little bite-sized pieces, then organizes them into a beautiful tree structure that would make any data structure proud.
Why Should You Care? ๐ค
Because the kid eating a steak and fries combo used to produce spaghetti code which is not a clean and proper way to treat our data. The new AST-based approach means:
Less "Why isn't this working?" moments
More "Awesome, everything works!" moments
Fewer bugs doing the cha-cha in your templates
The Cool New Features ๐
Our template engine now handles expressions like a boss, has plenty of powerful filters to transform and format data, and can nest templates deeper than your family's drama at Thanksgiving dinner.
The End Result ๐
STE went from being the kid who eats glue to the one who gets straight A's. It's still simple (because nobody likes a show-off), but now it's simple AND smart.
Our templates can now pass data like players in the Premier League, but you don't have to worry since LiteNode stays as simple to use as your grandmother's HTML from 1995. Because sometimes the sweetest solutions are the simplest ones... just like a scoop of vanilla JS! ๐ฆ
Remember folks: Even template engines grow up. They just need a little AST-itude adjustment! ๐
P.S. No LEGO blocks, steak, fries or spaghetti were harmed in the making of this AST-based template engine. They were just organized into a more sophisticated structure.