summaryrefslogtreecommitdiff
path: root/sqlparse/sql.py
diff options
context:
space:
mode:
authorDarik Gamble <darik.gamble@gmail.com>2016-06-20 09:56:42 -0400
committerDarik Gamble <darik.gamble@gmail.com>2016-06-20 09:56:42 -0400
commit66ae504c4bf8cc1f005c8822623d2b3c3d3e4aa3 (patch)
tree6c6a15e28d6d77b7ddb3559bcde43ac431360b8b /sqlparse/sql.py
parentb3700f44ff6945d1ace9d5d809dd272c9acd268e (diff)
downloadsqlparse-66ae504c4bf8cc1f005c8822623d2b3c3d3e4aa3.tar.gz
token_next shouldn't ignore skip_cm
Diffstat (limited to 'sqlparse/sql.py')
-rw-r--r--sqlparse/sql.py26
1 files changed, 7 insertions, 19 deletions
diff --git a/sqlparse/sql.py b/sqlparse/sql.py
index 9656390..4b4627f 100644
--- a/sqlparse/sql.py
+++ b/sqlparse/sql.py
@@ -257,37 +257,25 @@ class TokenList(Token):
"""Returns the previous token relative to *idx*.
If *skip_ws* is ``True`` (the default) whitespace tokens are ignored.
+ If *skip_cm* is ``True`` comments are ignored.
``None`` is returned if there's no previous token.
"""
- if idx is None:
- return None, None
- idx += 1 # alot of code usage current pre-compensates for this
- funcs = lambda tk: not ((skip_ws and tk.is_whitespace()) or
- (skip_cm and imt(tk, t=T.Comment, i=Comment)))
- return self._token_matching(funcs, idx, reverse=True)
+ return self.token_next(idx, skip_ws, skip_cm, _reverse=True)
- # TODO: May need to implement skip_cm for upstream changes.
# TODO: May need to re-add default value to idx
- def token_next(self, idx, skip_ws=True, skip_cm=False):
+ def token_next(self, idx, skip_ws=True, skip_cm=False, _reverse=False):
"""Returns the next token relative to *idx*.
If *skip_ws* is ``True`` (the default) whitespace tokens are ignored.
+ If *skip_cm* is ``True`` comments are ignored.
``None`` is returned if there's no next token.
"""
if idx is None:
return None, None
idx += 1 # alot of code usage current pre-compensates for this
- try:
- if not skip_ws:
- return idx, self.tokens[idx]
- else:
- while True:
- token = self.tokens[idx]
- if not token.is_whitespace():
- return idx, token
- idx += 1
- except IndexError:
- return None, None
+ funcs = lambda tk: not ((skip_ws and tk.is_whitespace()) or
+ (skip_cm and imt(tk, t=T.Comment, i=Comment)))
+ return self._token_matching(funcs, idx, reverse=_reverse)
def token_index(self, token, start=0):
"""Return list index of token."""