tour_core/lib.rs
1//! The [`tour`][1] template parser.
2//!
3//! The [`Parser`] type will only scan for delimiters to split expressions and static contents.
4//! [`Parser`] requires a [`Visitor`] implementation which will actually process the inputs.
5//!
6//! For example:
7//!
8//! ```html
9//! Hello {{ name.to_uppercase() }}
10//! ```
11//!
12//! [`Parser`] will split the input, and call [`Visitor::visit_static`] with `"Hello "`, and
13//! [`Visitor::visit_expr`] with `"name.to_uppercase()"`.
14//!
15//! This separation allows for both compile time and runtime template loading without bringing an
16//! entire parser in the binary.
17//!
18//! The [`tour-macros`][2] contains implementation of [`Visitor`] utilizing the [`syn`][1]
19//! crate, which allows rust expression inside template.
20//!
21//! There is also [`StaticVisitor`] that only collect static content. This implementations is used
22//! in runtime template reloading.
23//!
24//! # Example
25//!
26//! ```
27//! use tour_core::{Parser, StaticVisitor};
28//!
29//! let source = "Hello {{ name.to_uppercase() }} !";
30//!
31//! let visitor = Parser::new(source, StaticVisitor::new()).parse().unwrap();
32//!
33//! assert_eq!(&visitor.statics[..], &["Hello "," !"]);
34//! ```
35//!
36//! [1]: <https://docs.rs/tour>
37//! [2]: <https://docs.rs/tour-macros>
38//! [3]: <https://docs.rs/syn>
39mod syntax;
40mod visitor;
41mod parser;
42mod error;
43
44pub use syntax::Delimiter;
45pub use visitor::{Visitor, StaticVisitor};
46pub use parser::Parser;
47pub use error::{Result, ParseError};