Mercurial > python-compiler.rs
comparison 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 |
comparison
equal
deleted
inserted
replaced
58:a0b23123901b | 59:407b3b217928 |
---|---|
1 use python_ast::{Module, stmt, expr, boolop, operator, unaryop, cmpop, arguments, arg, keyword, comprehension}; | 1 use python_ast::{Module, stmt, expr, boolop, operator, unaryop, cmpop, arguments, arg, keyword, comprehension, withitem}; |
2 | 2 |
3 use std::iter; | 3 use std::iter; |
4 | 4 |
5 trait to_string_able { | 5 trait to_string_able { |
6 fn to_string(&self) -> String; | 6 fn to_string(&self) -> String; |
57 cmpop::GtE => ">=", | 57 cmpop::GtE => ">=", |
58 cmpop::Is => "is", | 58 cmpop::Is => "is", |
59 cmpop::IsNot => "is not", | 59 cmpop::IsNot => "is not", |
60 cmpop::In => "in", | 60 cmpop::In => "in", |
61 cmpop::NotIn => "not in", | 61 cmpop::NotIn => "not in", |
62 } | |
63 } | |
64 } | |
65 | |
66 impl to_string_able for withitem { | |
67 fn to_string(&self) -> String { | |
68 match self.optional_vars { | |
69 None => format!("{}", self.context_expr.to_string()), | |
70 Some(ref optional_var) => format!("{} as {}", self.context_expr.to_string(), optional_var.to_string()) | |
62 } | 71 } |
63 } | 72 } |
64 } | 73 } |
65 | 74 |
66 fn vec_to_strings_vec<T: to_string_able>(values: Vec<T>) -> Vec<String> { | 75 fn vec_to_strings_vec<T: to_string_able>(values: Vec<T>) -> Vec<String> { |
275 Some(msg) => format!(", {}", msg.to_string()), | 284 Some(msg) => format!(", {}", msg.to_string()), |
276 None => String::new() | 285 None => String::new() |
277 } | 286 } |
278 } | 287 } |
279 ) | 288 ) |
289 }, | |
290 stmt::With(items, body) => { | |
291 format!("{}with {}:\n{}", | |
292 current_indent, | |
293 { | |
294 let items = vec_to_strings_vec(items); | |
295 items.join(", ") | |
296 }, | |
297 statements_to_string(indent, body) | |
298 ) | |
280 } | 299 } |
281 } | 300 } |
282 } | 301 } |
283 } | 302 } |
284 | 303 |