changeset 52:d9838e8b3ec5

Add ast.Ellipsis.
author Bastien Orivel <eijebong@bananium.fr>
date Wed, 08 Jun 2016 19:01:46 +0200
parents ded1907b7a69
children 1a815946c2e5
files src/ast_convert.rs src/ast_dump.rs src/python_ast.rs tests/test_parse_files/test_ellipsis.py
diffstat 4 files changed, 7 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/ast_convert.rs
+++ b/src/ast_convert.rs
@@ -251,6 +251,7 @@ fn parse_expr(py: Python, ast: PyObject)
     let listcomp_type = ast_module.get(py, "ListComp").unwrap();
     let dictcomp_type = ast_module.get(py, "DictComp").unwrap();
     let tuple_type = ast_module.get(py, "Tuple").unwrap();
+    let ellipsis_type = ast_module.get(py, "Ellipsis").unwrap();
 
     assert!(is_instance(&ast, &ast_type));
 
@@ -361,6 +362,8 @@ fn parse_expr(py: Python, ast: PyObject)
         let elts = ast.getattr(py, "elts").unwrap();
         let elts = parse_list(py, elts, parse_expr);
         expr::Tuple(elts, get_ctx(py, ast))
+    } else if is_instance(&ast, &ellipsis_type) {
+        expr::Ellipsis
     } else {
         println!("expr {}", ast);
         unreachable!()
--- a/src/ast_dump.rs
+++ b/src/ast_dump.rs
@@ -155,7 +155,8 @@ impl expr {
             expr::List(elts, ctx) => format!("[{}]", args_to_string(elts)),
             expr::ListComp(elt, generators) => format!("[{} {}]", elt.to_string(), generators_to_string(generators)),
             expr::DictComp(key, value, generators) => format!("{{{}: {} {}}}", key.to_string(), value.to_string(), generators_to_string(generators)),
-            expr::Tuple(elts, ctx) => format!("({})", args_to_string(elts))
+            expr::Tuple(elts, ctx) => format!("({})", args_to_string(elts)),
+            expr::Ellipsis => format!("..."),
         }
     }
 }
--- a/src/python_ast.rs
+++ b/src/python_ast.rs
@@ -103,7 +103,7 @@ pub enum expr {
     Str(String),
     //Bytes(String),
     NameConstant(String),
-    //Ellipsis,
+    Ellipsis,
 
     // the following expression can appear in assignment context
     Attribute(Box<expr>, String, expr_context),
new file mode 100644
--- /dev/null
+++ b/tests/test_parse_files/test_ellipsis.py
@@ -0,0 +1,1 @@
+a = ...