diff options
| author | Andi Albrecht <albrecht.andi@gmail.com> | 2010-11-14 22:03:13 +0100 |
|---|---|---|
| committer | Andi Albrecht <albrecht.andi@gmail.com> | 2010-11-14 22:03:13 +0100 |
| commit | fbaf4c2b596239e2ba2b88e36ac671672d94b1f3 (patch) | |
| tree | e6e151d9deeef04b3a7c53578edeccdb4f30839d | |
| parent | 51bd3d5e1603676ab245fd6637b7c7fc9de342f6 (diff) | |
| download | sqlparse-fbaf4c2b596239e2ba2b88e36ac671672d94b1f3.tar.gz | |
Match single line comments at end of string.
The bug was reported for CrunchyFrog: http://code.google.com/p/crunchyfrog/issues/detail?id=88
| -rw-r--r-- | sqlparse/lexer.py | 5 | ||||
| -rw-r--r-- | tests/test_split.py | 10 |
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) |
