summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndi Albrecht <albrecht.andi@gmail.com>2015-04-12 15:13:16 +0200
committerAndi Albrecht <albrecht.andi@gmail.com>2015-04-12 15:13:16 +0200
commitd463a753216b5c9e2c7f2b3c8a48fa76cbdb73c2 (patch)
treeed18fb65bfe8c4a565d95ee6ec407e5a10b9ff3e
parente038a06f0c92a9aec95c9771bae22fb5e8f16432 (diff)
parentf775030692222a5a0b296284328276b65259cc02 (diff)
downloadsqlparse-d463a753216b5c9e2c7f2b3c8a48fa76cbdb73c2.tar.gz
Merge remote-tracking branch 'origin/master' into v0.2.0
-rw-r--r--.gitignore3
-rw-r--r--CHANGES2
-rw-r--r--sqlparse/filters.py1
-rw-r--r--sqlparse/lexer.py7
-rw-r--r--tests/test_grouping.py8
-rw-r--r--tests/test_parse.py10
6 files changed, 27 insertions, 4 deletions
diff --git a/.gitignore b/.gitignore
index 3d7b563..24f7da0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,4 +12,5 @@ extras/appengine/lib/
extras/py3k/sqlparse
extras/py3k/tests
extras/py3k/sqlparse.diff
-extras/py3k/tests.diff \ No newline at end of file
+extras/py3k/tests.diff
+coverage.xml
diff --git a/CHANGES b/CHANGES
index c264b9f..51a2551 100644
--- a/CHANGES
+++ b/CHANGES
@@ -8,6 +8,7 @@ Bug Fixes
* Fix parsing of multi-line comments (issue172, by JacekPliszka).
* Fix parsing of escaped backslashes (issue174, by caseyching).
* Fix parsing of identifiers starting with underscore (issue175).
+* Fix misinterpretation of IN keyword (issue183).
Enhancements
* Improve formatting of HAVING statements.
@@ -17,6 +18,7 @@ Enhancements
* Add support for square bracket array indexing (issue170, issue176,
issue177 by darikg).
* Improve grouping of aliased elements (issue167, by darikg).
+* Support comments starting with '#' character (issue178).
Release 0.1.14 (Nov 30, 2014)
diff --git a/sqlparse/filters.py b/sqlparse/filters.py
index 7e82f26..b187907 100644
--- a/sqlparse/filters.py
+++ b/sqlparse/filters.py
@@ -347,6 +347,7 @@ class ReindentFilter:
nl = self.nl()
added.add(nl)
tlist.insert_before(token, nl)
+ offset += 1
token = _next_token(tlist.token_index(nl) + offset)
def _split_statements(self, tlist):
diff --git a/sqlparse/lexer.py b/sqlparse/lexer.py
index a0cc7ae..602d275 100644
--- a/sqlparse/lexer.py
+++ b/sqlparse/lexer.py
@@ -141,10 +141,10 @@ class Lexer(compat.with_metaclass(LexerMeta)):
tokens = {
'root': [
- (r'--.*?(\r\n|\r|\n)', tokens.Comment.Single),
+ (r'(--|#).*?(\r\n|\r|\n)', tokens.Comment.Single),
# $ matches *before* newline, therefore we have two patterns
# to match Comment.Single
- (r'--.*?$', tokens.Comment.Single),
+ (r'(--|#).*?$', tokens.Comment.Single),
(r'(\r\n|\r|\n)', tokens.Newline),
(r'\s+', tokens.Whitespace),
(r'/\*', tokens.Comment.Multiline, 'multiline-comments'),
@@ -163,6 +163,9 @@ class Lexer(compat.with_metaclass(LexerMeta)):
# see https://github.com/andialbrecht/sqlparse/pull/64
(r'VALUES', tokens.Keyword),
(r'@[^\W\d_]\w+', tokens.Name),
+ # IN is special, it may be followed by a parenthesis, but
+ # is never a functino, see issue183
+ (r'in\b(?=[ (])?', 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),
diff --git a/tests/test_grouping.py b/tests/test_grouping.py
index e1dc3fe..0c2f108 100644
--- a/tests/test_grouping.py
+++ b/tests/test_grouping.py
@@ -208,6 +208,12 @@ class TestGrouping(TestCaseBase):
self.assert_(isinstance(p.tokens[0], sql.Function))
self.assertEqual(len(list(p.tokens[0].get_parameters())), 2)
+ def test_function_not_in(self): # issue183
+ p = sqlparse.parse('in(1, 2)')[0]
+ self.assertEqual(len(p.tokens), 2)
+ self.assertEqual(p.tokens[0].ttype, T.Keyword)
+ self.assert_(isinstance(p.tokens[1], sql.Parenthesis))
+
def test_varchar(self):
p = sqlparse.parse('"text" Varchar(50) NOT NULL')[0]
self.assert_(isinstance(p.tokens[2], sql.Function))
@@ -386,4 +392,4 @@ def test_aliased_function_without_as():
def test_aliased_literal_without_as():
p = sqlparse.parse('1 foo')[0].tokens
assert len(p) == 1
- assert p[0].get_alias() == 'foo' \ No newline at end of file
+ assert p[0].get_alias() == 'foo'
diff --git a/tests/test_parse.py b/tests/test_parse.py
index 31451c1..c953dc2 100644
--- a/tests/test_parse.py
+++ b/tests/test_parse.py
@@ -284,3 +284,13 @@ def test_typed_array_definition():
assert names == ['x', 'y', 'z']
+@pytest.mark.parametrize('sql', [
+ 'select 1 -- foo',
+ 'select 1 # foo' # see issue178
+])
+def test_single_line_comments(sql):
+ p = sqlparse.parse(sql)[0]
+ assert len(p.tokens) == 5
+ assert p.tokens[-1].ttype == T.Comment.Single
+
+