Lavash.TagEngine (Lavash v0.3.0-rc.1)

Copy Markdown View Source

Thin wrapper around Phoenix.LiveView.TagEngine.{Parser, Compiler}.

Previously this module was a copy-paste fork of Phoenix.LiveView.TagEngine to insert a :token_transformer hook between tokenization and AST emission. In LV 1.2 the tag engine was split into a Parser (produces a node tree) and a Compiler (consumes the tree). That gives us a clean seam: tokenize once, walk/mutate the tree via a transformer, then compile.

Public API (unchanged for callers)

  • tokenize(source, opts) — parses source to a %Parser{} (nodes tree)
  • compile_from_tokens(parsed, opts) — applies the optional :token_transformer and compiles to AST

Options understood by compile_from_tokens/2:

  • :token_transformer — module implementing Lavash.TokenTransformer (the transformer's transform/2 now receives the node tree, not a flat token list)
  • :lavash_metadata — opaque metadata passed to the transformer
  • everything else is forwarded to Phoenix.LiveView.TagEngine.Compiler

Summary

Functions

Compiles a parsed node tree into Elixir AST.

Parses source into a %Parser{} (a node tree, suitable as input to compile_from_tokens/2).

Functions

compile_from_tokens(parsed, opts)

Compiles a parsed node tree into Elixir AST.

Accepts the %Parser{} returned by tokenize/2. If a :token_transformer module is supplied in opts, its transform/2 is invoked on the node tree before compilation.

tokenize(source, opts)

Parses source into a %Parser{} (a node tree, suitable as input to compile_from_tokens/2).

Raises if parsing fails.