Parser

Type Alias Parser 

Source
pub type Parser<EscapeParser, QueryParser> = EnclosedTemplateParser<EscapeParser, QueryParser>;

Aliased Type§

pub struct Parser<EscapeParser, QueryParser> {
    pub config: ParserConfig,
    pub escape_parser: EscapeParser,
    pub query_parser: QueryParser,
}

Fields§

§config: ParserConfig§escape_parser: EscapeParser§query_parser: QueryParser

Implementations§

Source§

impl<EscapeParser, QueryParser> Parser<EscapeParser, QueryParser>

Source

pub fn with_config(self, config: ParserConfig) -> Self

Replace Parser::config.

Source

pub fn with_escape_parser<NewEscapeParser>( self, escape_parser: NewEscapeParser, ) -> Parser<NewEscapeParser, QueryParser>

Source

pub fn with_query_parser<NewQueryParser>( self, query_parser: NewQueryParser, ) -> Parser<EscapeParser, NewQueryParser>

Source§

impl Parser<(), ()>

Source

pub fn curly_braces() -> Self

Create a builder of an EnclosedTemplateParser of templates whose queries should be placed between curly braces.

The curly braces can be replaced by replacing the config.

The value returned from this function is not useful immediately. The query parser and the escape parser must be replaced first.

Usage example:

use lazy_template::{
    enclosed::{Parser, SimpleEscapeParser, SimpleQuery, SimpleQueryParser},
    IntoTemplateSystem,
};
let output = Parser::curly_braces()
    .with_escape_parser(SimpleEscapeParser)
    .with_query_parser(SimpleQueryParser)
    .into_template_system::<SimpleQuery>()
    .lazy_parse("{name} is a {age} years old {descriptor}")
    .to_string(|query| match query {
        "name" => Ok("Alice"),
        "age" => Ok("20"),
        "descriptor" => Ok("girl"),
        _ => Err(format!("Can't answer {query:?}")),
    })
    .unwrap();
assert_eq!(output, "Alice is a 20 years old girl");

Trait Implementations§

Source§

impl<'a, EscapeParser, QueryParser> Parse<'a> for Parser<EscapeParser, QueryParser>
where EscapeParser: Parse<'a, ComponentParserInput<'a>, Output = char>, EscapeParser::Error: IntoSkipOrFatal, QueryParser: Parse<'a, ComponentParserInput<'a>>, QueryParser::Error: IntoSkipOrFatal,

Source§

type Output = Segment<<QueryParser as Parse<'a, ComponentParserInput<'a>>>::Output>

Source§

type Error = ParseError<<<EscapeParser as Parse<'a, ComponentParserInput<'a>>>::Error as IntoSkipOrFatal>::Fatal, <<QueryParser as Parse<'a, ComponentParserInput<'a>>>::Error as IntoSkipOrFatal>::Fatal>

Source§

fn parse(&self, input: &'a str) -> Result<(Self::Output, &'a str), Self::Error>