From 63eabf72174c22e875551eee8fba085085721306 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Mon, 19 May 2008 01:04:48 +0200 Subject: [PATCH] make imported names behave like identifiers, too --- Cython/Compiler/Parsing.py | 13 +++++-------- Cython/Compiler/Symtab.py | 6 +++--- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/Cython/Compiler/Parsing.py b/Cython/Compiler/Parsing.py index d6f9fcb4..159c2e56 100644 --- a/Cython/Compiler/Parsing.py +++ b/Cython/Compiler/Parsing.py @@ -284,7 +284,7 @@ def p_call(s, function): s.error("Expected an identifier before '='", pos = arg.pos) encoded_name = Utils.EncodedString(arg.name) - keyword = ExprNodes.KeywordNameNode(arg.pos, + keyword = ExprNodes.IdentifierStringNode(arg.pos, value = encoded_name) arg = p_simple_expr(s) keyword_args.append((keyword, arg)) @@ -926,8 +926,8 @@ def p_import_statement(s): lhs = ExprNodes.NameNode(pos, name = as_name or target_name), rhs = ExprNodes.ImportNode(pos, - module_name = ExprNodes.StringNode(pos, - value = dotted_name), + module_name = ExprNodes.IdentifierStringNode( + pos, value = dotted_name), name_list = name_list)) stats.append(stat) return Nodes.StatListNode(pos, stats = stats) @@ -974,9 +974,8 @@ def p_from_import_statement(s, first_statement = 0): items = [] for (name_pos, name, as_name) in imported_names: encoded_name = Utils.EncodedString(name) - encoded_name.encoding = s.source_encoding imported_name_strings.append( - ExprNodes.StringNode(name_pos, value = encoded_name)) + ExprNodes.IdentifierStringNode(name_pos, value = encoded_name)) items.append( (name, ExprNodes.NameNode(name_pos, @@ -984,11 +983,9 @@ def p_from_import_statement(s, first_statement = 0): import_list = ExprNodes.ListNode( imported_names[0][0], args = imported_name_strings) dotted_name = Utils.EncodedString(dotted_name) - dotted_name.encoding = s.source_encoding return Nodes.FromImportStatNode(pos, module = ExprNodes.ImportNode(dotted_name_pos, - module_name = ExprNodes.StringNode(dotted_name_pos, - value = dotted_name), + module_name = ExprNodes.IdentifierStringNode(pos, value = dotted_name), name_list = import_list), items = items) diff --git a/Cython/Compiler/Symtab.py b/Cython/Compiler/Symtab.py index eb9d3ba9..3ca412b6 100644 --- a/Cython/Compiler/Symtab.py +++ b/Cython/Compiler/Symtab.py @@ -464,7 +464,7 @@ class Scope: string_map[value] = entry return entry - def add_py_string(self, entry): + def add_py_string(self, entry, identifier = None): # If not already done, allocate a C name for a Python version of # a string literal, and add it to the list of Python strings to # be created at module init time. If the string resembles a @@ -475,7 +475,7 @@ class Scope: entry.pystring_cname = entry.cname + "p" self.pystring_entries.append(entry) self.global_scope().all_pystring_entries.append(entry) - if possible_identifier(value): + if identifier or (identifier is None and possible_identifier(value)): entry.is_interned = 1 self.global_scope().new_interned_string_entries.append(entry) @@ -751,7 +751,7 @@ class ModuleScope(Scope): def intern_identifier(self, name): string_entry = self.get_string_const(name, identifier = True) - self.add_py_string(string_entry) + self.add_py_string(string_entry, identifier = 1) return string_entry.pystring_cname def find_module(self, module_name, pos): -- 2.26.2