diff options
author | René Kijewski <kijewski@library.vetmed.fu-berlin.de> | 2021-06-29 14:57:20 +0200 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2021-07-01 10:24:32 +0200 |
commit | c3e8b2cc724abc063f731ba5a222324b95b72042 (patch) | |
tree | 093221ddb34096ed201542fcf2db20129a393f4a /askama_shared/src/generator.rs | |
parent | c1fa2d61468aa3591c4d6a259aa1e486eb936da9 (diff) | |
download | askama-c3e8b2cc724abc063f731ba5a222324b95b72042.tar.gz askama-c3e8b2cc724abc063f731ba5a222324b95b72042.tar.bz2 askama-c3e8b2cc724abc063f731ba5a222324b95b72042.zip |
Move visit_match_params into its own method
Diffstat (limited to 'askama_shared/src/generator.rs')
-rw-r--r-- | askama_shared/src/generator.rs | 80 |
1 files changed, 42 insertions, 38 deletions
diff --git a/askama_shared/src/generator.rs b/askama_shared/src/generator.rs index 0ce7df3..ddcc1d8 100644 --- a/askama_shared/src/generator.rs +++ b/askama_shared/src/generator.rs @@ -564,44 +564,7 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { None => buf.write("_"), }; - match params { - MatchParameters::Simple(params) => { - if !params.is_empty() { - buf.write("("); - for (i, param) in params.iter().enumerate() { - if let MatchParameter::Name(p) = *param { - self.locals.insert_with_default(p); - } - if i > 0 { - buf.write(", "); - } - self.visit_match_param(buf, param); - } - buf.write(")"); - } - } - MatchParameters::Named(params) => { - buf.write("{"); - for (i, param) in params.iter().enumerate() { - if let Some(MatchParameter::Name(p)) = param.1 { - let p = normalize_identifier(p); - self.locals.insert_with_default(p); - } else { - self.locals.insert_with_default(param.0); - } - - if i > 0 { - buf.write(", "); - } - buf.write(param.0); - if let Some(param) = ¶m.1 { - buf.write(":"); - self.visit_match_param(buf, param); - } - } - buf.write("}"); - } - } + self.visit_match_params(buf, params); buf.writeln(" => {")?; arm_size = self.handle(ctx, body, buf, AstLevel::Nested)?; @@ -1155,6 +1118,47 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { wrapped } + fn visit_match_params(&mut self, buf: &mut Buffer, params: &MatchParameters<'a>) { + match params { + MatchParameters::Simple(params) => { + if !params.is_empty() { + buf.write("("); + for (i, param) in params.iter().enumerate() { + if let MatchParameter::Name(p) = *param { + self.locals.insert_with_default(p); + } + if i > 0 { + buf.write(", "); + } + self.visit_match_param(buf, param); + } + buf.write(")"); + } + } + MatchParameters::Named(params) => { + buf.write("{"); + for (i, param) in params.iter().enumerate() { + if let Some(MatchParameter::Name(p)) = param.1 { + let p = normalize_identifier(p); + self.locals.insert_with_default(p); + } else { + self.locals.insert_with_default(param.0); + } + + if i > 0 { + buf.write(", "); + } + buf.write(param.0); + if let Some(param) = ¶m.1 { + buf.write(":"); + self.visit_match_param(buf, param); + } + } + buf.write("}"); + } + } + } + fn visit_filter( &mut self, buf: &mut Buffer, |