summaryrefslogtreecommitdiff
path: root/sqlparse
diff options
context:
space:
mode:
authorJesús Leganés Combarro "Piranna" <piranna@gmail.com>2012-06-02 00:20:20 +0200
committerJesús Leganés Combarro "Piranna" <piranna@gmail.com>2012-06-02 00:20:20 +0200
commitc7115f84fea3fd16922b5a3012d04a4ec185bb3d (patch)
tree9360e07f5fe891f58482d611a8719be95a800a63 /sqlparse
parent6e5b576d1e28af1aacd687af048ca6f79a956ad9 (diff)
downloadsqlparse-c7115f84fea3fd16922b5a3012d04a4ec185bb3d.tar.gz
Optimized
Diffstat (limited to 'sqlparse')
-rw-r--r--sqlparse/engine/grouping.py33
1 files changed, 15 insertions, 18 deletions
diff --git a/sqlparse/engine/grouping.py b/sqlparse/engine/grouping.py
index 4120fc3..bab932d 100644
--- a/sqlparse/engine/grouping.py
+++ b/sqlparse/engine/grouping.py
@@ -205,9 +205,16 @@ def group_identifier_list(tlist):
lambda t: isinstance(t, sql.Comment),
]
- start = None
+ def group(start, after):
+ """
+ Create and group the identifiers list
+ """
+ tokens = tlist.tokens_between(start, after)
+ return tlist.group_tokens(sql.IdentifierList, tokens)
+ start = None
tcomma = tlist.token_next_match(0, T.Punctuation, ',')
+
while tcomma:
before = tlist.token_prev(tcomma)
after = tlist.token_next(tcomma)
@@ -240,26 +247,16 @@ def group_identifier_list(tlist):
# 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)
+ tcomma = group(start, after)
- # 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(tcomma) + 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:
- start = None
- tcomma = tlist.token_next_match(tlist.token_index(tcomma) + 1,
- T.Punctuation, ',')
-
- # There's an open identifier list
+ # There's an open identifier list, create and group the identifiers list
if start:
- # Create and group the identifiers list
- tokens = tlist.tokens_between(start, after)
- group = tlist.group_tokens(sql.IdentifierList, tokens)
+ group(start, after)
def group_parenthesis(tlist):