comparison src/ast_dump.rs @ 89:898876834564

Rename trait to respect CamelCase conventions.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Wed, 22 Jun 2016 23:10:21 +0100
parents a7b1db623f41
children 859d44f143b8
comparison
equal deleted inserted replaced
88:5923cd4bfc36 89:898876834564
1 use python_ast::{Module, stmt, expr, boolop, operator, unaryop, cmpop, arguments, arg, keyword, comprehension, withitem, excepthandler, slice, name_constant}; 1 use python_ast::{Module, stmt, expr, boolop, operator, unaryop, cmpop, arguments, arg, keyword, comprehension, withitem, excepthandler, slice, name_constant};
2 2
3 use std::iter; 3 use std::iter;
4 4
5 trait to_string_able { 5 trait ToStringable {
6 fn to_string(&self) -> String; 6 fn to_string(&self) -> String;
7 } 7 }
8 8
9 impl boolop { 9 impl boolop {
10 fn to_string(&self) -> &'static str { 10 fn to_string(&self) -> &'static str {
61 cmpop::NotIn => "not in", 61 cmpop::NotIn => "not in",
62 } 62 }
63 } 63 }
64 } 64 }
65 65
66 impl to_string_able for withitem { 66 impl ToStringable for withitem {
67 fn to_string(&self) -> String { 67 fn to_string(&self) -> String {
68 match self.optional_vars { 68 match self.optional_vars {
69 None => format!("{}", self.context_expr.to_string()), 69 None => format!("{}", self.context_expr.to_string()),
70 Some(ref optional_var) => format!("{} as {}", self.context_expr.to_string(), optional_var.to_string()) 70 Some(ref optional_var) => format!("{} as {}", self.context_expr.to_string(), optional_var.to_string())
71 } 71 }
72 } 72 }
73 } 73 }
74 74
75 fn vec_to_strings_vec<T: to_string_able>(values: Vec<T>) -> Vec<String> { 75 fn vec_to_strings_vec<T: ToStringable>(values: Vec<T>) -> Vec<String> {
76 let mut vector = vec!(); 76 let mut vector = vec!();
77 for value in values { 77 for value in values {
78 vector.push(value.to_string()); 78 vector.push(value.to_string());
79 } 79 }
80 vector 80 vector
81 } 81 }
82 82
83 impl to_string_able for keyword { 83 impl ToStringable for keyword {
84 fn to_string(&self) -> String { 84 fn to_string(&self) -> String {
85 match self.arg.clone() { 85 match self.arg.clone() {
86 Some(arg) => format!("{}={}", arg, self.value.to_string()), 86 Some(arg) => format!("{}={}", arg, self.value.to_string()),
87 None => format!("**{}", self.value.to_string()) 87 None => format!("**{}", self.value.to_string())
88 } 88 }
104 } else { 104 } else {
105 format!("{}\n{}else:\n{}", body, make_indent(indent), statements_to_string(indent, orelse)) 105 format!("{}\n{}else:\n{}", body, make_indent(indent), statements_to_string(indent, orelse))
106 } 106 }
107 } 107 }
108 108
109 impl to_string_able for comprehension { 109 impl ToStringable for comprehension {
110 fn to_string(&self) -> String { 110 fn to_string(&self) -> String {
111 let mut result = vec!(); 111 let mut result = vec!();
112 result.push(format!("for {} in {}", self.target.to_string(), self.iter.to_string())); 112 result.push(format!("for {} in {}", self.target.to_string(), self.iter.to_string()));
113 for if_ in self.ifs.clone() { 113 for if_ in self.ifs.clone() {
114 result.push(format!("if {}", if_.to_string())) 114 result.push(format!("if {}", if_.to_string()))
115 } 115 }
116 result.join(" ") 116 result.join(" ")
117 } 117 }
118 } 118 }
119 119
120 impl to_string_able for slice { 120 impl ToStringable for slice {
121 fn to_string(&self) -> String { 121 fn to_string(&self) -> String {
122 match *self { 122 match *self {
123 slice::Index(ref value) => value.to_string(), 123 slice::Index(ref value) => value.to_string(),
124 slice::Slice(ref lower, ref upper, ref step) => { 124 slice::Slice(ref lower, ref upper, ref step) => {
125 format!("{}{}{}", 125 format!("{}{}{}",
164 statements_to_string(indent, self.body) 164 statements_to_string(indent, self.body)
165 ) 165 )
166 } 166 }
167 } 167 }
168 168
169 impl to_string_able for expr { 169 impl ToStringable for expr {
170 fn to_string(&self) -> String { 170 fn to_string(&self) -> String {
171 match self.clone() { 171 match self.clone() {
172 expr::BoolOp(op, values) => { 172 expr::BoolOp(op, values) => {
173 let mut data = vec!(); 173 let mut data = vec!();
174 for value in values { 174 for value in values {
240 expr::Starred(value, _) => format!("*{}", value.to_string()), 240 expr::Starred(value, _) => format!("*{}", value.to_string()),
241 } 241 }
242 } 242 }
243 } 243 }
244 244
245 impl to_string_able for arg { 245 impl ToStringable for arg {
246 fn to_string(&self) -> String { 246 fn to_string(&self) -> String {
247 match self.annotation { 247 match self.annotation {
248 None => self.arg.clone(), 248 None => self.arg.clone(),
249 Some(ref annotation) => format!("{}: {}", self.arg, annotation.to_string()) 249 Some(ref annotation) => format!("{}: {}", self.arg, annotation.to_string())
250 } 250 }
251 } 251 }
252 } 252 }
253 253
254 impl to_string_able for arguments { 254 impl ToStringable for arguments {
255 fn to_string(&self) -> String { 255 fn to_string(&self) -> String {
256 let mut args = vec!(); 256 let mut args = vec!();
257 let num_args = self.args.len(); 257 let num_args = self.args.len();
258 let num_defaults = self.defaults.len(); 258 let num_defaults = self.defaults.len();
259 259