44
55from sqlparse import sql
66from sqlparse import tokens as T
7+ from sqlparse .utils import recurse
78
89
910def _group_left_right (tlist , ttype , value , cls ,
@@ -229,9 +230,8 @@ def _next_token(tl, i):
229230 token = _next_token (tlist , idx )
230231
231232
233+ @recurse (sql .IdentifierList )
232234def group_identifier_list (tlist ):
233- [group_identifier_list (sgroup ) for sgroup in tlist .get_sublists ()
234- if not isinstance (sgroup , sql .IdentifierList )]
235235 # Allowed list items
236236 fend1_funcs = [lambda t : isinstance (t , (sql .Identifier , sql .Function ,
237237 sql .Case )),
@@ -327,9 +327,8 @@ def group_brackets(tlist):
327327 token = tlist .token_next_match (idx , T .Punctuation , ['(' , '[' ])
328328
329329
330+ @recurse (sql .Comment )
330331def group_comments (tlist ):
331- [group_comments (sgroup ) for sgroup in tlist .get_sublists ()
332- if not isinstance (sgroup , sql .Comment )]
333332 idx = 0
334333 token = tlist .token_next_by_type (idx , T .Comment )
335334 while token :
@@ -348,9 +347,8 @@ def group_comments(tlist):
348347 token = tlist .token_next_by_type (idx , T .Comment )
349348
350349
350+ @recurse (sql .Where )
351351def group_where (tlist ):
352- [group_where (sgroup ) for sgroup in tlist .get_sublists ()
353- if not isinstance (sgroup , sql .Where )]
354352 idx = 0
355353 token = tlist .token_next_match (idx , T .Keyword , 'WHERE' )
356354 stopwords = ('ORDER' , 'GROUP' , 'LIMIT' , 'UNION' , 'EXCEPT' , 'HAVING' )
@@ -368,10 +366,9 @@ def group_where(tlist):
368366 token = tlist .token_next_match (idx , T .Keyword , 'WHERE' )
369367
370368
369+ @recurse (sql .Identifier , sql .Function , sql .Case )
371370def group_aliased (tlist ):
372371 clss = (sql .Identifier , sql .Function , sql .Case )
373- [group_aliased (sgroup ) for sgroup in tlist .get_sublists ()
374- if not isinstance (sgroup , clss )]
375372 idx = 0
376373 token = tlist .token_next_by_instance (idx , clss )
377374 while token :
@@ -390,9 +387,8 @@ def group_typecasts(tlist):
390387 _group_left_right (tlist , T .Punctuation , '::' , sql .Identifier )
391388
392389
390+ @recurse (sql .Function )
393391def group_functions (tlist ):
394- [group_functions (sgroup ) for sgroup in tlist .get_sublists ()
395- if not isinstance (sgroup , sql .Function )]
396392 idx = 0
397393 token = tlist .token_next_by_type (idx , T .Name )
398394 while token :
@@ -420,8 +416,8 @@ def group_order(tlist):
420416 token = tlist .token_next_by_type (idx , T .Keyword .Order )
421417
422418
419+ @recurse ()
423420def align_comments (tlist ):
424- [align_comments (sgroup ) for sgroup in tlist .get_sublists ()]
425421 token = tlist .token_next_by (i = sql .Comment )
426422 while token :
427423 before = tlist .token_prev (tlist .token_index (token ))
0 commit comments