diff options
author | Victor Uriarte <victor.m.uriarte@intel.com> | 2016-06-14 04:15:27 -0700 |
---|---|---|
committer | Victor Uriarte <victor.m.uriarte@intel.com> | 2016-06-15 13:29:17 -0700 |
commit | 56b28dc15023d36bab8764bea6df75e28651646e (patch) | |
tree | 9811b4a0624f092dc7cb886e1aaeec4354b272c0 /sqlparse/sql.py | |
parent | 5002bfa36c4fa2ee72eff18648b6ddc616b718f0 (diff) | |
download | sqlparse-56b28dc15023d36bab8764bea6df75e28651646e.tar.gz |
Make use of token_index more obvious
Diffstat (limited to 'sqlparse/sql.py')
-rw-r--r-- | sqlparse/sql.py | 13 |
1 files changed, 3 insertions, 10 deletions
diff --git a/sqlparse/sql.py b/sqlparse/sql.py index 4b6abf1..9656390 100644 --- a/sqlparse/sql.py +++ b/sqlparse/sql.py @@ -248,7 +248,7 @@ class TokenList(Token): def token_not_matching(self, funcs, idx): funcs = (funcs,) if not isinstance(funcs, (list, tuple)) else funcs funcs = [lambda tk: not func(tk) for func in funcs] - return self._token_matching(funcs, idx)[1] + return self._token_matching(funcs, idx) def token_matching(self, funcs, idx): return self._token_matching(funcs, idx)[1] @@ -297,13 +297,9 @@ class TokenList(Token): def group_tokens(self, grp_cls, start, end, include_end=True, extend=False): """Replace tokens by an instance of *grp_cls*.""" - if isinstance(start, int): - start_idx = start - start = self.tokens[start_idx] - else: - start_idx = self.token_index(start) + start_idx = start + start = self.tokens[start_idx] - end = end if isinstance(end, int) else self.token_index(end, start_idx) end_idx = end + include_end # will be needed later for new group_clauses @@ -390,9 +386,6 @@ class TokenList(Token): def _get_first_name(self, idx=None, reverse=False, keywords=False): """Returns the name of the first token with a name""" - if idx and not isinstance(idx, int): - idx = self.token_index(idx) + 1 - tokens = self.tokens[idx:] if idx else self.tokens tokens = reversed(tokens) if reverse else tokens types = [T.Name, T.Wildcard, T.String.Symbol] |