From 05fb6421329c85dc8afaf400a5df2186da1971e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s=20Combarro=20=22Piranna=22?= Date: Sat, 2 Jun 2012 19:22:08 +0200 Subject: Fixed issue_50 (with some pending regressions) --- sqlparse/engine/grouping.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'sqlparse/engine') diff --git a/sqlparse/engine/grouping.py b/sqlparse/engine/grouping.py index 046ec9b..66ae807 100644 --- a/sqlparse/engine/grouping.py +++ b/sqlparse/engine/grouping.py @@ -209,9 +209,11 @@ def group_identifier_list(tlist): """ Create and group the identifiers list """ + print "group_identifierlist", start, after tokens = tlist.tokens_between(start, after) return tlist.group_tokens(sql.IdentifierList, tokens) + # Search for the first identifier list start = None tcomma = tlist.token_next_match(0, T.Punctuation, ',') @@ -233,23 +235,25 @@ def group_identifier_list(tlist): if start == None: start = before - # Look if the next token is another comma - next_ = tlist.token_next(after) - if next_: - if next_.match(T.Punctuation, ','): - tcomma = next_ - continue + def continue_next(): + # Check the next token + next_ = tlist.token_next(after) + while next_: + # Next token is another comma or an identifier list keyword + if next_.match(T.Punctuation, ','): + return next_ - elif(next_.ttype == T.Keyword - and next_.value.upper() not in ('FROM', 'WHERE', 'GROUP')): - tcomma = next_ - continue + next_ = tlist.token_next(next_) + + tcomma = continue_next() + if tcomma: + continue # Reached the end of the list # Create and group the identifiers list tcomma = group_identifierlist(start, after) - # Skip ahead to next "," + # Skip ahead to next identifier list start = None tcomma = tlist.token_next_match(tlist.token_index(tcomma) + 1, T.Punctuation, ',') -- cgit v1.2.1