summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiikka Salminen <miikka.salminen@gmail.com>2015-03-08 15:15:22 +0200
committerMiikka Salminen <miikka.salminen@gmail.com>2015-03-08 15:15:22 +0200
commite871b16968f56234daa21947598e89638279c9a1 (patch)
treece76d180f37fc4271710e13a3ad7931330b166af
parentaecf4f9187aceadb123a0155dafe3f9e7e0e9b6e (diff)
downloadpygments-e871b16968f56234daa21947598e89638279c9a1.tar.gz
The new style string formatting now works correctly with multiple occurrences of interpolation fields in one string, and erroneous fields are handled properly.
-rw-r--r--pygments/lexers/python.py8
1 files changed, 4 insertions, 4 deletions
diff --git a/pygments/lexers/python.py b/pygments/lexers/python.py
index ed63fb25..e5218be0 100644
--- a/pygments/lexers/python.py
+++ b/pygments/lexers/python.py
@@ -159,8 +159,8 @@ class PythonLexer(RegexLexer):
# the old style '%s' % (...) string formatting
(r'%(\(\w+\))?[-#0 +]*([0-9]+|[*])?(\.([0-9]+|[*]))?'
'[hlL]?[diouxXeEfFgGcrs%]', String.Interpol),
+ # backslashes, quotes and formatting signs must be parsed one at a time
(r'[^\\\'"%\n]+', String),
- # quotes, percents and backslashes must be parsed one at a time
(r'[\'"\\]', String),
# unhandled string formatting sign
(r'%', String)
@@ -303,11 +303,11 @@ class Python3Lexer(RegexLexer):
'(\![sra])?' # conversion
'(\:(.?[<>=\^])?[-+ ]?#?0?(\d+)?,?(\.\d+)?[bcdeEfFgGnosxX%]?)?'
'\}', String.Interpol),
- (r'[^\\\'"%\n]+', String),
- # quotes, percents and backslashes must be parsed one at a time
+ # backslashes, quotes and formatting signs must be parsed one at a time
+ (r'[^\\\'"%\{\n]+', String),
(r'[\'"\\]', String),
# unhandled string formatting sign
- (r'%', String)
+ (r'%|(\{{1,2})', String)
# newlines are an error (use "nl" state)
]