View Source Alembic.Lexer (alembic v0.1.0)

Convert Alembic template source into lexical tokens.

Summary

Functions

Converts raw template source into a flat list of Alembic.Token.t().

Types

@type position() :: Alembic.Token.position()
@type reason() ::
  {:unterminated_output, position()}
  | {:unterminated_tag, position()}
  | {:empty_output_tag, position()}
  | {:unterminated_comment, position()}
  | {:unterminated_raw, position()}

Functions

@spec tokenize(String.t()) :: {:ok, [Alembic.Token.t()]} | {:error, reason()}

Converts raw template source into a flat list of Alembic.Token.t().

Examples

iex> Alembic.Lexer.tokenize("Hello {{ name }}!")
{:ok,
 [
   {:text, "Hello ", %{line: 1, col: 1}},
   {:output, "name", false, false, %{line: 1, col: 7}},
   {:text, "!", %{line: 1, col: 17}}
 ]}

iex> Alembic.Lexer.tokenize("{{ name")
{:error, {:unterminated_output, %{line: 1, col: 1}}}