def _regroup_tokens(tokens):
  """Returns recursive list of sqlparse.Token for nested statements."""
  grouped_tokens = []
  current_idx = 0
  while current_idx < len(tokens):
    token = tokens[current_idx]
    if current_idx > 0 and token.value.lower() == 'select':
      end_idx = _find_statement_end_idx(tokens, current_idx)
      nested_tokens = tokens[current_idx:end_idx + 1]
      grouped_tokens.append(_regroup_tokens(nested_tokens))
      current_idx = end_idx + 1
    else:
      grouped_tokens.append(token)
      current_idx += 1
  return grouped_tokens
Returns recursive list of sqlparse.Token for nested statements.
language/xsp/data_preprocessing/abstract_sql.py