Commits

Anonymous committed 6e8709d

codeanalyze: handled string literals in comments for finding primary

Comments (0)

Files changed (2)

rope/base/codeanalyze.py

             offset += 1;
         return offset
 
-    _char_pat = re.compile(r'[\'"#\n]')
+    _char_pat = re.compile(r'[\'"#]')
     def _find_last_non_space_char(self, offset):
         if offset <= 0:
             return 0
                 except ValueError:
                     start = 0
 
-                match = self._char_pat.search(self.source[start:offset][::-1])
+                match = self._char_pat.search(self.source[start:offset])
                 if match and match.group() == '#':
-                    offset = self.source.rindex('#', 0, offset)
+                    offset = self.source.rindex('#', start, offset)
             offset -= 1
         return offset
 

ropetest/codeanalyzetest.py

         code = '# var2 . \n  var3'
         self.assertEquals('var3', self._find_primary(code, 14))
 
+    def test_str_in_comments_for_finding_statements(self):
+        code = '# "var2" . \n  var3'
+        self.assertEquals('var3', self._find_primary(code, 14))
+
     def test_comments_for_finding_statements2(self):
         code = 'var1 + "# var2".\n  var3'
         self.assertEquals('"# var2".\n  var3', self._find_primary(code, 21))