diff --git a/README.md b/README.md index d1b806a..c3b2f39 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,7 @@ The most up-to-date lexer and highlighter for [_Mathematica_](http://wolfram.com source code using the [pygments](http://pygments.org) engine. ![](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square) -![](https://img.shields.io/badge/version-0.4.0-yellow.svg?style=flat-square) -![](https://img.shields.io/travis/rsmenon/pygments-mathematica/master.svg?style=flat-square) +![](https://img.shields.io/badge/version-0.4.1-yellow.svg?style=flat-square) ![](https://img.shields.io/badge/python-3.9%2B-lightgrey.svg?style=flat-square) ![](https://img.shields.io/pypi/v/pygments-mathematica.svg?style=flat-square) ## Features diff --git a/mathematica/lexer.py b/mathematica/lexer.py index b2efc83..a09708a 100644 --- a/mathematica/lexer.py +++ b/mathematica/lexer.py @@ -82,11 +82,7 @@ class MathematicaLexer(RegexLexer): (Regex.INTEGER, MToken.NUMBER), ], 'strings': [ - (r'[^"\\]+', MToken.STRING), - (r'^[\\"]', MToken.STRING), - (r'(\\n|\\r)', MToken.STRING), - (r'\\"', MToken.STRING), - (r'\\', MToken.STRING), + (r'([^"\\]|\\.)+', MToken.STRING), (r'"', MToken.STRING, '#pop'), ], } diff --git a/setup.py b/setup.py index 705a79b..ece1df8 100644 --- a/setup.py +++ b/setup.py @@ -29,7 +29,7 @@ setup( name='pygments-mathematica', - version='0.4.0', + version='0.4.1', description='Mathematica/Wolfram Language Lexer for Pygments', long_description=__doc__, author='rsmenon', diff --git a/tests/test_lexer.py b/tests/test_lexer.py index c7149a3..34f7a9f 100644 --- a/tests/test_lexer.py +++ b/tests/test_lexer.py @@ -77,22 +77,17 @@ def test_strings(self): ], [ (MToken.STRING, '"'), - (MToken.STRING, 'a string '), - (MToken.STRING, '\\"'), - (MToken.STRING, ' with a quote'), + (MToken.STRING, 'a string \\" with a quote'), (MToken.STRING, '"'), ], [ (MToken.STRING, '"'), - (MToken.STRING, 'a string with a newline'), - (MToken.STRING, '\\n'), + (MToken.STRING, 'a string with a newline\\n'), (MToken.STRING, '"'), ], [ (MToken.STRING, '"'), - (MToken.STRING, 'a string with '), - (MToken.STRING, '\\'), - (MToken.STRING, ' two backslashes'), + (MToken.STRING, 'a string with \\ two backslashes'), (MToken.STRING, '"'), ] ] @@ -393,3 +388,13 @@ def test_lexical_scope_nasty(self): (MToken.GROUP, ']'), ] self.verify(code, expected) + + def test_string_closing_quote_on_newline(self): + code = '"test string\n"abc' + expected = [ + (MToken.STRING, '"'), + (MToken.STRING, 'test string\n'), + (MToken.STRING, '"'), + (MToken.SYMBOL, 'abc'), + ] + self.verify(code, expected) \ No newline at end of file