aboutsummaryrefslogtreecommitdiffstats
path: root/askama_parser/src
diff options
context:
space:
mode:
Diffstat (limited to 'askama_parser/src')
-rw-r--r--askama_parser/src/lib.rs15
-rw-r--r--askama_parser/src/node.rs12
2 files changed, 23 insertions, 4 deletions
diff --git a/askama_parser/src/lib.rs b/askama_parser/src/lib.rs
index de88a20..3428735 100644
--- a/askama_parser/src/lib.rs
+++ b/askama_parser/src/lib.rs
@@ -255,6 +255,7 @@ fn path_or_identifier(i: &str) -> IResult<&str, PathOrIdentifier<'_>> {
struct State<'a> {
syntax: &'a Syntax<'a>,
loop_depth: Cell<usize>,
+ level: Cell<Level>,
}
impl<'a> State<'a> {
@@ -262,9 +263,19 @@ impl<'a> State<'a> {
State {
syntax,
loop_depth: Cell::new(0),
+ level: Cell::new(Level::default()),
}
}
+ fn nest<'b>(&self, i: &'b str) -> Result<(), nom::Err<nom::error::Error<&'b str>>> {
+ self.level.set(self.level.get().nest(i)?);
+ Ok(())
+ }
+
+ fn leave(&self) {
+ self.level.set(self.level.get().leave());
+ }
+
fn tag_block_start<'i>(&self, i: &'i str) -> IResult<&'i str, &'i str> {
tag(self.syntax.block_start)(i)
}
@@ -337,5 +348,9 @@ impl Level {
Ok(Level(self.0 + 1))
}
+ fn leave(&self) -> Self {
+ Level(self.0 - 1)
+ }
+
const MAX_DEPTH: u8 = 64;
}
diff --git a/askama_parser/src/node.rs b/askama_parser/src/node.rs
index f25f25a..1909f6c 100644
--- a/askama_parser/src/node.rs
+++ b/askama_parser/src/node.rs
@@ -47,7 +47,7 @@ impl<'a> Node<'a> {
}
fn parse(i: &'a str, s: &State<'_>) -> IResult<&'a str, Self> {
- let mut p = tuple((
+ let mut p = delimited(
|i| s.tag_block_start(i),
alt((
map(Call::parse, Self::Call),
@@ -65,9 +65,13 @@ impl<'a> Node<'a> {
|i| Self::r#continue(i, s),
)),
cut(|i| s.tag_block_end(i)),
- ));
- let (i, (_, contents, _)) = p(i)?;
- Ok((i, contents))
+ );
+
+ s.nest(i)?;
+ let result = p(i);
+ s.leave();
+
+ result
}
fn r#break(i: &'a str, s: &State<'_>) -> IResult<&'a str, Self> {