diff options
| author | Darik Gamble <darik.gamble@gmail.com> | 2015-03-04 10:34:47 -0500 |
|---|---|---|
| committer | Darik Gamble <darik.gamble@gmail.com> | 2015-03-04 10:34:47 -0500 |
| commit | 66f00a994437a02a8a2dac81ccdceb88d7013c83 (patch) | |
| tree | 8560f66b1c4e91d7a00e4188dad385ab7c9c31c8 /sqlparse/engine | |
| parent | c9dc9c8b79a3e290c28761a786993b02eff705d6 (diff) | |
| download | sqlparse-66f00a994437a02a8a2dac81ccdceb88d7013c83.tar.gz | |
Move _find_matching to a module-level function
Diffstat (limited to 'sqlparse/engine')
| -rw-r--r-- | sqlparse/engine/grouping.py | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/sqlparse/engine/grouping.py b/sqlparse/engine/grouping.py index 9314b89..0be44da 100644 --- a/sqlparse/engine/grouping.py +++ b/sqlparse/engine/grouping.py @@ -51,19 +51,21 @@ def _group_left_right(tlist, ttype, value, cls, ttype, value) +def _find_matching(idx, tlist, start_ttype, start_value, end_ttype, end_value): + depth = 1 + for tok in tlist.tokens[idx:]: + if tok.match(start_ttype, start_value): + depth += 1 + elif tok.match(end_ttype, end_value): + depth -= 1 + if depth == 1: + return tok + return None + + def _group_matching(tlist, start_ttype, start_value, end_ttype, end_value, cls, include_semicolon=False, recurse=False): - def _find_matching(i, tl, stt, sva, ett, eva): - depth = 1 - for n in xrange(i, len(tl.tokens)): - t = tl.tokens[n] - if t.match(stt, sva): - depth += 1 - elif t.match(ett, eva): - depth -= 1 - if depth == 1: - return t - return None + [_group_matching(sgroup, start_ttype, start_value, end_ttype, end_value, cls, include_semicolon) for sgroup in tlist.get_sublists() if recurse] |
