diff options
| author | Andi Albrecht <albrecht.andi@gmail.com> | 2011-07-24 00:56:18 +0200 |
|---|---|---|
| committer | Andi Albrecht <albrecht.andi@gmail.com> | 2011-07-24 00:56:18 +0200 |
| commit | 16dbc49a3fb4928365550775efa925640b4cb768 (patch) | |
| tree | 76576aac1ea3c3e61556b4bf01b3840b2d4925b7 | |
| parent | 693d7a31c1fff960763ff3ba485142ce67ff708f (diff) | |
| download | sqlparse-16dbc49a3fb4928365550775efa925640b4cb768.tar.gz | |
Releax keyword detection, when keywords are used as function names (fixes issue36).
| -rw-r--r-- | CHANGES | 2 | ||||
| -rw-r--r-- | sqlparse/lexer.py | 3 | ||||
| -rw-r--r-- | tests/test_format.py | 7 |
3 files changed, 11 insertions, 1 deletions
@@ -10,6 +10,8 @@ Bug Fixes reported by djo...@taket.org). * Split statements with IF as functions correctly (issue33, reported by charles....@unige.ch). + * Relax detection of keywords, esp. when used as function names + (issue36, nyuhu...@gmail.com). Release 0.1.2 (Nov 23, 2010) diff --git a/sqlparse/lexer.py b/sqlparse/lexer.py index 6304911..507217a 100644 --- a/sqlparse/lexer.py +++ b/sqlparse/lexer.py @@ -172,10 +172,11 @@ class Lexer: (r':=', tokens.Assignment), (r'::', tokens.Punctuation), (r'[*]', tokens.Wildcard), + (r'CASE\b', tokens.Keyword), # extended CASE(foo) (r"`(``|[^`])*`", tokens.Name), (r"´(´´|[^´])*´", tokens.Name), (r'@[a-zA-Z_][a-zA-Z0-9_]+', tokens.Name), - (r'[a-zA-Z_][a-zA-Z0-9_]*(?=\.)', tokens.Name), # see issue39 + (r'[a-zA-Z_][a-zA-Z0-9_]*(?=[.(])', tokens.Name), # see issue39 (r'[<>=~!]+', tokens.Operator.Comparison), (r'[+/@#%^&|`?^-]+', tokens.Operator), (r'0x[0-9a-fA-F]+', tokens.Number.Hexadecimal), diff --git a/tests/test_format.py b/tests/test_format.py index f9740d5..e41b6b6 100644 --- a/tests/test_format.py +++ b/tests/test_format.py @@ -221,6 +221,13 @@ class TestFormatReindent(TestCaseBase): 'where (c1 = 1)', 'order by c1'])) + def test_keywordfunctions(self): # issue36 + f = lambda sql: sqlparse.format(sql, reindent=True) + s = 'select max(a) b, foo, bar' + self.ndiffAssertEqual(f(s), '\n'.join(['select max(a) b,', + ' foo,', + ' bar'])) + |
