aboutsummaryrefslogtreecommitdiffstats
path: root/askama_derive/src/generator.rs
diff options
context:
space:
mode:
authorLibravatar René Kijewski <rene.kijewski@fu-berlin.de>2023-08-01 04:04:27 +0200
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2023-08-01 13:04:41 +0200
commitc5c46ada406aea830293a22bcef64a0d6205b3f4 (patch)
treebb17d5a179c330e433ef20f1919c285ff9a4c723 /askama_derive/src/generator.rs
parentfa3a3271ee8d2514cf96e6a7733312a958a78962 (diff)
downloadaskama-c5c46ada406aea830293a22bcef64a0d6205b3f4.tar.gz
askama-c5c46ada406aea830293a22bcef64a0d6205b3f4.tar.bz2
askama-c5c46ada406aea830293a22bcef64a0d6205b3f4.zip
parser: rename `Node::Cond` into `If` and add type
Diffstat (limited to '')
-rw-r--r--askama_derive/src/generator.rs15
1 files changed, 7 insertions, 8 deletions
diff --git a/askama_derive/src/generator.rs b/askama_derive/src/generator.rs
index 643fb73..4cf972b 100644
--- a/askama_derive/src/generator.rs
+++ b/askama_derive/src/generator.rs
@@ -3,7 +3,7 @@ use crate::heritage::{Context, Heritage};
use crate::input::{Print, Source, TemplateInput};
use crate::CompileError;
use parser::{
- Call, Cond, CondTest, Expr, Let, Lit, Loop, Match, Node, Parsed, Target, Whitespace, Ws,
+ Call, CondTest, Expr, If, Let, Lit, Loop, Match, Node, Parsed, Target, Whitespace, Ws,
};
use proc_macro::TokenStream;
@@ -640,8 +640,8 @@ impl<'a> Generator<'a> {
Node::Let(ref l) => {
self.write_let(buf, l)?;
}
- Node::Cond(ref conds, ws) => {
- size_hint += self.write_cond(ctx, buf, conds, ws)?;
+ Node::If(ref i) => {
+ size_hint += self.write_if(ctx, buf, i)?;
}
Node::Match(ref m) => {
size_hint += self.write_match(ctx, buf, m)?;
@@ -707,17 +707,16 @@ impl<'a> Generator<'a> {
Ok(size_hint)
}
- fn write_cond(
+ fn write_if(
&mut self,
ctx: &'a Context<'_>,
buf: &mut Buffer,
- conds: &'a [Cond<'_>],
- ws: Ws,
+ i: &'a If<'_>,
) -> Result<usize, CompileError> {
let mut flushed = 0;
let mut arm_sizes = Vec::new();
let mut has_else = false;
- for (i, cond) in conds.iter().enumerate() {
+ for (i, cond) in i.branches.iter().enumerate() {
self.handle_ws(cond.ws);
flushed += self.write_buf_writable(buf)?;
if i > 0 {
@@ -764,7 +763,7 @@ impl<'a> Generator<'a> {
arm_size += self.handle(ctx, &cond.nodes, buf, AstLevel::Nested)?;
arm_sizes.push(arm_size);
}
- self.handle_ws(ws);
+ self.handle_ws(i.ws);
flushed += self.write_buf_writable(buf)?;
buf.writeln("}")?;