diff options
| -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 + + |
