summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiikka Salminen <miikka.salminen@gmail.com>2015-03-08 14:59:05 +0200
committerMiikka Salminen <miikka.salminen@gmail.com>2015-03-08 14:59:05 +0200
commitaecf4f9187aceadb123a0155dafe3f9e7e0e9b6e (patch)
tree64e03bae7409eedb5b6cbe089fcdc33c93354d09
parent98a654a135e4d6f65d03ffae12ebb24afb78f3ee (diff)
parentee9a9c0563710b000b276fa215e189335b7da69b (diff)
downloadpygments-aecf4f9187aceadb123a0155dafe3f9e7e0e9b6e.tar.gz
Merged birkenfeld/pygments-main into default
-rw-r--r--pygments/lexers/python.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/pygments/lexers/python.py b/pygments/lexers/python.py
index eab4f9f4..ed63fb25 100644
--- a/pygments/lexers/python.py
+++ b/pygments/lexers/python.py
@@ -156,6 +156,7 @@ class PythonLexer(RegexLexer):
r'U[a-fA-F0-9]{8}|x[a-fA-F0-9]{2}|[0-7]{1,3})', String.Escape)
],
'strings': [
+ # the old style '%s' % (...) string formatting
(r'%(\(\w+\))?[-#0 +]*([0-9]+|[*])?(\.([0-9]+|[*]))?'
'[hlL]?[diouxXeEfFgGcrs%]', String.Interpol),
(r'[^\\\'"%\n]+', String),
@@ -292,8 +293,16 @@ class Python3Lexer(RegexLexer):
(uni_name, Name.Namespace),
default('#pop'),
]
- # don't highlight "%s" substitutions
tokens['strings'] = [
+ # the old style '%s' % (...) string formatting (still valid in Py3)
+ (r'%(\(\w+\))?[-#0 +]*([0-9]+|[*])?(\.([0-9]+|[*]))?'
+ '[hlL]?[diouxXeEfFgGcrs%]', String.Interpol),
+ # the new style '{}'.format(...) string formatting
+ (r'\{'
+ '((\w+)((\.\w+)|(\[[^\]]+\]))*)?' # field name
+ '(\![sra])?' # conversion
+ '(\:(.?[<>=\^])?[-+ ]?#?0?(\d+)?,?(\.\d+)?[bcdeEfFgGnosxX%]?)?'
+ '\}', String.Interpol),
(r'[^\\\'"%\n]+', String),
# quotes, percents and backslashes must be parsed one at a time
(r'[\'"\\]', String),