diff options
| author | Jesús Leganés Combarro "Piranna" <piranna@gmail.com> | 2012-05-19 18:00:43 +0200 |
|---|---|---|
| committer | Jesús Leganés Combarro "Piranna" <piranna@gmail.com> | 2012-05-19 18:00:43 +0200 |
| commit | 1b1810e4eaa5af17fe8d4f40717ae8f0a30554d4 (patch) | |
| tree | d476024393c039a12ff560924ae7f854c7f63737 /sqlparse | |
| parent | 42f9f77e07efc1c4f248aa9e48401e11c0ae4601 (diff) | |
| download | sqlparse-1b1810e4eaa5af17fe8d4f40717ae8f0a30554d4.tar.gz | |
Commented group_identifier_list()
Diffstat (limited to 'sqlparse')
| -rw-r--r-- | sqlparse/engine/grouping.py | 21 |
1 files changed, 16 insertions, 5 deletions
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, ',') |
