Skip to content

Commit 49979e9

Browse files
committed
Refactor _group's prev token logic
1 parent 0acaa4c commit 49979e9

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

sqlparse/engine/grouping.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -321,20 +321,18 @@ def _group(tlist, cls, match,
321321

322322
if token.is_whitespace():
323323
continue
324+
324325
if token.is_group() and not isinstance(token, cls):
325326
_group(token, cls, match, valid_left, valid_right, post, extend)
326-
pidx, prev_ = tidx, token
327-
continue
328-
if not match(token):
329-
pidx, prev_ = tidx, token
330-
continue
331327

332-
nidx, next_ = tlist.token_next(tidx)
328+
if match(token):
329+
nidx, next_ = tlist.token_next(tidx)
330+
if valid_left(prev_) and valid_right(next_):
331+
from_idx, to_idx = post(tlist, pidx, tidx, nidx)
332+
grp = tlist.group_tokens(cls, from_idx, to_idx, extend=extend)
333333

334-
if valid_left(prev_) and valid_right(next_):
335-
from_idx, to_idx = post(tlist, pidx, tidx, nidx)
336-
grp = tlist.group_tokens(cls, from_idx, to_idx, extend=extend)
337-
tidx_offset += to_idx - from_idx
338-
pidx, prev_ = from_idx, grp
339-
else:
340-
pidx, prev_ = tidx, token
334+
tidx_offset += to_idx - from_idx
335+
pidx, prev_ = from_idx, grp
336+
continue
337+
338+
pidx, prev_ = tidx, token

0 commit comments

Comments
 (0)