mirror of
https://github.com/askama-rs/askama.git
synced 2025-09-28 13:30:59 +00:00

This implementation resolves djc/askama#44 by changing the precedence implementation. The previous solution was very slow because it had to try to parse all combinations of precedence layers leading to 2^9 iterations for each expr_any. This is solved by reusing the left operand instead of reparsing it when the operator isn't found. This implementation also solves another related issue that expressions with multiple operators couldn't be parsed, for example {{1 * 2 * 3}}. This is handled by using expr_any for the right operand instead of only using higher level precedence layers.
16 lines
268 B
Rust
16 lines
268 B
Rust
#[macro_use]
|
|
extern crate askama;
|
|
|
|
use askama::Template;
|
|
|
|
#[derive(Template)]
|
|
#[template(path = "precedence.html")]
|
|
struct PrecedenceTemplate {
|
|
}
|
|
|
|
#[test]
|
|
fn test_precedence() {
|
|
let t = PrecedenceTemplate { };
|
|
assert_eq!(t.render().unwrap(), "6".repeat(7));
|
|
}
|