snor v0.5.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
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
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
Link to this type
parsed_node()
parsed_node() :: plaintext_node() | interpolation_node() | block_node() | function_node()
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
Link to this section Functions
Parse a string into a list of nodes
Examples
iex> Snor.Parser.parse("Hello")
[%{plaintext: "Hello"}]
iex> Snor.Parser.parse("{{name}}")
[%{interpolation: "name", escape: true}]
iex> Snor.Parser.parse("{{{name}}}")
[%{interpolation: "name", escape: false}]
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", escape: true}], negative: false, with_scope: "person"}]