aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2023-09-28 15:22:58 +0200
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2023-09-28 17:28:26 +0200
commit36f4442978674a79aaebefcd4f04c7bfe6fe54c4 (patch)
tree40c53ded4ae37734cfce66c51db19df27db4d02d
parent57181752917c67a007c86fdbe133d2c64db7c749 (diff)
downloadaskama-36f4442978674a79aaebefcd4f04c7bfe6fe54c4.tar.gz
askama-36f4442978674a79aaebefcd4f04c7bfe6fe54c4.tar.bz2
askama-36f4442978674a79aaebefcd4f04c7bfe6fe54c4.zip
Require Expr::parse() callers to supply Level
-rw-r--r--askama_parser/src/expr.rs16
-rw-r--r--askama_parser/src/node.rs18
2 files changed, 18 insertions, 16 deletions
diff --git a/askama_parser/src/expr.rs b/askama_parser/src/expr.rs
index d676e85..3b6bced 100644
--- a/askama_parser/src/expr.rs
+++ b/askama_parser/src/expr.rs
@@ -76,17 +76,13 @@ impl<'a> Expr<'a> {
preceded(
ws(char('(')),
cut(terminated(
- separated_list0(char(','), ws(move |i| Self::nested(i, level))),
+ separated_list0(char(','), ws(move |i| Self::parse(i, level))),
char(')'),
)),
)(i)
}
- pub(super) fn parse(i: &'a str) -> IResult<&'a str, Self> {
- Self::nested(i, Level::default())
- }
-
- fn nested(i: &'a str, level: Level) -> IResult<&'a str, Self> {
+ pub(super) fn parse(i: &'a str, level: Level) -> IResult<&'a str, Self> {
let level = level.nest(i)?;
let range_right = move |i| {
pair(
@@ -172,7 +168,7 @@ impl<'a> Expr<'a> {
fn group(i: &'a str, level: Level) -> IResult<&'a str, Self> {
let level = level.nest(i)?;
- let (i, expr) = preceded(ws(char('(')), opt(|i| Self::nested(i, level)))(i)?;
+ let (i, expr) = preceded(ws(char('(')), opt(|i| Self::parse(i, level)))(i)?;
let expr = match expr {
Some(expr) => expr,
None => {
@@ -189,7 +185,7 @@ impl<'a> Expr<'a> {
let mut exprs = vec![expr];
let (i, _) = fold_many0(
- preceded(char(','), ws(|i| Self::nested(i, level))),
+ preceded(char(','), ws(|i| Self::parse(i, level))),
|| (),
|_, expr| {
exprs.push(expr);
@@ -205,7 +201,7 @@ impl<'a> Expr<'a> {
ws(char('[')),
cut(terminated(
map(
- separated_list0(char(','), ws(move |i| Self::nested(i, level))),
+ separated_list0(char(','), ws(move |i| Self::parse(i, level))),
Self::Array,
),
char(']'),
@@ -348,7 +344,7 @@ impl<'a> Suffix<'a> {
map(
preceded(
ws(char('[')),
- cut(terminated(ws(move |i| Expr::nested(i, level)), char(']'))),
+ cut(terminated(ws(move |i| Expr::parse(i, level)), char(']'))),
),
Self::Index,
)(i)
diff --git a/askama_parser/src/node.rs b/askama_parser/src/node.rs
index c3a59c6..f25f25a 100644
--- a/askama_parser/src/node.rs
+++ b/askama_parser/src/node.rs
@@ -101,7 +101,7 @@ impl<'a> Node<'a> {
|i| s.tag_expr_start(i),
cut(tuple((
opt(Whitespace::parse),
- ws(Expr::parse),
+ ws(|i| Expr::parse(i, Level::default())),
opt(Whitespace::parse),
|i| s.tag_expr_end(i),
))),
@@ -325,7 +325,7 @@ impl<'a> CondTest<'a> {
ws(Target::parse),
ws(char('=')),
)),
- ws(Expr::parse),
+ ws(|i| Expr::parse(i, Level::default())),
))),
);
let (i, (target, expr)) = p(i)?;
@@ -371,7 +371,10 @@ impl<'a> Loop<'a> {
result
}
- let if_cond = preceded(ws(keyword("if")), cut(ws(Expr::parse)));
+ let if_cond = preceded(
+ ws(keyword("if")),
+ cut(ws(|i| Expr::parse(i, Level::default()))),
+ );
let else_block = |i| {
let mut p = preceded(
ws(keyword("else")),
@@ -395,7 +398,7 @@ impl<'a> Loop<'a> {
ws(Target::parse),
ws(keyword("in")),
cut(tuple((
- ws(Expr::parse),
+ ws(|i| Expr::parse(i, Level::default())),
opt(if_cond),
opt(Whitespace::parse),
|i| s.tag_block_end(i),
@@ -570,7 +573,7 @@ impl<'a> Match<'a> {
opt(Whitespace::parse),
ws(keyword("match")),
cut(tuple((
- ws(Expr::parse),
+ ws(|i| Expr::parse(i, Level::default())),
opt(Whitespace::parse),
|i| s.tag_block_end(i),
cut(tuple((
@@ -738,7 +741,10 @@ impl<'a> Let<'a> {
ws(alt((keyword("let"), keyword("set")))),
cut(tuple((
ws(Target::parse),
- opt(preceded(ws(char('=')), ws(Expr::parse))),
+ opt(preceded(
+ ws(char('=')),
+ ws(|i| Expr::parse(i, Level::default())),
+ )),
opt(Whitespace::parse),
))),
));