diff options
author | Andi Albrecht <albrecht.andi@gmail.com> | 2015-03-16 07:50:06 +0100 |
---|---|---|
committer | Andi Albrecht <albrecht.andi@gmail.com> | 2015-03-16 07:50:06 +0100 |
commit | 9dbcfd31abafe48ee7c646129c40e904ff0a5fac (patch) | |
tree | 32e0909ffcf69d10e38f87575ecc0ce2aecc3958 | |
parent | d02a952b7c3f9a01c40630b6bf7699c1e9c95e21 (diff) | |
download | sqlparse-9dbcfd31abafe48ee7c646129c40e904ff0a5fac.tar.gz |
Support comments starting with '#' character (fixes #178).
-rw-r--r-- | CHANGES | 1 | ||||
-rw-r--r-- | sqlparse/lexer.py | 2 | ||||
-rw-r--r-- | tests/test_parse.py | 10 |
3 files changed, 12 insertions, 1 deletions
@@ -17,6 +17,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/lexer.py b/sqlparse/lexer.py index 4707990..0a402c3 100644 --- a/sqlparse/lexer.py +++ b/sqlparse/lexer.py @@ -167,7 +167,7 @@ class Lexer(object): (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'), diff --git a/tests/test_parse.py b/tests/test_parse.py index f6e796f..857685b 100644 --- a/tests/test_parse.py +++ b/tests/test_parse.py @@ -283,3 +283,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 + + |