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.
- Static
Visitor Visitorimplementation that only collect static content.
Enums§
- Delimiter
- An expression delimiter.
- Parse
Error - An error that may occur during parsing in
Parser.
Traits§
Type Aliases§
- Result
Resultalias forParseError.