Mercurial > python-compiler.rs
comparison src/ast_dump.rs @ 19:0cb53a31ac12
Implement ast.BoolOp, and improve its display.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Fri, 03 Jun 2016 00:55:24 +0100 |
parents | f1c77634a2eb |
children | 7af637f444d1 |
comparison
equal
deleted
inserted
replaced
18:51ef651266b1 | 19:0cb53a31ac12 |
---|---|
3 use std::iter; | 3 use std::iter; |
4 | 4 |
5 impl boolop { | 5 impl boolop { |
6 fn to_string(&self) -> &'static str { | 6 fn to_string(&self) -> &'static str { |
7 match *self { | 7 match *self { |
8 boolop::And => "and", | 8 boolop::And => " and ", |
9 boolop::Or => "or" | 9 boolop::Or => " or " |
10 } | 10 } |
11 } | 11 } |
12 } | 12 } |
13 | 13 |
14 impl operator { | 14 impl operator { |
114 result.join(" ") | 114 result.join(" ") |
115 } | 115 } |
116 impl expr { | 116 impl expr { |
117 fn to_string(&self) -> String { | 117 fn to_string(&self) -> String { |
118 match self.clone() { | 118 match self.clone() { |
119 expr::BoolOp(op, values) => format!("{}({})", op.to_string(), args_to_string(values)), | 119 expr::BoolOp(op, values) => { |
120 let mut data = vec!(); | |
121 for value in values { | |
122 data.push(value.to_string()); | |
123 } | |
124 data.join(op.to_string()) | |
125 }, | |
120 expr::BinOp(a, op, b) => format!("{} {} {}", a.to_string(), op.to_string(), b.to_string()), | 126 expr::BinOp(a, op, b) => format!("{} {} {}", a.to_string(), op.to_string(), b.to_string()), |
121 expr::UnaryOp(op, operand) => format!("{}{}", op.to_string(), operand.to_string()), | 127 expr::UnaryOp(op, operand) => format!("{}{}", op.to_string(), operand.to_string()), |
122 | 128 |
123 expr::Compare(left, ops, comparators) => format!("{} {}", left.to_string(), { | 129 expr::Compare(left, ops, comparators) => format!("{} {}", left.to_string(), { |
124 let mut arguments = vec!(); | 130 let mut arguments = vec!(); |