Mercurial > python-compiler.rs
changeset 83:e59cd5754268
Add ast.Starred.
author | Bastien Orivel <eijebong@bananium.fr> |
---|---|
date | Mon, 13 Jun 2016 21:41:14 +0200 |
parents | 2d906d1cb940 |
children | ff6b1aeb544a |
files | src/ast_convert.rs src/ast_dump.rs src/python_ast.rs tests/test_parse_files/test_starred.py |
diffstat | 4 files changed, 11 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ast_convert.rs +++ b/src/ast_convert.rs @@ -351,6 +351,7 @@ fn parse_expr(py: Python, ast: PyObject) let ifexp_type = ast_module.get(py, "IfExp").unwrap(); let dict_type = ast_module.get(py, "Dict").unwrap(); let subscript_type = ast_module.get(py, "Subscript").unwrap(); + let starred_type = ast_module.get(py, "Starred").unwrap(); assert!(is_instance(&ast, &ast_type)); @@ -523,6 +524,13 @@ fn parse_expr(py: Python, ast: PyObject) let slice = parse_slice(py, slice); expr::Subscript(Box::new(value), Box::new(slice), ctx) + } else if is_instance(&ast, &starred_type) { + let value = ast.getattr(py, "value").unwrap(); + let ctx = get_ctx(py, ast); + + let value = parse_expr(py, value); + + expr::Starred(Box::new(value), ctx) } else { println!("expr {}", ast); unreachable!()
--- a/src/ast_dump.rs +++ b/src/ast_dump.rs @@ -246,6 +246,7 @@ impl to_string_able for expr { ) }, expr::Subscript(value, slice, _) => format!("{}[{}]", value.to_string(), slice.to_string()), + expr::Starred(value, _) => format!("*{}", value.to_string()), } } }
--- a/src/python_ast.rs +++ b/src/python_ast.rs @@ -109,7 +109,7 @@ pub enum expr { // the following expression can appear in assignment context Attribute(Box<expr>, String, expr_context), Subscript(Box<expr>, Box<slice>, expr_context), - //Starred(Box<expr>, expr_context), + Starred(Box<expr>, expr_context), Name(String, expr_context), List(Vec<expr>, expr_context), Tuple(Vec<expr>, expr_context),