summaryrefslogtreecommitdiff
path: root/sqlparse/engine
diff options
context:
space:
mode:
authorVictor Uriarte <victor.m.uriarte@intel.com>2016-05-10 19:42:08 -0700
committerVictor Uriarte <victor.m.uriarte@intel.com>2016-05-10 19:42:08 -0700
commit5a1830554f9c1d6b626f57fd88c19c6f7063b434 (patch)
tree3ae4df5cb8ba7ea9314a20f9917e5c0b8ea771d9 /sqlparse/engine
parentdbf8a624e091e1da24a7a90c4ff59d88ce816b8f (diff)
downloadsqlparse-5a1830554f9c1d6b626f57fd88c19c6f7063b434.tar.gz
generalize group_tokens for more use cases
Diffstat (limited to 'sqlparse/engine')
-rw-r--r--sqlparse/engine/grouping.py14
1 files changed, 4 insertions, 10 deletions
diff --git a/sqlparse/engine/grouping.py b/sqlparse/engine/grouping.py
index 982488b..ab519f0 100644
--- a/sqlparse/engine/grouping.py
+++ b/sqlparse/engine/grouping.py
@@ -422,19 +422,13 @@ def group_order(tlist):
def align_comments(tlist):
[align_comments(sgroup) for sgroup in tlist.get_sublists()]
- idx = 0
- token = tlist.token_next_by_instance(idx, sql.Comment)
+ token = tlist.token_next_by(i=sql.Comment)
while token:
before = tlist.token_prev(tlist.token_index(token))
if isinstance(before, sql.TokenList):
- grp = tlist.tokens_between(before, token)[1:]
- before.tokens.extend(grp)
- for t in grp:
- tlist.tokens.remove(t)
- idx = tlist.token_index(before) + 1
- else:
- idx = tlist.token_index(token) + 1
- token = tlist.token_next_by_instance(idx, sql.Comment)
+ tokens = tlist.tokens_between(before, token)
+ token = tlist.group_tokens(sql.TokenList, tokens, extend=True)
+ token = tlist.token_next_by(i=sql.Comment, idx=token)
def group(tlist):