diff options
author | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2017-01-03 09:56:08 +0100 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2017-01-03 09:56:08 +0100 |
commit | 3e7983d7af8d19393507e50778b818f8dcf24b91 (patch) | |
tree | ca7d45b89cf8fd5c9ba581a63a4a6b1b67f06471 /askama_codegen/src/generator.rs | |
parent | d82a8fdf39783e3bfae6b2ea9eb08f011ba195b7 (diff) | |
download | askama-3e7983d7af8d19393507e50778b818f8dcf24b91.tar.gz askama-3e7983d7af8d19393507e50778b818f8dcf24b91.tar.bz2 askama-3e7983d7af8d19393507e50778b818f8dcf24b91.zip |
Extend parser to allow different expression types
Diffstat (limited to '')
-rw-r--r-- | askama_codegen/src/generator.rs | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/askama_codegen/src/generator.rs b/askama_codegen/src/generator.rs index 34c9757..b1babce 100644 --- a/askama_codegen/src/generator.rs +++ b/askama_codegen/src/generator.rs @@ -1,4 +1,4 @@ -use parser::Node; +use parser::{Expr, Node}; use std::str; struct Generator { @@ -56,18 +56,24 @@ impl Generator { self.writeln(");"); } - fn visit_expr(&mut self, s: &[u8]) { + fn visit_var(&mut self, s: &[u8]) { let var_name = str::from_utf8(s).unwrap(); let code = format!("std::fmt::Write::write_fmt(\ &mut buf, format_args!(\"{{}}\", self.{})).unwrap();", var_name); self.writeln(&code); } + fn visit_expr(&mut self, expr: &Expr) { + match expr { + &Expr::Var(s) => self.visit_var(s), + } + } + fn handle(&mut self, tokens: &Vec<Node>) { for n in tokens { match n { &Node::Lit(val) => { self.visit_lit(val); }, - &Node::Expr(val) => { self.visit_expr(val); }, + &Node::Expr(ref val) => { self.visit_expr(&val); }, } } } |