summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sqlparse/lexer.py5
-rw-r--r--tests/test_split.py10
2 files changed, 14 insertions, 1 deletions
diff --git a/sqlparse/lexer.py b/sqlparse/lexer.py
index 305ac66..dc87f94 100644
--- a/sqlparse/lexer.py
+++ b/sqlparse/lexer.py
@@ -162,7 +162,10 @@ class Lexer:
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'(\r|\n|\r\n)', tokens.Newline),
(r'\s+', tokens.Whitespace),
(r'/\*', tokens.Comment.Multiline, 'multiline-comments'),
diff --git a/tests/test_split.py b/tests/test_split.py
index 50b3a6b..1995ca5 100644
--- a/tests/test_split.py
+++ b/tests/test_split.py
@@ -53,6 +53,16 @@ class SQLSplitTest(TestCaseBase):
self.assertEqual(len(stmts), 3)
self.ndiffAssertEqual(''.join(unicode(q) for q in stmts), sql)
+ def test_dashcomments_eol(self):
+ stmts = sqlparse.parse('select foo; -- comment\n')
+ self.assertEqual(len(stmts), 1)
+ stmts = sqlparse.parse('select foo; -- comment\r')
+ self.assertEqual(len(stmts), 1)
+ stmts = sqlparse.parse('select foo; -- comment\r\n')
+ self.assertEqual(len(stmts), 1)
+ stmts = sqlparse.parse('select foo; -- comment')
+ self.assertEqual(len(stmts), 1)
+
def test_begintag(self):
sql = load_file('begintag.sql')
stmts = sqlparse.parse(sql)