Skip to content

Commit c7115f8

Browse files
committed
Optimized
1 parent 6e5b576 commit c7115f8

1 file changed

Lines changed: 15 additions & 18 deletions

File tree

sqlparse/engine/grouping.py

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,16 @@ def group_identifier_list(tlist):
205205
lambda t: isinstance(t, sql.Comment),
206206
]
207207

208-
start = None
208+
def group(start, after):
209+
"""
210+
Create and group the identifiers list
211+
"""
212+
tokens = tlist.tokens_between(start, after)
213+
return tlist.group_tokens(sql.IdentifierList, tokens)
209214

215+
start = None
210216
tcomma = tlist.token_next_match(0, T.Punctuation, ',')
217+
211218
while tcomma:
212219
before = tlist.token_prev(tcomma)
213220
after = tlist.token_next(tcomma)
@@ -240,26 +247,16 @@ def group_identifier_list(tlist):
240247

241248
# Reached the end of the list
242249
# Create and group the identifiers list
243-
tokens = tlist.tokens_between(start, after)
244-
group = tlist.group_tokens(sql.IdentifierList, tokens)
250+
tcomma = group(start, after)
245251

246-
# Skip ahead to next ","
247-
start = None
248-
tcomma = tlist.token_next_match(tlist.token_index(group) + 1,
249-
T.Punctuation, ',')
252+
# Skip ahead to next ","
253+
start = None
254+
tcomma = tlist.token_next_match(tlist.token_index(tcomma) + 1,
255+
T.Punctuation, ',')
250256

251-
# At least one of the tokens around tcomma don't belong to an
252-
# identifier list. Something's wrong here, skip ahead to next ","
253-
else:
254-
start = None
255-
tcomma = tlist.token_next_match(tlist.token_index(tcomma) + 1,
256-
T.Punctuation, ',')
257-
258-
# There's an open identifier list
257+
# There's an open identifier list, create and group the identifiers list
259258
if start:
260-
# Create and group the identifiers list
261-
tokens = tlist.tokens_between(start, after)
262-
group = tlist.group_tokens(sql.IdentifierList, tokens)
259+
group(start, after)
263260

264261

265262
def group_parenthesis(tlist):

0 commit comments

Comments
 (0)