Replace tokens by an instance of *grp_cls*.
(self, grp_cls, start, end, include_end=True,
extend=False)
| 305 | return start + self.tokens[start:].index(token) |
| 306 | |
| 307 | def group_tokens(self, grp_cls, start, end, include_end=True, |
| 308 | extend=False): |
| 309 | """Replace tokens by an instance of *grp_cls*.""" |
| 310 | start_idx = start |
| 311 | start = self.tokens[start_idx] |
| 312 | |
| 313 | end_idx = end + include_end |
| 314 | |
| 315 | # will be needed later for new group_clauses |
| 316 | # while skip_ws and tokens and tokens[-1].is_whitespace: |
| 317 | # tokens = tokens[:-1] |
| 318 | |
| 319 | if extend and isinstance(start, grp_cls): |
| 320 | subtokens = self.tokens[start_idx + 1:end_idx] |
| 321 | |
| 322 | grp = start |
| 323 | grp.tokens.extend(subtokens) |
| 324 | del self.tokens[start_idx + 1:end_idx] |
| 325 | grp.value = str(start) |
| 326 | else: |
| 327 | subtokens = self.tokens[start_idx:end_idx] |
| 328 | grp = grp_cls(subtokens) |
| 329 | self.tokens[start_idx:end_idx] = [grp] |
| 330 | grp.parent = self |
| 331 | |
| 332 | for token in subtokens: |
| 333 | token.parent = grp |
| 334 | |
| 335 | return grp |
| 336 | |
| 337 | def insert_before(self, where, token): |
| 338 | """Inserts *token* before *where*.""" |
no outgoing calls
no test coverage detected