From 1b1810e4eaa5af17fe8d4f40717ae8f0a30554d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s=20Combarro=20=22Piranna=22?= Date: Sat, 19 May 2012 18:00:43 +0200 Subject: Commented group_identifier_list() --- sqlparse/engine/grouping.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'sqlparse/engine') diff --git a/sqlparse/engine/grouping.py b/sqlparse/engine/grouping.py index 8f5ccd9..37e029b 100644 --- a/sqlparse/engine/grouping.py +++ b/sqlparse/engine/grouping.py @@ -185,6 +185,7 @@ def group_identifier(tlist): def group_identifier_list(tlist): + # First group the `tlist` sublists for sgroup in tlist.get_sublists(): if not isinstance(sgroup, sql.IdentifierList): group_identifier_list(sgroup) @@ -204,13 +205,14 @@ def group_identifier_list(tlist): lambda t: isinstance(t, sql.Comment), ] - tcomma = tlist.token_next_match(0, T.Punctuation, ',') start = None + + tcomma = tlist.token_next_match(0, T.Punctuation, ',') while tcomma: before = tlist.token_prev(tcomma) after = tlist.token_next(tcomma) - # Check if the tokens around tcomma belong to a list + # Check if the tokens around tcomma belong to an identifier list bpassed = apassed = False for func in fend1_funcs: if before and func(before): @@ -218,22 +220,31 @@ def group_identifier_list(tlist): if after and func(after): apassed = True + # Both tokens around tcomma belong to a list if bpassed and apassed: - if start is None: + # Set the start of the identifier list if not defined before + if start == None: start = before + # Look if the next token is another comma next_ = tlist.token_next(after) if next_ and next_.match(T.Punctuation, ','): tcomma = next_ + + # Reached the end of the list else: - # Reached the end of the list + # Create and group the identifiers list tokens = tlist.tokens_between(start, after) group = tlist.group_tokens(sql.IdentifierList, tokens) + + # Skip ahead to next "," start = None tcomma = tlist.token_next_match(tlist.token_index(group) + 1, T.Punctuation, ',') + + # At least one of the tokens around tcomma don't belong to an + # identifier list. Something's wrong here, skip ahead to next "," else: - # Something's wrong here, skip ahead to next "," start = None tcomma = tlist.token_next_match(tlist.token_index(tcomma) + 1, T.Punctuation, ',') -- cgit v1.2.1