Commit 72fc9e34 authored by Stefan Behnel's avatar Stefan Behnel

support parentheses around import-from names

parent e021a252
...@@ -42,6 +42,10 @@ class Ctx(object): ...@@ -42,6 +42,10 @@ class Ctx(object):
d.update(kwds) d.update(kwds)
return ctx return ctx
def eat_newlines(s):
while s.sy == 'NEWLINE':
s.next()
def p_ident(s, message = "Expected an identifier"): def p_ident(s, message = "Expected an identifier"):
if s.sy == 'IDENT': if s.sy == 'IDENT':
name = s.systring name = s.systring
...@@ -1022,14 +1026,27 @@ def p_from_import_statement(s, first_statement = 0): ...@@ -1022,14 +1026,27 @@ def p_from_import_statement(s, first_statement = 0):
else: else:
s.error("Expected 'import' or 'cimport'") s.error("Expected 'import' or 'cimport'")
is_cimport = kind == 'cimport' is_cimport = kind == 'cimport'
is_parenthesized = False
if s.sy == '*': if s.sy == '*':
imported_names = [(s.position(), "*", None, None)] imported_names = [(s.position(), "*", None, None)]
s.next() s.next()
else: else:
if s.sy == '(':
is_parenthesized = True
s.next()
eat_newlines(s)
imported_names = [p_imported_name(s, is_cimport)] imported_names = [p_imported_name(s, is_cimport)]
if is_parenthesized:
eat_newlines(s)
while s.sy == ',': while s.sy == ',':
s.next() s.next()
if is_parenthesized:
eat_newlines(s)
imported_names.append(p_imported_name(s, is_cimport)) imported_names.append(p_imported_name(s, is_cimport))
if is_parenthesized:
eat_newlines(s)
if is_parenthesized:
s.expect(')')
dotted_name = EncodedString(dotted_name) dotted_name = EncodedString(dotted_name)
if dotted_name == '__future__': if dotted_name == '__future__':
if not first_statement: if not first_statement:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment