]> granicus.if.org Git - python/commitdiff
"from ... import x" should not be a syntax error... make
authorGeorg Brandl <georg@python.org>
Mon, 19 Mar 2007 18:56:50 +0000 (18:56 +0000)
committerGeorg Brandl <georg@python.org>
Mon, 19 Mar 2007 18:56:50 +0000 (18:56 +0000)
import_stmt accept ELLIPSes and DOTs.

Grammar/Grammar
Python/ast.c

index e4cd3e07fe63fa4e00abd19c982367f67ef7754c..41d8be8a9ef9fd9a533133573edc13317113c258 100644 (file)
@@ -55,7 +55,8 @@ yield_stmt: yield_expr
 raise_stmt: 'raise' [test [',' test [',' test]]]
 import_stmt: import_name | import_from
 import_name: 'import' dotted_as_names
-import_from: ('from' ('.'* dotted_name | '.'+)
+# note below: the ('.' | '...') is necessary because '...' is tokenized as ELLIPSIS
+import_from: ('from' (('.' | '...')* dotted_name | ('.' | '...')+)
               'import' ('*' | '(' import_as_names ')' | import_as_names))
 import_as_name: NAME ['as' NAME]
 dotted_as_name: dotted_name ['as' NAME]
index 8180b4224dd244aa0244f87089ef9eaf4987f01f..777c00ec0b60330337b529b792afdbbc15265d25 100644 (file)
@@ -2406,8 +2406,8 @@ ast_for_import_stmt(struct compiling *c, const node *n)
     /*
       import_stmt: import_name | import_from
       import_name: 'import' dotted_as_names
-      import_from: 'from' ('.'* dotted_name | '.') 'import'
-                          ('*' | '(' import_as_names ')' | import_as_names)
+      import_from: 'from' (('.' | '...')* dotted_name | ('.' | '...')+)
+                   'import' ('*' | '(' import_as_names ')' | import_as_names)
     */
     int lineno;
     int col_offset;
@@ -2445,6 +2445,10 @@ ast_for_import_stmt(struct compiling *c, const node *n)
                 mod = alias_for_import_name(c, CHILD(n, idx));
                 idx++;
                 break;
+            } else if (TYPE(CHILD(n, idx)) == ELLIPSIS) {
+                /* three consecutive dots are tokenized as one ELLIPSIS */ 
+                ndots += 3;
+                continue;
             } else if (TYPE(CHILD(n, idx)) != DOT) {
                 break;
             }