Mercurial > python-compiler.rs
diff 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 |
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, withitem, excepthandler}; +use python_ast::{Module, stmt, expr, boolop, operator, unaryop, cmpop, arguments, arg, keyword, comprehension, withitem, excepthandler, slice}; use std::iter; @@ -117,6 +117,37 @@ impl to_string_able for comprehension { } } +impl to_string_able for slice { + fn to_string(&self) -> String { + match *self { + slice::Index(ref value) => value.to_string(), + slice::Slice(ref lower, ref upper, ref step) => { + format!("{}{}{}", + match *lower { + None => String::new(), + Some(ref lower) => lower.to_string() + }, + match *upper { + None => String::new(), + Some(ref upper) => format!(":{}", upper.to_string()) + }, + match *step { + None => String::new(), + Some(ref step) => format!(":{}", step.to_string()) + }, + ) + }, + slice::ExtSlice(ref dims) => { + let mut dims_ = vec!(); + for dim in dims { + dims_.push(dim.to_string()); + } + dims_.join(", ") + } + } + } +} + impl excepthandler { fn to_string(self, indent: usize) -> String { let current_indent = make_indent(indent); @@ -214,6 +245,7 @@ impl to_string_able for expr { } ) }, + expr::Subscript(value, slice, _) => format!("{}[{}]", value.to_string(), slice.to_string()), } } }