Mercurial > python-compiler.rs
comparison src/ast_dump.rs @ 82:2d906d1cb940
Add ast.Subscript.
author | Bastien Orivel <eijebong@bananium.fr> |
---|---|
date | Mon, 13 Jun 2016 21:32:43 +0200 |
parents | dc82a0d8f144 |
children | e59cd5754268 |
comparison
equal
deleted
inserted
replaced
81:dc82a0d8f144 | 82:2d906d1cb940 |
---|---|
1 use python_ast::{Module, stmt, expr, boolop, operator, unaryop, cmpop, arguments, arg, keyword, comprehension, withitem, excepthandler}; | 1 use python_ast::{Module, stmt, expr, boolop, operator, unaryop, cmpop, arguments, arg, keyword, comprehension, withitem, excepthandler, slice}; |
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; |
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 } | |
118 } | |
119 | |
120 impl to_string_able for slice { | |
121 fn to_string(&self) -> String { | |
122 match *self { | |
123 slice::Index(ref value) => value.to_string(), | |
124 slice::Slice(ref lower, ref upper, ref step) => { | |
125 format!("{}{}{}", | |
126 match *lower { | |
127 None => String::new(), | |
128 Some(ref lower) => lower.to_string() | |
129 }, | |
130 match *upper { | |
131 None => String::new(), | |
132 Some(ref upper) => format!(":{}", upper.to_string()) | |
133 }, | |
134 match *step { | |
135 None => String::new(), | |
136 Some(ref step) => format!(":{}", step.to_string()) | |
137 }, | |
138 ) | |
139 }, | |
140 slice::ExtSlice(ref dims) => { | |
141 let mut dims_ = vec!(); | |
142 for dim in dims { | |
143 dims_.push(dim.to_string()); | |
144 } | |
145 dims_.join(", ") | |
146 } | |
147 } | |
117 } | 148 } |
118 } | 149 } |
119 | 150 |
120 impl excepthandler { | 151 impl excepthandler { |
121 fn to_string(self, indent: usize) -> String { | 152 fn to_string(self, indent: usize) -> String { |
212 } | 243 } |
213 items.join(", ") | 244 items.join(", ") |
214 } | 245 } |
215 ) | 246 ) |
216 }, | 247 }, |
248 expr::Subscript(value, slice, _) => format!("{}[{}]", value.to_string(), slice.to_string()), | |
217 } | 249 } |
218 } | 250 } |
219 } | 251 } |
220 | 252 |
221 impl to_string_able for arg { | 253 impl to_string_able for arg { |