@@ -338,16 +338,6 @@ def token_index(self, token, start=0):
338338 start = start if isinstance (start , int ) else self .token_index (start )
339339 return start + self .tokens [start :].index (token )
340340
341- def tokens_between (self , start , end , include_end = True ):
342- """Return all tokens between (and including) start and end.
343-
344- If *include_end* is ``False`` (default is ``True``) the end token
345- is excluded.
346- """
347- start_idx = self .token_index (start )
348- end_idx = include_end + self .token_index (end )
349- return self .tokens [start_idx :end_idx ]
350-
351341 def group_tokens_between (self , grp_cls , start , end , include_end = True ,
352342 extend = False ):
353343 """Replace tokens by an instance of *grp_cls*."""
@@ -357,16 +347,20 @@ def group_tokens_between(self, grp_cls, start, end, include_end=True,
357347 else :
358348 start_idx = self .token_index (start )
359349
360- end_idx = self .token_index (end ) if not isinstance (end , int ) else end
361- end_idx += include_end
350+ end = end if isinstance (end , int ) else self .token_index (end , start_idx )
351+ end_idx = end + include_end
352+
353+ # will be needed later for new group_clauses
354+ # while skip_ws and tokens and tokens[-1].is_whitespace():
355+ # tokens = tokens[:-1]
362356
363357 if extend and isinstance (start , grp_cls ):
364358 subtokens = self .tokens [start_idx + 1 :end_idx ]
365359
366360 grp = start
367361 grp .tokens .extend (subtokens )
368362 del self .tokens [start_idx + 1 :end_idx ]
369- grp .value = start . __str__ ( )
363+ grp .value = text_type ( start )
370364 else :
371365 subtokens = self .tokens [start_idx :end_idx ]
372366 grp = grp_cls (subtokens )
@@ -378,31 +372,6 @@ def group_tokens_between(self, grp_cls, start, end, include_end=True,
378372
379373 return grp
380374
381- def group_tokens (self , grp_cls , tokens , skip_ws = False , extend = False ):
382- """Replace tokens by an instance of *grp_cls*."""
383-
384- while skip_ws and tokens and tokens [- 1 ].is_whitespace ():
385- tokens = tokens [:- 1 ]
386-
387- left = tokens [0 ]
388- idx = self .token_index (left )
389-
390- if extend and isinstance (left , grp_cls ):
391- grp = left
392- grp .tokens .extend (tokens [1 :])
393- else :
394- grp = grp_cls (tokens )
395-
396- for token in tokens :
397- token .parent = grp
398-
399- # Improve performance. LOOP(list.remove()) is O(n**2) operation
400- self .tokens = [token for token in self .tokens if token not in tokens ]
401-
402- self .tokens .insert (idx , grp )
403- grp .parent = self
404- return grp
405-
406375 def insert_before (self , where , token ):
407376 """Inserts *token* before *where*."""
408377 token .parent = self
0 commit comments