Skip to content

Refactor TagEngine introducing TagEngine.Compiler#4125

Merged
SteffenDE merged 5 commits intomainfrom
sd-tagcompiler
Jan 23, 2026
Merged

Refactor TagEngine introducing TagEngine.Compiler#4125
SteffenDE merged 5 commits intomainfrom
sd-tagcompiler

Conversation

@SteffenDE
Copy link
Copy Markdown
Collaborator

@SteffenDE SteffenDE commented Jan 22, 2026

This PR refactors the TagEngine to work with the same tree we build for the HTMLFormatter. The benefit is that we have the full tree upfront which allows us to handle macro component directives (as explored by #4114, #4116). It also makes it easier to reason about the code, since all the code for handling a tag / component can be in one clause and the logic is not spread across an opening and closing clause.

This commit moves the Tokenizer into the
Phoenix.LiveView.TagCompiler.Tokenizer module and also
adds a Parser that builds a tree similar to what the
HTMLFormatter previously did. We're going to use that
node tree for compiling templates in a future commit.

The HTMLFormatter and HTMLAlgebra were now use this
tree format.
This commit introduces a compiler for the new unified
tree structure introduced in the previous commit. It
changes the TagEngine to use the new compiler and also
moves macro component handling to the parser.

For backwards compatibility, the TagEngine still implements
the EEx.Engine behaviour, but it is basically a no-op
(it will still parse Elixir expressions twice!)
and calls the new compiler at the end.

The benefit of this is that we can now have the full
tokenized template and handle macro components before
compiling inner parts of the template. This allows us
to more easily implement directives as explored by

#4114
#4116
@SteffenDE SteffenDE marked this pull request as ready for review January 23, 2026 12:26
@SteffenDE SteffenDE requested a review from josevalim January 23, 2026 13:37
Copy link
Copy Markdown
Member

@josevalim josevalim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. I would only rename the new modules to TagEngine.Compiler/Parser/Tokenizer, but it is not important. Ship it!

@SteffenDE SteffenDE added this to the v1.2 milestone Jan 23, 2026
@SteffenDE SteffenDE changed the title Refactor TagEngine introducing TagCompiler Refactor TagEngine introducing TagEngine.Compiler Jan 23, 2026
@SteffenDE SteffenDE merged commit 64a28ca into main Jan 23, 2026
16 checks passed
@SteffenDE SteffenDE deleted the sd-tagcompiler branch January 23, 2026 17:01
SteffenDE added a commit that referenced this pull request Feb 20, 2026
Fixes #4144.

When we simplified root tracking in #4125, we did not account for
EEx comments (<%!-- ... --%>). Since those are just ignored in the
compiler, we can already omit them at the tokenizer level.
SteffenDE added a commit that referenced this pull request Feb 20, 2026
Fixes #4144.

When we simplified root tracking in #4125, we did not account for
EEx comments (<%!-- ... --%>). Since those are just ignored in the
compiler, we can already omit them at the tokenizer level.
SteffenDE added a commit that referenced this pull request Feb 20, 2026
Fixes #4144.

When we simplified root tracking in #4125, we did not account for
EEx comments (<%!-- ... --%>). Since those are just ignored in the
compiler, we can already omit them at the tokenizer level.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants