aboutsummaryrefslogtreecommitdiffstats
path: root/askama_derive
diff options
context:
space:
mode:
authorLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2017-08-02 20:59:30 +0200
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2017-08-02 20:59:30 +0200
commit8ff2e316c07b4fd4373dd8a0bb5747bef3372a32 (patch)
tree5147b0be34fc45641d5e296c3020e91e6fec6f42 /askama_derive
parent91fe53d9b5db7ace5f82889a174ef5061a049771 (diff)
parentce84543b69b69ab2030ce4daeae3f26d5008b11d (diff)
downloadaskama-8ff2e316c07b4fd4373dd8a0bb5747bef3372a32.tar.gz
askama-8ff2e316c07b4fd4373dd8a0bb5747bef3372a32.tar.bz2
askama-8ff2e316c07b4fd4373dd8a0bb5747bef3372a32.zip
Merge changes
Diffstat (limited to 'askama_derive')
-rw-r--r--askama_derive/Cargo.toml2
-rw-r--r--askama_derive/src/generator.rs16
-rw-r--r--askama_derive/src/parser.rs33
3 files changed, 30 insertions, 21 deletions
diff --git a/askama_derive/Cargo.toml b/askama_derive/Cargo.toml
index 5f65f23..4aad3fb 100644
--- a/askama_derive/Cargo.toml
+++ b/askama_derive/Cargo.toml
@@ -12,6 +12,6 @@ workspace = ".."
proc-macro = true
[dependencies]
-nom = "2.1"
+nom = "3"
syn = "0.11"
quote = "0.3"
diff --git a/askama_derive/src/generator.rs b/askama_derive/src/generator.rs
index edde3fe..f055cb7 100644
--- a/askama_derive/src/generator.rs
+++ b/askama_derive/src/generator.rs
@@ -129,7 +129,7 @@ impl<'a> Generator<'a> {
if name == "format" {
self.write("format!(");
} else {
- self.write(&format!("askama::filters::{}(&", name));
+ self.write(&format!("::askama::filters::{}(&", name));
}
for (i, arg) in args.iter().enumerate() {
@@ -274,7 +274,7 @@ impl<'a> Generator<'a> {
ws2: &WS) {
self.writeln("#[allow(unused_variables)]");
self.writeln(&format!(
- "fn render_block_{}_to(&self, writer: &mut std::fmt::Write) {{",
+ "fn render_block_{}_to(&self, writer: &mut ::std::fmt::Write) {{",
name));
self.prepare_ws(ws1);
self.handle(nodes);
@@ -351,7 +351,7 @@ impl<'a> Generator<'a> {
let name = if let Some(suffix) = trait_suffix {
format!("TraitFrom{}", suffix)
} else {
- "askama::Template".to_string()
+ "::askama::Template".to_string()
};
self.writeln(&format!("impl{} {} for {}{}{} {{",
full_anno.as_str(), &name, ast.ident.as_ref(),
@@ -360,7 +360,7 @@ impl<'a> Generator<'a> {
fn impl_template(&mut self, ast: &syn::DeriveInput, nodes: &'a [Node]) {
self.write_header(ast, None);
- self.writeln("fn render_to(&self, writer: &mut std::fmt::Write) {");
+ self.writeln("fn render_to(&self, writer: &mut ::std::fmt::Write) {");
self.handle(nodes);
self.flush_ws(&WS(false, false));
self.writeln("}");
@@ -375,7 +375,7 @@ impl<'a> Generator<'a> {
self.writeln("#[allow(unused_variables)]");
let trait_name = format!("TraitFrom{}", path_as_identifier(base));
self.writeln(&format!(
- "fn render_trait_to(&self, timpl: &{}, writer: &mut std::fmt::Write) {{",
+ "fn render_trait_to(&self, timpl: &{}, writer: &mut ::std::fmt::Write) {{",
trait_name));
if let Some(nodes) = nodes {
@@ -392,7 +392,7 @@ impl<'a> Generator<'a> {
fn impl_template_for_trait(&mut self, ast: &syn::DeriveInput, derived: bool) {
self.write_header(ast, None);
- self.writeln("fn render_to(&self, writer: &mut std::fmt::Write) {");
+ self.writeln("fn render_to(&self, writer: &mut ::std::fmt::Write) {");
if derived {
self.writeln("self._parent.render_trait_to(self, writer);");
} else {
@@ -408,11 +408,11 @@ impl<'a> Generator<'a> {
for bname in block_names {
self.writeln(&format!(
- "fn render_block_{}_to(&self, writer: &mut std::fmt::Write);",
+ "fn render_block_{}_to(&self, writer: &mut ::std::fmt::Write);",
bname));
}
self.writeln(&format!(
- "fn render_trait_to(&self, timpl: &{}, writer: &mut std::fmt::Write);",
+ "fn render_trait_to(&self, timpl: &{}, writer: &mut ::std::fmt::Write);",
trait_name));
self.writeln("}");
diff --git a/askama_derive/src/parser.rs b/askama_derive/src/parser.rs
index 74140bf..61ccb09 100644
--- a/askama_derive/src/parser.rs
+++ b/askama_derive/src/parser.rs
@@ -156,18 +156,27 @@ named!(expr_single<Expr>, alt!(
expr_group
));
-named!(expr_attr<Expr>, alt!(
- do_parse!(
- obj: expr_single >>
- tag_s!(".") >>
- attr: identifier >>
- args: arguments >>
- (if args.is_some() {
- Expr::Call(Box::new(obj), attr, args.unwrap())
- } else {
- Expr::Attr(Box::new(obj), attr)
- })
- ) | expr_single
+named!(attr<(&str, Option<Vec<Expr>>)>, do_parse!(
+ tag_s!(".") >>
+ attr: identifier >>
+ args: arguments >>
+ (attr, args)
+));
+
+named!(expr_attr<Expr>, do_parse!(
+ obj: expr_single >>
+ attrs: many0!(attr) >>
+ ({
+ let mut res = obj;
+ for (aname, args) in attrs {
+ res = if args.is_some() {
+ Expr::Call(Box::new(res), aname, args.unwrap())
+ } else {
+ Expr::Attr(Box::new(res), aname)
+ };
+ }
+ res
+ })
));
named!(filter<(&str, Option<Vec<Expr>>)>, do_parse!(