mirror of
https://github.com/askama-rs/askama.git
synced 2025-10-02 07:20:55 +00:00
Pass Node
parsing level to expressions
This commit is contained in:
parent
238e4bbad7
commit
eef38cea67
@ -352,5 +352,5 @@ impl Level {
|
|||||||
Level(self.0 - 1)
|
Level(self.0 - 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
const MAX_DEPTH: u8 = 64;
|
const MAX_DEPTH: u8 = 128;
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ use nom::{error_position, IResult};
|
|||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
bool_lit, char_lit, identifier, is_ws, keyword, num_lit, path_or_identifier, skip_till,
|
bool_lit, char_lit, identifier, is_ws, keyword, num_lit, path_or_identifier, skip_till,
|
||||||
str_lit, ws, Expr, Level, PathOrIdentifier, State,
|
str_lit, ws, Expr, PathOrIdentifier, State,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
@ -50,8 +50,8 @@ impl<'a> Node<'a> {
|
|||||||
let mut p = delimited(
|
let mut p = delimited(
|
||||||
|i| s.tag_block_start(i),
|
|i| s.tag_block_start(i),
|
||||||
alt((
|
alt((
|
||||||
map(Call::parse, Self::Call),
|
map(|i| Call::parse(i, s), Self::Call),
|
||||||
map(Let::parse, Self::Let),
|
map(|i| Let::parse(i, s), Self::Let),
|
||||||
map(|i| If::parse(i, s), Self::If),
|
map(|i| If::parse(i, s), Self::If),
|
||||||
map(|i| Loop::parse(i, s), |l| Self::Loop(Box::new(l))),
|
map(|i| Loop::parse(i, s), |l| Self::Loop(Box::new(l))),
|
||||||
map(|i| Match::parse(i, s), Self::Match),
|
map(|i| Match::parse(i, s), Self::Match),
|
||||||
@ -105,7 +105,7 @@ impl<'a> Node<'a> {
|
|||||||
|i| s.tag_expr_start(i),
|
|i| s.tag_expr_start(i),
|
||||||
cut(tuple((
|
cut(tuple((
|
||||||
opt(Whitespace::parse),
|
opt(Whitespace::parse),
|
||||||
ws(|i| Expr::parse(i, Level::default())),
|
ws(|i| Expr::parse(i, s.level.get())),
|
||||||
opt(Whitespace::parse),
|
opt(Whitespace::parse),
|
||||||
|i| s.tag_expr_end(i),
|
|i| s.tag_expr_end(i),
|
||||||
))),
|
))),
|
||||||
@ -295,7 +295,7 @@ impl<'a> Cond<'a> {
|
|||||||
opt(Whitespace::parse),
|
opt(Whitespace::parse),
|
||||||
ws(keyword("else")),
|
ws(keyword("else")),
|
||||||
cut(tuple((
|
cut(tuple((
|
||||||
opt(CondTest::parse),
|
opt(|i| CondTest::parse(i, s)),
|
||||||
opt(Whitespace::parse),
|
opt(Whitespace::parse),
|
||||||
|i| s.tag_block_end(i),
|
|i| s.tag_block_end(i),
|
||||||
cut(|i| Node::many(i, s)),
|
cut(|i| Node::many(i, s)),
|
||||||
@ -320,7 +320,7 @@ pub struct CondTest<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> CondTest<'a> {
|
impl<'a> CondTest<'a> {
|
||||||
fn parse(i: &'a str) -> IResult<&'a str, Self> {
|
fn parse(i: &'a str, s: &State<'_>) -> IResult<&'a str, Self> {
|
||||||
let mut p = preceded(
|
let mut p = preceded(
|
||||||
ws(keyword("if")),
|
ws(keyword("if")),
|
||||||
cut(tuple((
|
cut(tuple((
|
||||||
@ -329,7 +329,7 @@ impl<'a> CondTest<'a> {
|
|||||||
ws(Target::parse),
|
ws(Target::parse),
|
||||||
ws(char('=')),
|
ws(char('=')),
|
||||||
)),
|
)),
|
||||||
ws(|i| Expr::parse(i, Level::default())),
|
ws(|i| Expr::parse(i, s.level.get())),
|
||||||
))),
|
))),
|
||||||
);
|
);
|
||||||
let (i, (target, expr)) = p(i)?;
|
let (i, (target, expr)) = p(i)?;
|
||||||
@ -377,7 +377,7 @@ impl<'a> Loop<'a> {
|
|||||||
|
|
||||||
let if_cond = preceded(
|
let if_cond = preceded(
|
||||||
ws(keyword("if")),
|
ws(keyword("if")),
|
||||||
cut(ws(|i| Expr::parse(i, Level::default()))),
|
cut(ws(|i| Expr::parse(i, s.level.get()))),
|
||||||
);
|
);
|
||||||
let else_block = |i| {
|
let else_block = |i| {
|
||||||
let mut p = preceded(
|
let mut p = preceded(
|
||||||
@ -402,7 +402,7 @@ impl<'a> Loop<'a> {
|
|||||||
ws(Target::parse),
|
ws(Target::parse),
|
||||||
ws(keyword("in")),
|
ws(keyword("in")),
|
||||||
cut(tuple((
|
cut(tuple((
|
||||||
ws(|i| Expr::parse(i, Level::default())),
|
ws(|i| Expr::parse(i, s.level.get())),
|
||||||
opt(if_cond),
|
opt(if_cond),
|
||||||
opt(Whitespace::parse),
|
opt(Whitespace::parse),
|
||||||
|i| s.tag_block_end(i),
|
|i| s.tag_block_end(i),
|
||||||
@ -537,14 +537,14 @@ pub struct Call<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Call<'a> {
|
impl<'a> Call<'a> {
|
||||||
fn parse(i: &'a str) -> IResult<&'a str, Self> {
|
fn parse(i: &'a str, s: &State<'_>) -> IResult<&'a str, Self> {
|
||||||
let mut p = tuple((
|
let mut p = tuple((
|
||||||
opt(Whitespace::parse),
|
opt(Whitespace::parse),
|
||||||
ws(keyword("call")),
|
ws(keyword("call")),
|
||||||
cut(tuple((
|
cut(tuple((
|
||||||
opt(tuple((ws(identifier), ws(tag("::"))))),
|
opt(tuple((ws(identifier), ws(tag("::"))))),
|
||||||
ws(identifier),
|
ws(identifier),
|
||||||
opt(ws(|nested| Expr::arguments(nested, Level::default()))),
|
opt(ws(|nested| Expr::arguments(nested, s.level.get()))),
|
||||||
opt(Whitespace::parse),
|
opt(Whitespace::parse),
|
||||||
))),
|
))),
|
||||||
));
|
));
|
||||||
@ -577,7 +577,7 @@ impl<'a> Match<'a> {
|
|||||||
opt(Whitespace::parse),
|
opt(Whitespace::parse),
|
||||||
ws(keyword("match")),
|
ws(keyword("match")),
|
||||||
cut(tuple((
|
cut(tuple((
|
||||||
ws(|i| Expr::parse(i, Level::default())),
|
ws(|i| Expr::parse(i, s.level.get())),
|
||||||
opt(Whitespace::parse),
|
opt(Whitespace::parse),
|
||||||
|i| s.tag_block_end(i),
|
|i| s.tag_block_end(i),
|
||||||
cut(tuple((
|
cut(tuple((
|
||||||
@ -739,7 +739,7 @@ pub struct Let<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Let<'a> {
|
impl<'a> Let<'a> {
|
||||||
fn parse(i: &'a str) -> IResult<&'a str, Self> {
|
fn parse(i: &'a str, s: &State<'_>) -> IResult<&'a str, Self> {
|
||||||
let mut p = tuple((
|
let mut p = tuple((
|
||||||
opt(Whitespace::parse),
|
opt(Whitespace::parse),
|
||||||
ws(alt((keyword("let"), keyword("set")))),
|
ws(alt((keyword("let"), keyword("set")))),
|
||||||
@ -747,7 +747,7 @@ impl<'a> Let<'a> {
|
|||||||
ws(Target::parse),
|
ws(Target::parse),
|
||||||
opt(preceded(
|
opt(preceded(
|
||||||
ws(char('=')),
|
ws(char('=')),
|
||||||
ws(|i| Expr::parse(i, Level::default())),
|
ws(|i| Expr::parse(i, s.level.get())),
|
||||||
)),
|
)),
|
||||||
opt(Whitespace::parse),
|
opt(Whitespace::parse),
|
||||||
))),
|
))),
|
||||||
@ -775,7 +775,7 @@ impl<'a> If<'a> {
|
|||||||
fn parse(i: &'a str, s: &State<'_>) -> IResult<&'a str, Self> {
|
fn parse(i: &'a str, s: &State<'_>) -> IResult<&'a str, Self> {
|
||||||
let mut p = tuple((
|
let mut p = tuple((
|
||||||
opt(Whitespace::parse),
|
opt(Whitespace::parse),
|
||||||
CondTest::parse,
|
|i| CondTest::parse(i, s),
|
||||||
cut(tuple((
|
cut(tuple((
|
||||||
opt(Whitespace::parse),
|
opt(Whitespace::parse),
|
||||||
|i| s.tag_block_end(i),
|
|i| s.tag_block_end(i),
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
error: problems parsing template source at row 8, column 36 near:
|
error: problems parsing template source at row 14, column 34 near:
|
||||||
"{%if 1%}{%if 1%}{%if 1%}{%if 1%}{%if 1%}"...
|
"%}{%if 1%}{%if 1%}{%if 1%}{%if 1%}{%if 1"...
|
||||||
--> tests/ui/excessive_nesting.rs:3:10
|
--> tests/ui/excessive_nesting.rs:3:10
|
||||||
|
|
|
|
||||||
3 | #[derive(Template)]
|
3 | #[derive(Template)]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user