diff options
author | Nathan Lapel <nathanlapel@gmail.com> | 2020-03-15 11:46:31 +0100 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2020-03-18 22:33:51 +0100 |
commit | 520c5d7d5f09c0b205e6e1c471483730380c5e33 (patch) | |
tree | 23b9c9560ebc78d74ddee2a71d48b3025659644e /askama_shared/src/generator.rs | |
parent | cff49453a851029f87b35512f5234a999fea3e6c (diff) | |
download | askama-520c5d7d5f09c0b205e6e1c471483730380c5e33.tar.gz askama-520c5d7d5f09c0b205e6e1c471483730380c5e33.tar.bz2 askama-520c5d7d5f09c0b205e6e1c471483730380c5e33.zip |
Support function calls
Diffstat (limited to '')
-rw-r--r-- | askama_shared/src/generator.rs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/askama_shared/src/generator.rs b/askama_shared/src/generator.rs index 59df687..fb8619e 100644 --- a/askama_shared/src/generator.rs +++ b/askama_shared/src/generator.rs @@ -909,7 +909,9 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, 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::VarCall(var, ref args) => self.visit_var_call(buf, var, args), Expr::Path(ref path) => self.visit_path(buf, path), + Expr::PathCall(ref path, ref args) => self.visit_path_call(buf, path, args), Expr::Array(ref elements) => self.visit_array(buf, elements), Expr::Attr(ref obj, name) => self.visit_attr(buf, obj, name), Expr::Index(ref obj, ref key) => self.visit_index(buf, obj, key), @@ -1160,6 +1162,24 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { DisplayWrap::Unwrapped } + fn visit_path_call(&mut self, buf: &mut Buffer, path: &[&str], args: &[Expr]) -> DisplayWrap { + for (i, part) in path.iter().enumerate() { + if i > 0 { + buf.write("::"); + } + buf.write(part); + } + buf.write("("); + for (i, arg) in args.iter().enumerate() { + if i > 0 { + buf.write(","); + } + self.visit_expr(buf, arg); + } + buf.write(")"); + DisplayWrap::Unwrapped + } + fn visit_var(&mut self, buf: &mut Buffer, s: &str) -> DisplayWrap { if self.locals.contains(s) || s == "self" { buf.write(s); @@ -1170,6 +1190,25 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { DisplayWrap::Unwrapped } + fn visit_var_call(&mut self, buf: &mut Buffer, s: &str, args: &[Expr]) -> DisplayWrap { + buf.write("("); + if self.locals.contains(s) || s == "self" { + buf.write(s); + } else { + buf.write("self."); + buf.write(s); + } + buf.write(")("); + for (i, arg) in args.iter().enumerate() { + if i > 0 { + buf.write(","); + } + self.visit_expr(buf, arg); + } + buf.write(")"); + DisplayWrap::Unwrapped + } + fn visit_bool_lit(&mut self, buf: &mut Buffer, s: &str) -> DisplayWrap { buf.write(s); DisplayWrap::Unwrapped |