diff options
author | René Kijewski <kijewski@library.vetmed.fu-berlin.de> | 2022-01-14 15:32:53 +0100 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2022-01-28 11:21:06 +0100 |
commit | da0b6ead0e75082bfffa24f8529d1f83961ba45c (patch) | |
tree | 58bbdb1de244e99c77b378a9a9d4eaf4dd873474 /askama_shared/src/generator.rs | |
parent | 85ad2e6ba3a205e9b648431318aac0e75c027a82 (diff) | |
download | askama-da0b6ead0e75082bfffa24f8529d1f83961ba45c.tar.gz askama-da0b6ead0e75082bfffa24f8529d1f83961ba45c.tar.bz2 askama-da0b6ead0e75082bfffa24f8529d1f83961ba45c.zip |
Parse tuple expressions
Askama understands how to destructure tuples in let and match
statements, but it does not understand how to build a tuple.
This PR fixes this shortcoming.
Diffstat (limited to 'askama_shared/src/generator.rs')
-rw-r--r-- | askama_shared/src/generator.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/askama_shared/src/generator.rs b/askama_shared/src/generator.rs index de2fdcb..7080b87 100644 --- a/askama_shared/src/generator.rs +++ b/askama_shared/src/generator.rs @@ -1061,6 +1061,7 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { Expr::Call(ref obj, ref args) => self.visit_call(buf, obj, args)?, Expr::RustMacro(name, args) => self.visit_rust_macro(buf, name, args), Expr::Try(ref expr) => self.visit_try(buf, expr.as_ref())?, + Expr::Tuple(ref exprs) => self.visit_tuple(buf, exprs)?, }) } @@ -1403,6 +1404,23 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { Ok(DisplayWrap::Unwrapped) } + fn visit_tuple( + &mut self, + buf: &mut Buffer, + exprs: &[Expr<'_>], + ) -> Result<DisplayWrap, CompileError> { + buf.write("("); + for (index, expr) in exprs.iter().enumerate() { + if index > 0 { + buf.write(" "); + } + self.visit_expr(buf, expr)?; + buf.write(","); + } + buf.write(")"); + Ok(DisplayWrap::Unwrapped) + } + fn visit_array( &mut self, buf: &mut Buffer, |