diff options
| author | Andi Albrecht <albrecht.andi@gmail.com> | 2015-01-16 21:45:32 +0100 |
|---|---|---|
| committer | Andi Albrecht <albrecht.andi@gmail.com> | 2015-01-16 21:45:32 +0100 |
| commit | a17db7a7557056728acf5506d3dea6841ad55fa9 (patch) | |
| tree | 07b9ef8495bbfef326cd4c92676cdcc11498fd12 | |
| parent | c8f2febb01bc6d5c5a1973881bf3c48f80a3d3d1 (diff) | |
| download | sqlparse-a17db7a7557056728acf5506d3dea6841ad55fa9.tar.gz | |
Improve parsing of inline comments for identifiers (fixes #163).
| -rw-r--r-- | CHANGES | 3 | ||||
| -rw-r--r-- | sqlparse/engine/grouping.py | 2 | ||||
| -rw-r--r-- | sqlparse/sql.py | 3 | ||||
| -rw-r--r-- | tests/test_grouping.py | 6 |
4 files changed, 13 insertions, 1 deletions
@@ -5,7 +5,8 @@ Bug Fixes * Fix a regression for identifiers with square bracktes notation (issue153). Enhancements -* Improved formatting of HAVING statements. +* Improve formatting of HAVING statements. +* Improve parsing of inline comments (issue163). Release 0.1.14 (Nov 30, 2014) diff --git a/sqlparse/engine/grouping.py b/sqlparse/engine/grouping.py index a048128..5189f7e 100644 --- a/sqlparse/engine/grouping.py +++ b/sqlparse/engine/grouping.py @@ -172,6 +172,8 @@ def group_identifier(tlist): if next(x)(t): yield t else: + if isinstance(t, sql.Comment) and t.is_multiline(): + yield t raise StopIteration def _next_token(tl, i): diff --git a/sqlparse/sql.py b/sqlparse/sql.py index b8e4090..6174db0 100644 --- a/sqlparse/sql.py +++ b/sqlparse/sql.py @@ -559,6 +559,9 @@ class Comment(TokenList): """A comment.""" __slots__ = ('value', 'ttype', 'tokens') + def is_multiline(self): + return self.tokens and self.tokens[0].ttype == T.Comment.Multiline + class Where(TokenList): """A WHERE clause.""" diff --git a/tests/test_grouping.py b/tests/test_grouping.py index 86d4c7a..44a8072 100644 --- a/tests/test_grouping.py +++ b/tests/test_grouping.py @@ -131,6 +131,12 @@ class TestGrouping(TestCaseBase): l = p.tokens[2] self.assertEqual(len(l.tokens), 13) + def test_identifier_list_with_inline_comments(self): # issue163 + p = sqlparse.parse('foo /* a comment */, bar')[0] + self.assert_(isinstance(p.tokens[0], sql.IdentifierList)) + self.assert_(isinstance(p.tokens[0].tokens[0], sql.Identifier)) + self.assert_(isinstance(p.tokens[0].tokens[3], sql.Identifier)) + def test_where(self): s = 'select * from foo where bar = 1 order by id desc' p = sqlparse.parse(s)[0] |
