[pypy-svn] r17688 - in pypy/dist/pypy/interpreter: pyparser pyparser/data test
ac at codespeak.net
ac at codespeak.net
Tue Sep 20 14:10:16 CEST 2005
Author: ac
Date: Tue Sep 20 14:10:15 2005
New Revision: 17688
Modified:
pypy/dist/pypy/interpreter/pyparser/astbuilder.py
pypy/dist/pypy/interpreter/pyparser/data/Grammar2.4
pypy/dist/pypy/interpreter/test/test_compiler.py
Log:
Catch a problem with multi-line imports without ().
Modified: pypy/dist/pypy/interpreter/pyparser/astbuilder.py
==============================================================================
--- pypy/dist/pypy/interpreter/pyparser/astbuilder.py (original)
+++ pypy/dist/pypy/interpreter/pyparser/astbuilder.py Tue Sep 20 14:10:15 2005
@@ -1229,9 +1229,9 @@
def build_import_from(builder, nb):
"""
- import_from: 'from' dotted_name 'import' ('*' | '(' import_as_names ')' | import_as_names)
+ import_from: 'from' dotted_name 'import' ('*' | '(' import_as_names [','] ')' | import_as_names)
- import_as_names: import_as_name (',' import_as_name)* [',']
+ import_as_names: import_as_name (',' import_as_name)*
import_as_name: NAME [NAME NAME]
"""
atoms = get_atoms(builder, nb)
Modified: pypy/dist/pypy/interpreter/pyparser/data/Grammar2.4
==============================================================================
--- pypy/dist/pypy/interpreter/pyparser/data/Grammar2.4 (original)
+++ pypy/dist/pypy/interpreter/pyparser/data/Grammar2.4 Tue Sep 20 14:10:15 2005
@@ -53,10 +53,10 @@
raise_stmt: 'raise' [test [',' test [',' test]]]
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)
import_as_name: NAME [NAME NAME]
dotted_as_name: dotted_name [NAME NAME]
-import_as_names: import_as_name (',' import_as_name)* [',']
+import_as_names: import_as_name (',' import_as_name)*
dotted_as_names: dotted_as_name (',' dotted_as_name)*
dotted_name: NAME ('.' NAME)*
global_stmt: 'global' NAME (',' NAME)*
Modified: pypy/dist/pypy/interpreter/test/test_compiler.py
==============================================================================
--- pypy/dist/pypy/interpreter/test/test_compiler.py (original)
+++ pypy/dist/pypy/interpreter/test/test_compiler.py Tue Sep 20 14:10:15 2005
@@ -227,6 +227,51 @@
ex.normalize_exception(self.space)
assert ex.match(self.space, self.space.w_SyntaxError)
+ def test_import(self):
+ succeed = [
+ 'import sys',
+ 'import os, sys',
+ 'from __future__ import nested_scopes, generators',
+ 'from __future__ import (nested_scopes,\ngenerators)',
+ 'from __future__ import (nested_scopes,\ngenerators,)',
+ 'from sys import stdin, stderr, stdout',
+ 'from sys import (stdin, stderr,\nstdout)',
+ 'from sys import (stdin, stderr,\nstdout,)',
+ 'from sys import (stdin\n, stderr, stdout)',
+ 'from sys import (stdin\n, stderr, stdout,)',
+ 'from sys import stdin as si, stdout as so, stderr as se',
+ 'from sys import (stdin as si, stdout as so, stderr as se)',
+ 'from sys import (stdin as si, stdout as so, stderr as se,)',
+ ]
+ fail = [
+ 'import (os, sys)',
+ 'import (os), (sys)',
+ 'import ((os), (sys))',
+ 'import (sys',
+ 'import sys)',
+ 'import (os,)',
+ 'from (sys) import stdin',
+ 'from __future__ import (nested_scopes',
+ 'from __future__ import nested_scopes)',
+ 'from __future__ import nested_scopes,\ngenerators',
+ 'from sys import (stdin',
+ 'from sys import stdin)',
+ 'from sys import stdin, stdout,\nstderr',
+ 'from sys import stdin si',
+ 'from sys import stdin,'
+ 'from sys import (*)',
+ 'from sys import (stdin,, stdout, stderr)',
+ 'from sys import (stdin, stdout),',
+ ]
+ for stmt in succeed:
+ self.compiler.compile(stmt, 'tmp', 'exec', 0)
+ for stmt in fail:
+ e = py.test.raises(OperationError, self.compiler.compile,
+ stmt, 'tmp', 'exec', 0)
+ ex = e.value
+ ex.normalize_exception(self.space)
+ assert ex.match(self.space, self.space.w_SyntaxError)
+
class TestECCompiler(BaseTestCompiler):
def setup_method(self, method):
self.compiler = self.space.getexecutioncontext().compiler
More information about the Pypy-commit
mailing list