diff options
| author | Andi Albrecht <albrecht.andi@gmail.com> | 2009-07-12 09:48:58 +0200 |
|---|---|---|
| committer | Andi Albrecht <albrecht.andi@gmail.com> | 2009-07-12 09:48:58 +0200 |
| commit | 612c7fd4c2394be0e04cd7b26c380088bfa20306 (patch) | |
| tree | 03c6726e6efb1297cb2683e18f8074ace839f3a1 /sqlparse/engine | |
| parent | 9114ff791c224f8edfa6f1ff00ae57e8e3296f75 (diff) | |
| download | sqlparse-612c7fd4c2394be0e04cd7b26c380088bfa20306.tar.gz | |
Detect functions if they are used as identifiers.
Diffstat (limited to 'sqlparse/engine')
| -rw-r--r-- | sqlparse/engine/grouping.py | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/sqlparse/engine/grouping.py b/sqlparse/engine/grouping.py index c123d3c..3b92361 100644 --- a/sqlparse/engine/grouping.py +++ b/sqlparse/engine/grouping.py @@ -111,11 +111,13 @@ def group_case(tlist): def group_identifier(tlist): def _consume_cycle(tl, i): - x = itertools.cycle((lambda y: (y.match(T.Punctuation, '.') - or y.ttype is T.Operator), - lambda y: y.ttype in (T.String.Symbol, - T.Name, - T.Wildcard))) + x = itertools.cycle(( + lambda y: (y.match(T.Punctuation, '.') + or y.ttype is T.Operator), + lambda y: (y.ttype in (T.String.Symbol, + T.Name, + T.Wildcard)) + )) for t in tl.tokens[i:]: if x.next()(t): yield t @@ -128,14 +130,22 @@ def group_identifier(tlist): # real processing idx = 0 - token = tlist.token_next_by_type(idx, (T.String.Symbol, T.Name)) + token = tlist.token_next_by_instance(idx, Function) + if token is None: + token = tlist.token_next_by_type(idx, (T.String.Symbol, T.Name)) while token: identifier_tokens = [token]+list( _consume_cycle(tlist, tlist.token_index(token)+1)) - group = tlist.group_tokens(Identifier, identifier_tokens) - idx = tlist.token_index(group)+1 - token = tlist.token_next_by_type(idx, (T.String.Symbol, T.Name)) + if not (len(identifier_tokens) == 1 + and isinstance(identifier_tokens[0], Function)): + group = tlist.group_tokens(Identifier, identifier_tokens) + idx = tlist.token_index(group)+1 + else: + idx += 1 + token = tlist.token_next_by_instance(idx, Function) + if token is None: + token = tlist.token_next_by_type(idx, (T.String.Symbol, T.Name)) def group_identifier_list(tlist): |
