
louise
Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.
ADR 0057: std's templaters are compiled syntax for the HTML tree
Status: Proposed (2026-10-22); needs engineering review (#44).
Supersedes the templater part of ADR 0048 (§std's templaters); resolves the "tagged templates" follow-up of ADR 0054. Issue #298.
Context
ADR 0048 made every templater an ordinary function called at run time
with a Template(parts, holes). That left std's pug, html and xml
worse than the HTML literals in three ways (issue #298):
- Boolean attributes render backwards. Every template hole is
stringified, so
pug\input(autofocus={off})`withoff = Falserendersautofocus="False"— and HTML reads a present boolean attribute as on. The literal's checker lowers aBool` attribute hole to a flag; a runtime templater cannot see a hole's position. - Template errors happen at run time. A malformed pug template
passed
louise checkand panicked at the first render, with a template-relative line number and no source span. - Pug was cut off from the HTML pipeline. ADR 0054's precompiled
renderers skip templater calls, so a pug page always built and walked
the whole
Elementtree.
Decision
When a template's tag resolves lexically to std/template.pug,
.html or .xml, the compiler lowers the template's text to the HIR an
HTML literal produces; there is no Template value and no call. A tag
resolving to anything else (a user templater like css or sql) keeps
the ADR 0048 runtime path untouched.
- The pug parser moves into the compiler (
louise_hir/src/lower/ pug.rs), a faithful port of the Louise grammar ADR 0048 wrote instd/template.lse: the indentation tree,.class/#idshorthands (bare shorthands aredivs),(attrs)(name="value",name={hole}, bare flags),| textlines,//comments, holes inline or alone on a line, and deeper lines as children. Its output isExpr::Htmlnodes with the holes at their positions; an uppercase tag is a component call (Card(title={t})with indented children iscard(title: t, children: [...])), exactly as in a literal. - Spans map back into the source. The template's text tokens keep
their source ranges; the parser decodes escapes itself, so every
character carries the range of itself or of its escape sequence and
every hole the range of its
{…}. Every runtime panic of the Louise parser is now a spanned diagnostic (E0601) at the token or line at fault, with the same message (its line number is the template's own, as before). The first error aborts the template, as the first panic did. Two panics were type-directed — "an element can't be an attribute value" — and are type errors now: E0602 inname={e}, E0401 (Elementhas noShow) inside a quoted value. - Holes are typed by position, with one rule set for both syntaxes
(extending ADR 0009): an attribute hole is a
StringorInt(text), aBool(a flag, present iff true) or — new, for literals too — anOption<String>(Noneleaves the attribute out); a child hole is aStringor shown value (escaped text), anElementor aList<Element>(embedded); a hole anywhere else (a tag or attribute name) is a parse error. A{e:?}hole shows withDebug, as templates always did: the lowering wraps it in a one-hole string interpolation, so it is aStringto the HTML rules. htmlis raw markup. Its text parts becomeRawchildren (a newHtmlChild::Raw, lowered to the existingRawconstructor) and its holes children typed as above — byte-identical to the runtimehtml, which never parsed.xmlis the same fragment, rendered into the opaqueXmlby a kept runtime helper the compiler calls:std/template.xml_of_element(e) = Xml(html.render(e)). Raw parts append as written, text holes are escaped, element holes render — the runtimexml's output byte for byte. (A tree is still built forxml; its result is aString, so ADR 0054 does not apply — as before.)Option<String>attributes lower to a newstd/htmlconstructorOptional(String, Option<String>):render_attributesappendsname="v"forSome(v)and nothing forNone. ADR 0054's pass matches it: a constant folds, else the append sits under a switch on the option.- std/template keeps
TemplateandHole(user templaters, e.g. thepostgrespackage'ssql), and keeps thepug/html/xmldeclarations as the tags' resolution targets, with unreachable bodies — they are never called: tag position is intercepted, and a reference to one of them anywhere else is E0605 ("std's templaters are syntax, not values"). A local shadowing the name resolves to the local and is fine; the check is on the resolved definition (module pathstd/template+ name), like Core'sstd_ctor.
Consequences
pug\input(required={on} autofocus={off})`withoff = Falserenders<input required>`. Output changes only where it was wrong.- A malformed template fails to compile, with a span, in the editor and at the command line; go-to-definition and hover work inside pug holes (the holes are ordinary expressions with their own spans).
- A compiled template is constructor calls, so ADR 0054's
precompilation fires on pug pages unchanged: no
Elementtree is built for a precompiled page. - Code passing
pug(orhtml,xml) around as a value stops compiling; nothing in the repo did. - The interpreter and the C backend needed no template code: compiled
templates are
Expr::Html, which both already lower. - Formatter follow-up (not here): the formatter keeps template text verbatim; normalising pug indentation is a separate change.
Alternatives considered
- Compile-time evaluation of the Louise pug parser. ADR 0048's "run pure templaters while compiling" would have kept one implementation, but nothing runs user code at compile time, and the port keeps the grammar next to the literal lowering it must match anyway (spans, components, hole positions).
xmlas constructor calls likehtml. TheXmlwrapper is an opaque string, not anElement; rendering through the kept helper is byte-identical and adds no Core concept.- Recovering after a pug error to report more of them. The runtime panicked on the first; one clear spanned error is already the improvement, and recovery rules would be guesswork.