aboutsummaryrefslogtreecommitdiffstats
path: root/askama_parser/src/lib.rs
diff options
context:
space:
mode:
authorLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2023-09-28 15:20:04 +0200
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2023-09-28 17:28:26 +0200
commit57181752917c67a007c86fdbe133d2c64db7c749 (patch)
tree5a05699619b35c6a580d1cbd7abf7fdcc8367851 /askama_parser/src/lib.rs
parent5ab8813fe29cfbc034b6f99fc36064dcd1a5bd3e (diff)
downloadaskama-57181752917c67a007c86fdbe133d2c64db7c749.tar.gz
askama-57181752917c67a007c86fdbe133d2c64db7c749.tar.bz2
askama-57181752917c67a007c86fdbe133d2c64db7c749.zip
Move Level into the crate root
Diffstat (limited to 'askama_parser/src/lib.rs')
-rw-r--r--askama_parser/src/lib.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/askama_parser/src/lib.rs b/askama_parser/src/lib.rs
index 1e48262..de88a20 100644
--- a/askama_parser/src/lib.rs
+++ b/askama_parser/src/lib.rs
@@ -324,3 +324,18 @@ impl Default for Syntax<'static> {
}
}
}
+
+#[derive(Clone, Copy, Default)]
+pub(crate) struct Level(u8);
+
+impl Level {
+ fn nest(self, i: &str) -> Result<Level, nom::Err<nom::error::Error<&str>>> {
+ if self.0 >= Self::MAX_DEPTH {
+ return Err(nom::Err::Failure(error_position!(i, ErrorKind::TooLarge)));
+ }
+
+ Ok(Level(self.0 + 1))
+ }
+
+ const MAX_DEPTH: u8 = 64;
+}