aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar René Kijewski <rene.kijewski@fu-berlin.de>2023-07-31 20:54:47 +0200
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2023-07-31 21:29:35 +0200
commit107bdfdd7658919691948f629adf2254cd6aa367 (patch)
tree7d28e7b08e7bf30bc9298fdc1466476624ca50ac
parent18b6d2f38ac51dfa3207c4d509567cd0db937274 (diff)
downloadaskama-107bdfdd7658919691948f629adf2254cd6aa367.tar.gz
askama-107bdfdd7658919691948f629adf2254cd6aa367.tar.bz2
askama-107bdfdd7658919691948f629adf2254cd6aa367.zip
Fix parsing calls
This change: * adds a cut when the leading `(` was encountered, and * fixed the interaction between call expressions and boolean OR.
-rw-r--r--askama_parser/src/expr.rs8
-rw-r--r--askama_parser/src/tests.rs27
-rw-r--r--testing/tests/ui/loop_cycle_empty.stderr4
3 files changed, 33 insertions, 6 deletions
diff --git a/askama_parser/src/expr.rs b/askama_parser/src/expr.rs
index ef5c5e2..ab7caff 100644
--- a/askama_parser/src/expr.rs
+++ b/askama_parser/src/expr.rs
@@ -68,10 +68,12 @@ pub enum Expr<'a> {
impl<'a> Expr<'a> {
pub(super) fn arguments(i: &'a str) -> IResult<&'a str, Vec<Self>> {
- delimited(
+ preceded(
ws(char('(')),
- separated_list0(char(','), ws(Self::parse)),
- ws(char(')')),
+ cut(terminated(
+ separated_list0(char(','), ws(Self::parse)),
+ char(')'),
+ )),
)(i)
}
diff --git a/askama_parser/src/tests.rs b/askama_parser/src/tests.rs
index 5b3b66e..2beeb38 100644
--- a/askama_parser/src/tests.rs
+++ b/askama_parser/src/tests.rs
@@ -493,9 +493,34 @@ fn test_odd_calls() {
Ast::from_str("{{ -a(b) }}", &syntax).unwrap().nodes,
vec![Node::Expr(
Ws(None, None),
- Unary("-", Box::new(Call(Box::new(Var("a")), vec![Var("b")])),),
+ Unary("-", Box::new(Call(Box::new(Var("a")), vec![Var("b")]))),
)],
);
+ assert_eq!(
+ Ast::from_str("{{ a(b)|c }}", &syntax).unwrap().nodes,
+ vec![Node::Expr(
+ Ws(None, None),
+ Filter("c", vec![Call(Box::new(Var("a")), vec![Var("b")])]),
+ )]
+ );
+ assert_eq!(
+ Ast::from_str("{{ a(b)| c }}", &syntax).unwrap().nodes,
+ vec![Node::Expr(
+ Ws(None, None),
+ Filter("c", vec![Call(Box::new(Var("a")), vec![Var("b")])]),
+ )]
+ );
+ assert_eq!(
+ Ast::from_str("{{ a(b) |c }}", &syntax).unwrap().nodes,
+ vec![Node::Expr(
+ Ws(None, None),
+ BinOp(
+ "|",
+ Box::new(Call(Box::new(Var("a")), vec![Var("b")])),
+ Box::new(Var("c"))
+ ),
+ )]
+ );
}
#[test]
diff --git a/testing/tests/ui/loop_cycle_empty.stderr b/testing/tests/ui/loop_cycle_empty.stderr
index 13beb9a..4fc35bb 100644
--- a/testing/tests/ui/loop_cycle_empty.stderr
+++ b/testing/tests/ui/loop_cycle_empty.stderr
@@ -1,5 +1,5 @@
-error: problems parsing template source at row 1, column 34 near:
- "([]) }}{{ v }},{% endfor %}"
+error: problems parsing template source at row 1, column 35 near:
+ "[]) }}{{ v }},{% endfor %}"
--> tests/ui/loop_cycle_empty.rs:6:10
|
6 | #[derive(Template)]