From 26b5385babe69ced19e02dc4643a91f6aaf3a1a6 Mon Sep 17 00:00:00 2001 From: koljonen Date: Sat, 14 May 2016 21:54:50 +0200 Subject: [PATCH 1/2] Recognize USING as a keyword in 'USING(', not just in 'USING (' These were previously caught by (r'[^\W\d_]\w*(?=[.(])', tokens.Name), so I added a special regex just above that one. --- sqlparse/lexer.py | 1 + tests/test_grouping.py | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/sqlparse/lexer.py b/sqlparse/lexer.py index 7dd013ea..cf931e9e 100644 --- a/sqlparse/lexer.py +++ b/sqlparse/lexer.py @@ -187,6 +187,7 @@ class _Lexer(object): # IN is special, it may be followed by a parenthesis, but # is never a functino, see issue183 (r'in\b(?=[ (])?', tokens.Keyword), + (r'USING(?=\()', is_keyword), (r'[^\W\d_]\w*(?=[.(])', tokens.Name), # see issue39 (r'[-]?0x[0-9a-fA-F]+', tokens.Number.Hexadecimal), (r'[-]?[0-9]*(\.[0-9]+)?[eE][-]?[0-9]+', tokens.Number.Float), diff --git a/tests/test_grouping.py b/tests/test_grouping.py index 7dc12690..89610f8e 100644 --- a/tests/test_grouping.py +++ b/tests/test_grouping.py @@ -380,6 +380,13 @@ def test_begin(): assert isinstance(p.tokens[0], sql.Begin) +def test_keyword_followed_by_parenthesis(): + p = sqlparse.parse('USING(somecol')[0] + assert len(p.tokens) == 3 + assert p.tokens[0].ttype == T.Keyword + assert p.tokens[1].ttype == T.Punctuation + + def test_nested_begin(): p = sqlparse.parse('BEGIN foo BEGIN bar END END')[0] assert len(p.tokens) == 1 From 233216c3e9528b74ef7c6bc3054d2c0bd048620b Mon Sep 17 00:00:00 2001 From: koljonen Date: Sun, 15 May 2016 14:45:31 +0200 Subject: [PATCH 2/2] Don't call is_keyword for the new 'USING(' regex --- sqlparse/lexer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sqlparse/lexer.py b/sqlparse/lexer.py index cf931e9e..6bc49ee7 100644 --- a/sqlparse/lexer.py +++ b/sqlparse/lexer.py @@ -187,7 +187,7 @@ class _Lexer(object): # IN is special, it may be followed by a parenthesis, but # is never a functino, see issue183 (r'in\b(?=[ (])?', tokens.Keyword), - (r'USING(?=\()', is_keyword), + (r'USING(?=\()', tokens.Keyword), (r'[^\W\d_]\w*(?=[.(])', tokens.Name), # see issue39 (r'[-]?0x[0-9a-fA-F]+', tokens.Number.Hexadecimal), (r'[-]?[0-9]*(\.[0-9]+)?[eE][-]?[0-9]+', tokens.Number.Float),