diff options
-rw-r--r-- | askama/src/generator.rs | 16 | ||||
-rw-r--r-- | askama/src/parser.rs | 9 |
2 files changed, 12 insertions, 13 deletions
diff --git a/askama/src/generator.rs b/askama/src/generator.rs index 70bd8ff..403cd44 100644 --- a/askama/src/generator.rs +++ b/askama/src/generator.rs @@ -1,4 +1,4 @@ -use parser::{Conds, Expr, Node, Nodes, Target}; +use parser::{Cond, Expr, Node, Target}; use std::str; use std::collections::HashSet; use syn; @@ -130,7 +130,7 @@ impl Generator { self.writeln(")).unwrap();"); } - fn write_cond(&mut self, conds: &Conds) { + fn write_cond(&mut self, conds: &[Cond]) { for (i, &(ref cond, ref nodes)) in conds.iter().enumerate() { match *cond { Some(ref expr) => { @@ -151,7 +151,7 @@ impl Generator { self.writeln("}"); } - fn write_loop(&mut self, var: &Target, iter: &Expr, body: &Nodes) { + fn write_loop(&mut self, var: &Target, iter: &Expr, body: &[Node]) { self.write("for "); let targets = self.visit_target(var); @@ -176,7 +176,7 @@ impl Generator { self.writeln(&format!("self.render_block_{}_into(writer);", name)); } - fn handle(&mut self, nodes: &Vec<Node>) { + fn handle(&mut self, nodes: &[Node]) { for n in nodes { match *n { Node::Lit(val) => { self.write_lit(val); }, @@ -193,7 +193,7 @@ impl Generator { } } - fn block_methods(&mut self, blocks: &Vec<Node>) { + fn block_methods(&mut self, blocks: &[Node]) { for b in blocks { if let Node::BlockDef(name, ref nodes) = *b { self.writeln("#[allow(unused_variables)]"); @@ -220,7 +220,7 @@ impl Generator { self.writeln(&s); } - fn template_impl(&mut self, ast: &syn::DeriveInput, nodes: &Vec<Node>) { + fn template_impl(&mut self, ast: &syn::DeriveInput, nodes: &[Node]) { let anno = annotations(&ast.generics); self.writeln(&format!("impl{} askama::Template for {}{} {{", anno, ast.ident.as_ref(), anno)); @@ -236,7 +236,7 @@ impl Generator { self.writeln("}"); } - fn trait_impl(&mut self, ast: &syn::DeriveInput, base: &str, blocks: &Vec<Node>) { + fn trait_impl(&mut self, ast: &syn::DeriveInput, base: &str, blocks: &[Node]) { let anno = annotations(&ast.generics); self.writeln(&format!("impl{} TraitFrom{} for {}{} {{", anno, path_as_identifier(base), @@ -266,7 +266,7 @@ impl Generator { } fn template_trait(&mut self, ast: &syn::DeriveInput, path: &str, - blocks: &Vec<Node>, nodes: &Vec<Node>) { + blocks: &[Node], nodes: &[Node]) { let anno = annotations(&ast.generics); self.writeln(&format!("trait{} TraitFrom{}{} {{", anno, path_as_identifier(path), anno)); diff --git a/askama/src/parser.rs b/askama/src/parser.rs index 1e2b94e..1ba2174 100644 --- a/askama/src/parser.rs +++ b/askama/src/parser.rs @@ -22,8 +22,7 @@ pub enum Node<'a> { Block(&'a str), } -pub type Nodes<'a> = Vec<Node<'a>>; -pub type Conds<'a> = Vec<(Option<Expr<'a>>, Nodes<'a>)>; +pub type Cond<'a> = (Option<Expr<'a>>, Vec<Node<'a>>); fn take_content(i: &[u8]) -> IResult<&[u8], Node> { if i.len() < 1 || i[0] == b'{' { @@ -97,7 +96,7 @@ named!(cond_if<Expr>, do_parse!( cond: ws!(expr_any) >> (cond))); -named!(cond_block<(Option<Expr>, Nodes)>, do_parse!( +named!(cond_block<Cond>, do_parse!( tag_s!("{%") >> ws!(tag_s!("else")) >> cond: opt!(cond_if) >> @@ -152,7 +151,7 @@ named!(block_block<Node>, do_parse!( tag_s!("%}") >> (Node::BlockDef(str::from_utf8(name).unwrap(), contents)))); -named!(parse_template<Nodes>, many0!(alt!( +named!(parse_template<Vec<Node<'a>>>, many0!(alt!( take_content | expr_node | block_if | @@ -160,7 +159,7 @@ named!(parse_template<Nodes>, many0!(alt!( block_extends | block_block))); -pub fn parse<'a>(src: &'a str) -> Nodes { +pub fn parse<'a>(src: &'a str) -> Vec<Node<'a>> { match parse_template(src.as_bytes()) { IResult::Done(_, res) => res, IResult::Error(err) => panic!("problems parsing template source: {}", err), |