Mercurial > python-compiler.rs
comparison src/ast_dump.rs @ 91:859d44f143b8
Implement Bytes in the AST.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Sat, 25 Jun 2016 02:08:50 +0100 |
parents | 898876834564 |
children | 7977a52c3202 |
comparison
equal
deleted
inserted
replaced
90:4e62a8927dcc | 91:859d44f143b8 |
---|---|
194 arguments.extend(keywords); | 194 arguments.extend(keywords); |
195 arguments.join(", ") | 195 arguments.join(", ") |
196 }), | 196 }), |
197 expr::Num(n) => format!("{}", n), | 197 expr::Num(n) => format!("{}", n), |
198 expr::Str(s) => format!("\"{}\"", s), | 198 expr::Str(s) => format!("\"{}\"", s), |
199 expr::Bytes(s) => format!("b\"{}\"", { | |
200 let mut string = String::with_capacity(s.len()); | |
201 for ascii_code in s { | |
202 let c = ascii_code as char; | |
203 if c >= ' ' && c <= '~' { | |
204 if c == '"' || c == '\\' { | |
205 string.push('\\'); | |
206 } | |
207 string.push(c); | |
208 } else if c == '\t' { | |
209 string.push_str("\\t"); | |
210 } else if c == '\n' { | |
211 string.push_str("\\n"); | |
212 } else if c == '\r' { | |
213 string.push_str("\\r"); | |
214 } else /* if c > '~' */ { | |
215 let value = format!("\\x{:02x}", ascii_code); | |
216 string.push_str(value.as_str()); | |
217 } | |
218 } | |
219 string | |
220 }), | |
199 expr::NameConstant(constant) => match constant { | 221 expr::NameConstant(constant) => match constant { |
200 name_constant::True => String::from("True"), | 222 name_constant::True => String::from("True"), |
201 name_constant::False => String::from("False"), | 223 name_constant::False => String::from("False"), |
202 name_constant::None_ => String::from("None") | 224 name_constant::None_ => String::from("None") |
203 }, | 225 }, |