david_walker avatar david_walker committed 89b3cbb

finish adding code to update cbegin and cend attributes of tokens

Comments (0)

Files changed (1)

                 middle = token_to_transform.str[self._index]
                 right = token_to_transform.str[self._index + 1:]
 
-                self.rule.tokens.insert(transform_token_index, Token(left))
+                cbegin = token_to_transform.cbegin
+                cend = cbegin + len(left)
+                new_token = Token(left, cbegin, cend)
+                logging.debug(new_token)
+                self.rule.tokens.insert(transform_token_index, new_token)
+                cbegin = cend
+                cend = cbegin + len(middle)
                 token_to_transform.str = middle
+                token_to_transform.cbegin = cbegin
+                token_to_transform.cend = cend
+                logging.debug(token_to_transform)
+
+                cbegin = cend
+                cend = cbegin + len(right)
+                new_token = Token(right, cbegin, cend)
+                logging.debug(new_token)
                 self.rule.tokens.insert(transform_token_index + 2,
-                                        Token(right))
+                                        new_token)
             else:
                 # split the token string at the supplied character index
                 index = self._index
                 left = token_to_transform.str[:index]
                 right = token_to_transform.str[index:]
                 # insert a new token for the left part of the split
-                self.rule.tokens.insert(transform_token_index, Token(left))
+                cbegin = token_to_transform.cbegin
+                cend = cbegin + len(left)
+                new_token = Token(left, cbegin, cend)
+                logging.debug(new_token)
+                self.rule.tokens.insert(transform_token_index,
+                                        new_token)
                 token_to_transform.str = right
+                token_to_transform.cbegin = cend
+                token_to_transform.cend = cend + len(right)
+                logging.debug(token_to_transform)
         logging.debug(u'<IndexSplitTransform %s',
                       token_strings(self.rule.tokens))
         return self.rule.tokens
         new_tokens = map(Token, new_token_str.split())
         # this must be set to avoid infinite loop
         new_tokens[-2].ISO_currency_expanded = True
+        new_tokens[-2].cbegin = token.cbegin
+        new_tokens[-2].cend = token.cend
+        logging.debug(new_tokens)
         self.rule.tokens = left_of_split + new_tokens + right_of_split
         logging.debug(u'<ISOCurrencyTransform %s',
                       token_strings(self.rule.tokens))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.