Skip to main content

Crate tour_core

Crate tour_core 

Source
Expand description

The tour template parser.

The Parser type will only scan for delimiters to split expressions and static contents. Parser requires a Visitor implementation which will actually process the inputs.

For example:

Hello {{ name.to_uppercase() }}

Parser will split the input, and call Visitor::visit_static with "Hello ", and Visitor::visit_expr with "name.to_uppercase()".

This separation allows for both compile time and runtime template loading without bringing an entire parser in the binary.

The tour-macros contains implementation of Visitor utilizing the syn crate, which allows rust expression inside template.

There is also StaticVisitor that only collect static content. This implementations is used in runtime template reloading.

§Example

use tour_core::{Parser, StaticVisitor};

let source = "Hello {{ name.to_uppercase() }} !";

let visitor = Parser::new(source, StaticVisitor::new()).parse().unwrap();

assert_eq!(&visitor.statics[..], &["Hello "," !"]);

Structs§

Parser
Template source code parser.
StaticVisitor
Visitor implementation that only collect static content.

Enums§

Delimiter
An expression delimiter.
ParseError
An error that may occur during parsing in Parser.

Traits§

Visitor
This trait represents a visitor that collect input sources through a Parser.

Type Aliases§

Result
Result alias for ParseError.