diff options
| author | Victor Uriarte <victor.m.uriarte@intel.com> | 2016-06-06 20:38:04 -0700 |
|---|---|---|
| committer | Victor Uriarte <victor.m.uriarte@intel.com> | 2016-06-09 20:36:55 -0700 |
| commit | 36992fb015ae7c0701a4623b3f86e3f7c692bfe0 (patch) | |
| tree | effe09f9c4ac9c075fe31d38210e68b18b872013 /sqlparse | |
| parent | 3b626eef55b9b6b6bb48ad8f50173e754fc60c77 (diff) | |
| download | sqlparse-36992fb015ae7c0701a4623b3f86e3f7c692bfe0.tar.gz | |
refactor next token
Diffstat (limited to 'sqlparse')
| -rw-r--r-- | sqlparse/filters/aligned_indent.py | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/sqlparse/filters/aligned_indent.py b/sqlparse/filters/aligned_indent.py index 7f7557e..48f75a1 100644 --- a/sqlparse/filters/aligned_indent.py +++ b/sqlparse/filters/aligned_indent.py @@ -111,19 +111,18 @@ class AlignedIndentFilter(object): # if not the END add a newline tlist.insert_after(line[-1], self.newline()) - def _process_substatement(self, tlist, base_indent=0): - def _next_token(i): - t = tlist.token_next_by(m=(T.Keyword, self.split_words, True), - idx=i) - # treat "BETWEEN x and y" as a single statement - if t and t.value.upper() == 'BETWEEN': - t = _next_token(tlist.token_index(t) + 1) - if t and t.value.upper() == 'AND': - t = _next_token(tlist.token_index(t) + 1) - return t - - idx = 0 - token = _next_token(idx) + def _next_token(self, tlist, idx=0): + split_words = T.Keyword, self.split_words, True + token = tlist.token_next_by(m=split_words, idx=idx) + # treat "BETWEEN x and y" as a single statement + if token and token.value.upper() == 'BETWEEN': + token = self._next_token(tlist, token) + if token and token.value.upper() == 'AND': + token = self._next_token(tlist, token) + return token + + def _split_kwds(self, tlist, base_indent=0): + token = self._next_token(tlist) while token: # joins are special case. only consider the first word as aligner if token.match(T.Keyword, self.join_words, regex=True): @@ -134,8 +133,10 @@ class AlignedIndentFilter(object): self._max_kwd_len - token_indent + base_indent, newline_before=True)) next_idx = tlist.token_index(token) + 1 - token = _next_token(next_idx) + token = self._next_token(tlist, next_idx) + def _process_default(self, tlist, base_indent=0): + self._split_kwds(tlist, base_indent) # process any sub-sub statements for sgroup in tlist.get_sublists(): prev_token = tlist.token_prev(tlist.token_index(sgroup)) @@ -148,10 +149,10 @@ class AlignedIndentFilter(object): return tlist def _process(self, tlist, base_indent=0): - token_name = tlist.__class__.__name__.lower() - func_name = '_process_%s' % token_name - func = getattr(self, func_name, self._process_substatement) + func_name = '_process_{cls}'.format(cls=type(tlist).__name__) + func = getattr(self, func_name.lower(), self._process_default) return func(tlist, base_indent=base_indent) def process(self, stmt): self._process(stmt) + return stmt |
