snor v0.4.0 Snor.Parser

Convert a string into an intermediate representation - a list of nodes.

A node could be one of (mainly) -

  • A plaintext node
  • A function node
  • A block node
  • An interpolation node

Link to this section Summary

Types

An argument pair

A block node

A function node

An interpolation node

The result of a parse_* operation

A parsed node

A parser

A plaintext node

Represents remaining tokens after a node was parsed and extracted

A grapheme from the template that was passed in

Functions

Parse a string into a list of nodes

Link to this section Types

Link to this type

argument_pair()

argument_pair() :: %{key: String.t(), value: [parsed_node()]}

An argument pair

Link to this type

block_node()

block_node() :: %{
  with_scope: String.t(),
  children: [parsed_node()],
  negative: boolean()
}

A block node

Link to this type

function_node()

function_node() :: %{function: String.t(), arguments: [argument_pair()]}

A function node

Link to this type

interpolation_node()

interpolation_node() :: %{interpolation: String.t()}

An interpolation node

Link to this type

parse_result()

parse_result() :: {:error, String.t()} | {:ok, parsed_node() | any(), binary()}

The result of a parse_* operation

A parsed node

Link to this type

parser()

parser() :: function()

A parser

Link to this type

plaintext_node()

plaintext_node() :: %{plaintext: String.t()}

A plaintext node

Link to this type

remaining_tokens()

remaining_tokens() :: [token()]

Represents remaining tokens after a node was parsed and extracted

A grapheme from the template that was passed in

Link to this section Functions

Link to this function

parse(input)

parse(binary()) :: [parsed_node()]

Parse a string into a list of nodes

Examples

iex> Snor.Parser.parse("Hello")
[%{plaintext: "Hello"}]

iex> Snor.Parser.parse("{{name}}")
[%{interpolation: "name"}]

iex> Snor.Parser.parse("{{upcase item='Jane'}}")
[%{arguments: [%{key: "item", value: [%{plaintext: "Jane"}]}], function: "upcase"}]

iex> Snor.Parser.parse("{{#person}}{{name}}{{/person}}")
[%{children: [%{interpolation: "name"}], negative: false, with_scope: "person"}]