diff options
| author | Victor Uriarte <victor.m.uriarte@intel.com> | 2016-05-11 04:53:12 -0700 |
|---|---|---|
| committer | Victor Uriarte <victor.m.uriarte@intel.com> | 2016-05-11 04:54:14 -0700 |
| commit | 955996e3e5c49fb6b7f200ceecee2f8082656ac4 (patch) | |
| tree | 5ca2ce45fc9cf0a35efbcf68bb643f3a12e2575d /sqlparse/engine | |
| parent | 6748b48adc76491d3cdef5794ddd0731df0d3418 (diff) | |
| download | sqlparse-955996e3e5c49fb6b7f200ceecee2f8082656ac4.tar.gz | |
refactor group_comments
Diffstat (limited to 'sqlparse/engine')
| -rw-r--r-- | sqlparse/engine/grouping.py | 24 |
1 files changed, 9 insertions, 15 deletions
diff --git a/sqlparse/engine/grouping.py b/sqlparse/engine/grouping.py index 8fb4af1..e30abab 100644 --- a/sqlparse/engine/grouping.py +++ b/sqlparse/engine/grouping.py @@ -172,22 +172,16 @@ def group_parenthesis(tlist): @recurse(sql.Comment) def group_comments(tlist): - idx = 0 - token = tlist.token_next_by_type(idx, T.Comment) + token = tlist.token_next_by(t=T.Comment) while token: - tidx = tlist.token_index(token) - end = tlist.token_not_matching(tidx + 1, - [lambda t: t.ttype in T.Comment, - lambda t: t.is_whitespace()]) - if end is None: - idx = tidx + 1 - else: - eidx = tlist.token_index(end) - grp_tokens = tlist.tokens_between(token, - tlist.token_prev(eidx, False)) - group = tlist.group_tokens(sql.Comment, grp_tokens) - idx = tlist.token_index(group) - token = tlist.token_next_by_type(idx, T.Comment) + end = tlist.token_not_matching( + token, lambda tk: imt(tk, t=T.Comment) or tk.is_whitespace()) + if end is not None: + end = tlist.token_prev(end, False) + tokens = tlist.tokens_between(token, end) + token = tlist.group_tokens(sql.Comment, tokens) + + token = tlist.token_next_by(t=T.Comment, idx=token) @recurse(sql.Where) |
