Skip to main content

Module template

Module template 

Source
Expand description

The LGX template parser — HTML tokens plus Jinja-style {…} tags into a template tree.

Pure and grammar-agnostic about LOGOS: every expression (a hole, a condition, an iterable, a filter argument) comes out as TExpr — its text and byte offset — for the LOGOS parser to sub-lex with the real expression parser, so a mistake inside a hole is reported at the hole. This module owns everything structural instead:

  • nesting: elements close with their end tag, tags close with {end}, and the two may not cross ({if a:}<p>{end}</p> is an error at the {end});
  • the tags: {if c:}/{else if c:}/{else:}, {for each x in xs[, keyed by k][, at index i]:} with an {else:} arm for an empty collection, {inspect v:}/{when Pat:}, {let x be e}, {extends Layout} (first, or nowhere), {block name:}…{end} / {block name}, {children}, {raw e}, {# a comment #}, and {end};
  • holes with filters: {price | money | pad 8} — a filter is a function name followed by its extra arguments, split at the top level (a | inside a string or parens is not a filter);
  • components: a Capitalized tag is a component use, its attributes are props;
  • directives: on-<event>[.mod…]={…}, bind={field}, class:name={…};
  • whitespace: text that is only whitespace AND contains a newline is formatting and is dropped; other whitespace runs collapse to one space; <pre>/<textarea> are verbatim.

A misspelled tag word can only look like a hole, so a hole whose text ends in : is reported as a tag-like hole with the likely fix.

Structs§

TExpr
A LOGOS expression kept as text, with the byte offset of text in the template source.
TFilter
One filter application: | name arg arg….
TemplateError

Enums§

RetiredForm
A line of the retired Render: dialect, which a view no longer reads.
TAttr
An attribute or directive on an element / a prop on a component.
TNode
One node of the template tree.
TemplateErrorKind

Constants§

TAG_ALIASES
Tag words other template languages use, and the LGX tag each one means. Each is refused with the LGX spelling rather than read as a hole naming a variable called elif.

Functions§

parse
Parse a raw view body into template nodes.
print
Print a template tree back to LGX source. parse(print(t)) yields t again (spans aside), and printing is idempotent; text and attribute values are escaped so that no character can be re-read as markup or a hole.
retired_view_form
The retired form line is written in, read from the WHOLE line and only in the dialect’s exact shapes, so text that merely mentions a tag word (a: first option, Note: see below) is not one: an HTML element name, optionally a bracketed attribute list, then : and nothing, a string literal, or a call; or css followed by a string literal.