make imported names behave like identifiers, too
authorStefan Behnel <scoder@users.berlios.de>
Sun, 18 May 2008 23:04:48 +0000 (01:04 +0200)
committerStefan Behnel <scoder@users.berlios.de>
Sun, 18 May 2008 23:04:48 +0000 (01:04 +0200)
Cython/Compiler/Parsing.py
Cython/Compiler/Symtab.py

index d6f9fcb4ede87e054b5cd1cb296d75cea0527dfa..159c2e56c834ab360a615281c5e63e5152937450 100644 (file)
@@ -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)
 
index eb9d3ba945d5dbec7278cffcff6bdb917d7ba7a4..3ca412b6f95b9cde1d3bba53c0e5c3059e504f8e 100644 (file)
@@ -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):