From 9dbcfd31abafe48ee7c646129c40e904ff0a5fac Mon Sep 17 00:00:00 2001 From: Andi Albrecht Date: Mon, 16 Mar 2015 07:50:06 +0100 Subject: Support comments starting with '#' character (fixes #178). --- CHANGES | 1 + sqlparse/lexer.py | 2 +- tests/test_parse.py | 10 ++++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index c264b9f..4229de3 100644 --- a/CHANGES +++ b/CHANGES @@ -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 + + -- cgit v1.2.1