diff options
| author | Sjoerd Job Postmus <sjoerdjob@sjec.nl> | 2016-06-02 09:21:05 +0200 |
|---|---|---|
| committer | Victor Uriarte <victor.m.uriarte@intel.com> | 2016-06-12 17:34:03 -0700 |
| commit | 237575ef726e4232b60a5043177c43a72f370238 (patch) | |
| tree | b6b1d9bb2334269b39b313986a69398d0d20bb69 /sqlparse | |
| parent | d4cc0644c8348da5e49c58df5e26a3e969045249 (diff) | |
| download | sqlparse-237575ef726e4232b60a5043177c43a72f370238.tar.gz | |
Re-use token index in group_identifier.
Diffstat (limited to 'sqlparse')
| -rw-r--r-- | sqlparse/engine/grouping.py | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/sqlparse/engine/grouping.py b/sqlparse/engine/grouping.py index e004eae..77a53ad 100644 --- a/sqlparse/engine/grouping.py +++ b/sqlparse/engine/grouping.py @@ -109,8 +109,9 @@ def group_identifier(tlist): token = tlist.token_next_by(t=T_IDENT) while token: - token = tlist.group_tokens(sql.Identifier, [token, ]) - token = tlist.token_next_by(t=T_IDENT, idx=tlist.token_index(token) + 1) + tidx = tlist.token_index(token) + token = tlist.group_tokens_between(sql.Identifier, tidx, tidx) + token = tlist.token_next_by(t=T_IDENT, idx=tidx + 1) def group_period(tlist): @@ -165,11 +166,14 @@ def group_identifier_list(tlist): token = tlist.token_next_by(m=M_COMMA) while token: - before, after = tlist.token_prev(tlist.token_index(token)), tlist.token_next(tlist.token_index(token)) + tidx = tlist.token_index(token) + before, after = tlist.token_prev(tidx), tlist.token_next(tidx) if func(before) and func(after): - token = tlist.group_tokens_between(sql.IdentifierList, before, after, extend=True) - token = tlist.token_next_by(m=M_COMMA, idx=tlist.token_index(token) + 1) + tidx = tlist.token_index(before) + token = tlist.group_tokens_between(sql.IdentifierList, tidx, after, extend=True) + + token = tlist.token_next_by(m=M_COMMA, idx=tidx + 1) def group_brackets(tlist): @@ -215,10 +219,11 @@ def group_aliased(tlist): token = tlist.token_next_by(i=I_ALIAS, t=T.Number) while token: - next_ = tlist.token_next(tlist.token_index(token)) + tidx = tlist.token_index(token) + next_ = tlist.token_next(tidx) if imt(next_, i=sql.Identifier): - token = tlist.group_tokens_between(sql.Identifier, token, next_, extend=True) - token = tlist.token_next_by(i=I_ALIAS, t=T.Number, idx=tlist.token_index(token) + 1) + token = tlist.group_tokens_between(sql.Identifier, tidx, next_, extend=True) + token = tlist.token_next_by(i=I_ALIAS, t=T.Number, idx=tidx + 1) def group_typecasts(tlist): |
