From eeb5b9f147556dcb5d1a10a855e5c78c82c485e0 Mon Sep 17 00:00:00 2001 From: "R. Menon" Date: Sun, 2 Mar 2025 07:40:03 +0530 Subject: [PATCH 1/2] Fix incorrect tokenization when the string close quote is on a newline --- mathematica/lexer.py | 6 +----- tests/test_lexer.py | 21 +++++++++++++-------- 2 files changed, 14 insertions(+), 13 deletions(-) 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/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 From cfc6071aee74c73ea59400d2aa1707ffa9e960a8 Mon Sep 17 00:00:00 2001 From: "R. Menon" Date: Tue, 11 Mar 2025 16:32:48 +0530 Subject: [PATCH 2/2] Bump version to 0.4.1 --- README.md | 3 +-- setup.py | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) 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/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',