Solid.Parser (solid v1.0.0-rc.0)
View SourceThis module contains functions to parse Liquid templates
Summary
Functions
Tries to tokenize a tag entry if the tag name is included in the tag_names
Grab the line and column meta information of the first token
Parse text
Parses a Liquid entry
Parses a Liquid entry until one of the tags is found The main use case for this function is to parse nested liquid entries until one of the tags is found. For example an if block
Remove blank text when the entries account for a "blank body". Check Solid.Block.blank?/1
protocol
and the implementations
Types
@type entry() :: Solid.Text.t() | Solid.Object.t() | Solid.Renderable.t()
@type errors() :: [{binary(), Solid.Lexer.loc()}]
@type parse_tree() :: [entry()]
Functions
@spec maybe_tokenize_tag(binary() | [binary()], Solid.ParserContext.t()) :: {:tag, binary(), Solid.Lexer.tokens(), Solid.ParserContext.t()} | {:not_found, Solid.ParserContext.t()}
Tries to tokenize a tag entry if the tag name is included in the tag_names
@spec meta_head([Solid.Lexer.token(), ...]) :: Solid.Lexer.loc()
Grab the line and column meta information of the first token
@spec parse( binary(), keyword() ) :: {:ok, parse_tree()} | {:error, errors()}
Parse text
It accepts a :tags option to specify a map of tags to use. See Solid.Tag.default_tags/0
@spec parse_liquid_entry(Solid.ParserContext.t()) :: :ok | {:ok, [entry()], Solid.ParserContext.t()} | {:error, binary(), Solid.Lexer.loc(), Solid.ParserContext.t()}
Parses a Liquid entry
Returns :ok if there is nothing else to parse.
@spec parse_until( Solid.ParserContext.t(), tags :: [binary()] | binary(), reason :: binary() ) :: {:ok, parse_tree(), binary(), Solid.Lexer.tokens(), Solid.ParserContext.t()} | {:error, binary(), Solid.Lexer.loc()}
Parses a Liquid entry until one of the tags is found The main use case for this function is to parse nested liquid entries until one of the tags is found. For example an if block:
{% if true % } Text {{ object }} {% endif %}
using parse_until(context, "endif", "Expected endif")
will parse every liquid entry
until an endif
tag is found, the end of the template is reached or a parsing error occured.
If one of the tags is found return what was parsed until such tag was found
If none of the tags are found, returns the error tuple with the reason
@spec remove_blank_text_if_blank_body(parse_tree()) :: parse_tree()
Remove blank text when the entries account for a "blank body". Check Solid.Block.blank?/1
protocol
and the implementations