From cef055108de6c51c1423cd6a8919730ef01f64a3 Mon Sep 17 00:00:00 2001 From: Tuomas Siipola Date: Fri, 3 Jan 2020 20:36:17 +0200 Subject: Support char literals --- askama_derive/src/generator.rs | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'askama_derive/src/generator.rs') diff --git a/askama_derive/src/generator.rs b/askama_derive/src/generator.rs index 81f6ac9..9f60847 100644 --- a/askama_derive/src/generator.rs +++ b/askama_derive/src/generator.rs @@ -885,6 +885,7 @@ impl<'a> Generator<'a> { Expr::BoolLit(s) => self.visit_bool_lit(buf, s), Expr::NumLit(s) => self.visit_num_lit(buf, s), Expr::StrLit(s) => self.visit_str_lit(buf, s), + Expr::CharLit(s) => self.visit_char_lit(buf, s), Expr::Var(s) => self.visit_var(buf, s), Expr::Path(ref path) => self.visit_path(buf, path), Expr::Array(ref elements) => self.visit_array(buf, elements), @@ -918,6 +919,7 @@ impl<'a> Generator<'a> { expr_buf.write("&"); self.visit_str_lit(&mut expr_buf, s) } + MatchVariant::CharLit(s) => self.visit_char_lit(&mut expr_buf, s), MatchVariant::NumLit(s) => self.visit_num_lit(&mut expr_buf, s), MatchVariant::Name(s) => { expr_buf.write(s); @@ -937,6 +939,7 @@ impl<'a> Generator<'a> { let wrapped = match *param { MatchParameter::NumLit(s) => self.visit_num_lit(&mut expr_buf, s), MatchParameter::StrLit(s) => self.visit_str_lit(&mut expr_buf, s), + MatchParameter::CharLit(s) => self.visit_char_lit(&mut expr_buf, s), MatchParameter::Name(s) => { expr_buf.write(s); DisplayWrap::Unwrapped @@ -1155,6 +1158,11 @@ impl<'a> Generator<'a> { DisplayWrap::Unwrapped } + fn visit_char_lit(&mut self, buf: &mut Buffer, s: &str) -> DisplayWrap { + buf.write(&format!("'{}'", s)); + DisplayWrap::Unwrapped + } + fn visit_num_lit(&mut self, buf: &mut Buffer, s: &str) -> DisplayWrap { buf.write(s); DisplayWrap::Unwrapped -- cgit