summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesús Leganés Combarro "Piranna" <piranna@gmail.com>2012-05-19 18:36:36 +0200
committerJesús Leganés Combarro "Piranna" <piranna@gmail.com>2012-05-19 18:36:36 +0200
commit9255cbc838b1fada24b2360ec9a12e311b9ced63 (patch)
treeff689d03b547d5ae0e4062d56543a4ec6e3869aa
parent1b1810e4eaa5af17fe8d4f40717ae8f0a30554d4 (diff)
downloadsqlparse-9255cbc838b1fada24b2360ec9a12e311b9ced63.tar.gz
Improvements on identifierlist
-rw-r--r--sqlparse/engine/grouping.py32
1 files changed, 22 insertions, 10 deletions
diff --git a/sqlparse/engine/grouping.py b/sqlparse/engine/grouping.py
index 37e029b..095827c 100644
--- a/sqlparse/engine/grouping.py
+++ b/sqlparse/engine/grouping.py
@@ -228,19 +228,25 @@ def group_identifier_list(tlist):
# Look if the next token is another comma
next_ = tlist.token_next(after)
- if next_ and next_.match(T.Punctuation, ','):
- tcomma = next_
+ if next_:
+ if next_.match(T.Punctuation, ','):
+ tcomma = next_
+ continue
+
+ elif(next_.ttype == T.Keyword
+ and next_.value not in ('FROM', 'WHERE', 'GROUP')):
+ tcomma = next_
+ continue
# Reached the end of the list
- else:
- # Create and group the identifiers list
- tokens = tlist.tokens_between(start, after)
- group = tlist.group_tokens(sql.IdentifierList, tokens)
+ # 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, ',')
+ # 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 ","
@@ -249,6 +255,12 @@ def group_identifier_list(tlist):
tcomma = tlist.token_next_match(tlist.token_index(tcomma) + 1,
T.Punctuation, ',')
+ # There's an open identifier list
+ if start:
+ # Create and group the identifiers list
+ tokens = tlist.tokens_between(start, after)
+ group = tlist.group_tokens(sql.IdentifierList, tokens)
+
def group_parenthesis(tlist):
_group_matching(tlist, T.Punctuation, '(', T.Punctuation, ')',