diff src/ast_dump.rs @ 59:407b3b217928

Add ast.With.
author Bastien Orivel <eijebong@bananium.fr>
date Sun, 12 Jun 2016 20:14:27 +0200
parents a0b23123901b
children 9f0f457a67f6
line wrap: on
line diff
--- a/src/ast_dump.rs
+++ b/src/ast_dump.rs
@@ -1,4 +1,4 @@
-use python_ast::{Module, stmt, expr, boolop, operator, unaryop, cmpop, arguments, arg, keyword, comprehension};
+use python_ast::{Module, stmt, expr, boolop, operator, unaryop, cmpop, arguments, arg, keyword, comprehension, withitem};
 
 use std::iter;
 
@@ -63,6 +63,15 @@ impl cmpop {
     }
 }
 
+impl to_string_able for withitem {
+    fn to_string(&self) -> String {
+        match self.optional_vars {
+            None => format!("{}", self.context_expr.to_string()),
+            Some(ref optional_var) => format!("{} as {}", self.context_expr.to_string(), optional_var.to_string())
+        }
+    }
+}
+
 fn vec_to_strings_vec<T: to_string_able>(values: Vec<T>) -> Vec<String> {
     let mut vector = vec!();
     for value in values {
@@ -277,6 +286,16 @@ impl stmt {
                         }
                     }
                 )
+            },
+            stmt::With(items, body) => {
+                format!("{}with {}:\n{}",
+                    current_indent,
+                    {
+                        let items = vec_to_strings_vec(items);
+                        items.join(", ")
+                    },
+                    statements_to_string(indent, body)
+                )
             }
         }
     }