MCPcopy
hub / github.com/andialbrecht/sqlparse / group_tokens

Method group_tokens

sqlparse/sql.py:307–335  ·  view source on GitHub ↗

Replace tokens by an instance of *grp_cls*.

(self, grp_cls, start, end, include_end=True,
                     extend=False)

Source from the content-addressed store, hash-verified

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*."""

Callers 11

_group_matchingFunction · 0.80
group_identifierFunction · 0.80
group_overFunction · 0.80
group_commentsFunction · 0.80
group_whereFunction · 0.80
group_aliasedFunction · 0.80
group_functionsFunction · 0.80
group_orderFunction · 0.80
align_commentsFunction · 0.80
group_valuesFunction · 0.80
_groupFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected