diff options
author | Andi Albrecht <albrecht.andi@gmail.com> | 2011-09-29 09:33:47 +0200 |
---|---|---|
committer | Andi Albrecht <albrecht.andi@gmail.com> | 2011-09-29 09:33:47 +0200 |
commit | ff50b33074f5c276b0cff8094e85582dcd467095 (patch) | |
tree | 6f34a60f9d7b62530bb65dfe0c4d7be8eb45abf7 | |
parent | f811fa12247330adc27f1b842167a112b1c0829c (diff) | |
download | sqlparse-ff50b33074f5c276b0cff8094e85582dcd467095.tar.gz |
Make keyword detection more restrict (fixes issue47).
Keywords most likely don't follow dots. Maybe there are other
exclusions too, but for now let's just go with this one.
-rw-r--r-- | CHANGES | 1 | ||||
-rw-r--r-- | sqlparse/lexer.py | 1 | ||||
-rw-r--r-- | tests/test_parse.py | 4 |
3 files changed, 6 insertions, 0 deletions
@@ -4,6 +4,7 @@ Development Bug Fixes * Avoid "stair case" effects when identifiers and functions are mixed in identifier lists (issue45). + * Make keyword detection more restrict (issue47). Release 0.1.3 (Jul 29, 2011) diff --git a/sqlparse/lexer.py b/sqlparse/lexer.py index 8929e3e..e90cd64 100644 --- a/sqlparse/lexer.py +++ b/sqlparse/lexer.py @@ -194,6 +194,7 @@ class Lexer(object): (r'END( IF| LOOP)?\b', tokens.Keyword), (r'NOT NULL\b', tokens.Keyword), (r'CREATE( OR REPLACE)?\b', tokens.Keyword.DDL), + (r'(?<=\.)[a-zA-Z_][a-zA-Z0-9_]*', tokens.Name), (r'[a-zA-Z_][a-zA-Z0-9_]*', is_keyword), (r'[;:()\[\],\.]', tokens.Punctuation), ], diff --git a/tests/test_parse.py b/tests/test_parse.py index 5f9bb2d..e14c9e2 100644 --- a/tests/test_parse.py +++ b/tests/test_parse.py @@ -102,3 +102,7 @@ class SQLParseTest(TestCaseBase): self.assertEqual(t[-1].get_real_name(), '[foo bar]') self.assertEqual(t[-1].get_parent_name(), 'a') + def test_keyword_like_identifier(self): # see issue47 + t = sqlparse.parse('foo.key')[0].tokens + self.assertEqual(len(t), 1) + self.assert_(isinstance(t[0], sqlparse.sql.Identifier)) |