Skip to content

Commit 170010e

Browse files
Ian Robertsonandialbrecht
authored andcommitted
Add in slash comment functionality
1 parent ad8d1d1 commit 170010e

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

sqlparse/keywords.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ def is_keyword(value):
2121

2222
SQL_REGEX = {
2323
'root': [
24-
(r'(--|# )\+.*?(\r\n|\r|\n|$)', tokens.Comment.Single.Hint),
24+
(r'(--|//|# )\+.*?(\r\n|\r|\n|$)', tokens.Comment.Single.Hint),
2525
(r'/\*\+[\s\S]*?\*/', tokens.Comment.Multiline.Hint),
2626

27-
(r'(--|# ).*?(\r\n|\r|\n|$)', tokens.Comment.Single),
27+
(r'(--|//|# ).*?(\r\n|\r|\n|$)', tokens.Comment.Single),
2828
(r'/\*[\s\S]*?\*/', tokens.Comment.Multiline),
2929

3030
(r'(\r\n|\r|\n)', tokens.Newline),

tests/files/slashcomment.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
select * from user;
2+
//select * from host;
3+
select * from user;
4+
select * // foo;
5+
from foo;

tests/test_split.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,22 @@ def test_split_dashcomments_eol(s):
5252
assert len(stmts) == 1
5353

5454

55+
def test_split_slashcomments(load_file):
56+
sql = load_file('slashcomment.sql')
57+
stmts = sqlparse.parse(sql)
58+
assert len(stmts) == 3
59+
assert ''.join(str(q) for q in stmts) == sql
60+
61+
62+
@pytest.mark.parametrize('s', ['select foo; // comment\n',
63+
'select foo; // comment\r',
64+
'select foo; // comment\r\n',
65+
'select foo; // comment'])
66+
def test_split_slashcomments_eol(s):
67+
stmts = sqlparse.parse(s)
68+
assert len(stmts) == 1
69+
70+
5571
def test_split_begintag(load_file):
5672
sql = load_file('begintag.sql')
5773
stmts = sqlparse.parse(sql)

0 commit comments

Comments
 (0)