ThirdParty/Pygments/pygments/lexers/python.py

changeset 5072
aab59042fefb
parent 4697
c2e9bf425554
child 5713
6762afd9f963
--- a/ThirdParty/Pygments/pygments/lexers/python.py	Wed Jul 27 18:10:08 2016 +0200
+++ b/ThirdParty/Pygments/pygments/lexers/python.py	Fri Jul 29 19:50:40 2016 +0200
@@ -213,6 +213,26 @@
 
     uni_name = "[%s][%s]*" % (uni.xid_start, uni.xid_continue)
 
+    def innerstring_rules(ttype):
+        return [
+            # 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),
+
+            # backslashes, quotes and formatting signs must be parsed one at a time
+            (r'[^\\\'"%\{\n]+', ttype),
+            (r'[\'"\\]', ttype),
+            # unhandled string formatting sign
+            (r'%|(\{{1,2})', ttype)
+            # newlines are an error (use "nl" state)
+        ]
+
     tokens = PythonLexer.tokens.copy()
     tokens['keywords'] = [
         (words((
@@ -295,23 +315,8 @@
         (uni_name, Name.Namespace),
         default('#pop'),
     ]
-    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),
-        # backslashes, quotes and formatting signs must be parsed one at a time
-        (r'[^\\\'"%\{\n]+', String),
-        (r'[\'"\\]', String),
-        # unhandled string formatting sign
-        (r'%|(\{{1,2})', String)
-        # newlines are an error (use "nl" state)
-    ]
+    tokens['strings-single'] = innerstring_rules(String.Single)
+    tokens['strings-double'] = innerstring_rules(String.Double)
 
     def analyse_text(text):
         return shebang_matches(text, r'pythonw?3(\.\d)?')

eric ide

mercurial