Mercurial > python-compiler.rs
comparison src/ast_convert.rs @ 77:7d1406181aae
Add ast.SetComp.
author | Bastien Orivel <eijebong@bananium.fr> |
---|---|
date | Mon, 13 Jun 2016 19:22:59 +0200 |
parents | efd42fc280e8 |
children | f1a845e4121b |
comparison
equal
deleted
inserted
replaced
76:efd42fc280e8 | 77:7d1406181aae |
---|---|
303 let ellipsis_type = ast_module.get(py, "Ellipsis").unwrap(); | 303 let ellipsis_type = ast_module.get(py, "Ellipsis").unwrap(); |
304 let await_type = ast_module.get(py, "Await").unwrap(); | 304 let await_type = ast_module.get(py, "Await").unwrap(); |
305 let yield_type = ast_module.get(py, "Yield").unwrap(); | 305 let yield_type = ast_module.get(py, "Yield").unwrap(); |
306 let yield_from_type = ast_module.get(py, "YieldFrom").unwrap(); | 306 let yield_from_type = ast_module.get(py, "YieldFrom").unwrap(); |
307 let set_type = ast_module.get(py, "Set").unwrap(); | 307 let set_type = ast_module.get(py, "Set").unwrap(); |
308 let setcomp_type = ast_module.get(py, "SetComp").unwrap(); | |
308 | 309 |
309 assert!(is_instance(&ast, &ast_type)); | 310 assert!(is_instance(&ast, &ast_type)); |
310 | 311 |
311 if is_instance(&ast, &attribute_type) { | 312 if is_instance(&ast, &attribute_type) { |
312 let value = ast.getattr(py, "value").unwrap(); | 313 let value = ast.getattr(py, "value").unwrap(); |
424 } else if is_instance(&ast, &set_type) { | 425 } else if is_instance(&ast, &set_type) { |
425 let elts = ast.getattr(py, "elts").unwrap(); | 426 let elts = ast.getattr(py, "elts").unwrap(); |
426 let elements = parse_list(py, elts, parse_expr); | 427 let elements = parse_list(py, elts, parse_expr); |
427 | 428 |
428 expr::Set(elements) | 429 expr::Set(elements) |
430 } else if is_instance(&ast, &setcomp_type) { | |
431 let elt = ast.getattr(py, "elt").unwrap(); | |
432 let generators = ast.getattr(py, "generators").unwrap(); | |
433 | |
434 let elt = parse_expr(py, elt); | |
435 let generators = parse_list(py, generators, parse_comprehension); | |
436 | |
437 expr::SetComp(Box::new(elt), generators) | |
429 } else { | 438 } else { |
430 println!("expr {}", ast); | 439 println!("expr {}", ast); |
431 unreachable!() | 440 unreachable!() |
432 } | 441 } |
433 } | 442 } |