Packages

HTML templates → type-safe Gleam modules. Write familiar markup instead of nested function calls. No more bracket-counting nightmares.

Current section

Files

Jump to
ghtml src ghtml@types.erl
Raw

src/ghtml@types.erl

-module(ghtml@types).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/ghtml/types.gleam").
-export([start_position/0, point_span/1]).
-export_type([position/0, span/0, parse_error/0, attr/0, token/0, node_/0, case_branch/0, template/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(
" Type definitions for the Lustre template parser and code generator.\n"
"\n"
" This module defines all core types including source positions, tokens,\n"
" AST nodes, and the parsed template structure.\n"
).
-type position() :: {position, integer(), integer()}.
-type span() :: {span, position(), position()}.
-type parse_error() :: {parse_error, span(), binary()}.
-type attr() :: {static_attr, binary(), binary()} |
{dynamic_attr, binary(), binary()} |
{event_attr, binary(), binary()} |
{boolean_attr, binary()}.
-type token() :: {import, binary(), span()} |
{params, list({binary(), binary()}), span()} |
{html_open, binary(), list(attr()), boolean(), span()} |
{html_close, binary(), span()} |
{text, binary(), span()} |
{expr, binary(), span()} |
{if_start, binary(), span()} |
{'else', span()} |
{if_end, span()} |
{each_start, binary(), binary(), gleam@option:option(binary()), span()} |
{each_end, span()} |
{case_start, binary(), span()} |
{case_pattern, binary(), span()} |
{case_end, span()} |
{comment, span()}.
-type node_() :: {element, binary(), list(attr()), list(node_()), span()} |
{text_node, binary(), span()} |
{expr_node, binary(), span()} |
{if_node, binary(), list(node_()), list(node_()), span()} |
{each_node,
binary(),
binary(),
gleam@option:option(binary()),
list(node_()),
span()} |
{case_node, binary(), list(case_branch()), span()} |
{fragment, list(node_()), span()}.
-type case_branch() :: {case_branch, binary(), list(node_()), span()}.
-type template() :: {template,
list(binary()),
list({binary(), binary()}),
list(node_())}.
-file("src/ghtml/types.gleam", 91).
?DOC(" Create a position at line 1, column 1\n").
-spec start_position() -> position().
start_position() ->
{position, 1, 1}.
-file("src/ghtml/types.gleam", 96).
?DOC(" Create a zero-length span at a position\n").
-spec point_span(position()) -> span().
point_span(Pos) ->
{span, Pos, Pos}.