aboutsummaryrefslogtreecommitdiffstats
path: root/askama_shared/src/generator.rs
diff options
context:
space:
mode:
authorLibravatar Anthony Nowell <anowell@gmail.com>2017-10-05 02:47:36 -0600
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2017-11-02 14:58:46 +0100
commitcc51d201ab9e7ba958363d1f74b7bfd4dd12fecf (patch)
treef7c0c5ba23f1a6125846e248b73a8d273ebd7979 /askama_shared/src/generator.rs
parent751dee3fbabb35a8ad30ebdaee8e4dd4120c289a (diff)
downloadaskama-cc51d201ab9e7ba958363d1f74b7bfd4dd12fecf.tar.gz
askama-cc51d201ab9e7ba958363d1f74b7bfd4dd12fecf.tar.bz2
askama-cc51d201ab9e7ba958363d1f74b7bfd4dd12fecf.zip
support literals in match arms
Diffstat (limited to '')
-rw-r--r--askama_shared/src/generator.rs24
1 files changed, 20 insertions, 4 deletions
diff --git a/askama_shared/src/generator.rs b/askama_shared/src/generator.rs
index 6fca3fb..0c8b1e2 100644
--- a/askama_shared/src/generator.rs
+++ b/askama_shared/src/generator.rs
@@ -1,6 +1,6 @@
use filters;
use input::TemplateInput;
-use parser::{self, Cond, Expr, Macro, Node, Target, When, WS};
+use parser::{self, Cond, Expr, Macro, MatchParameter, Node, Target, When, WS};
use path;
use quote::{Tokens, ToTokens};
@@ -445,15 +445,20 @@ impl<'a> Generator<'a> {
for arm in arms {
let &(ref ws, ref variant, ref params, ref body) = arm;
self.locals.push();
- self.write(variant);
+ match *variant {
+ Some(ref param) => { self.visit_match_param(param); },
+ None => self.write("_"),
+ };
if params.len() > 0 {
self.write("(");
for (i, param) in params.iter().enumerate() {
- self.locals.insert(param);
+ if let MatchParameter::Name(ref p) = *param {
+ self.locals.insert(p);
+ }
if i > 0 {
self.write(", ");
}
- self.write(param);
+ self.visit_match_param(param);
}
self.write(")");
}
@@ -624,6 +629,17 @@ impl<'a> Generator<'a> {
}
}
+ fn visit_match_param(&mut self, param: &MatchParameter) -> DisplayWrap {
+ match *param {
+ MatchParameter::NumLit(s) => self.visit_num_lit(s),
+ MatchParameter::StrLit(s) => self.visit_str_lit(s),
+ MatchParameter::Name(s) => {
+ self.write(s);
+ DisplayWrap::Unwrapped
+ }
+ }
+ }
+
fn visit_filter(&mut self, name: &str, args: &[Expr]) -> DisplayWrap {
if name == "format" {
self._visit_format_filter(args);