ThirdParty/Pygments/pygments/lexers/python.py

changeset 5072
aab59042fefb
parent 4697
c2e9bf425554
child 5713
6762afd9f963
equal deleted inserted replaced
5070:4e4651e88674 5072:aab59042fefb
210 mimetypes = ['text/x-python3', 'application/x-python3'] 210 mimetypes = ['text/x-python3', 'application/x-python3']
211 211
212 flags = re.MULTILINE | re.UNICODE 212 flags = re.MULTILINE | re.UNICODE
213 213
214 uni_name = "[%s][%s]*" % (uni.xid_start, uni.xid_continue) 214 uni_name = "[%s][%s]*" % (uni.xid_start, uni.xid_continue)
215
216 def innerstring_rules(ttype):
217 return [
218 # the old style '%s' % (...) string formatting (still valid in Py3)
219 (r'%(\(\w+\))?[-#0 +]*([0-9]+|[*])?(\.([0-9]+|[*]))?'
220 '[hlL]?[diouxXeEfFgGcrs%]', String.Interpol),
221 # the new style '{}'.format(...) string formatting
222 (r'\{'
223 '((\w+)((\.\w+)|(\[[^\]]+\]))*)?' # field name
224 '(\![sra])?' # conversion
225 '(\:(.?[<>=\^])?[-+ ]?#?0?(\d+)?,?(\.\d+)?[bcdeEfFgGnosxX%]?)?'
226 '\}', String.Interpol),
227
228 # backslashes, quotes and formatting signs must be parsed one at a time
229 (r'[^\\\'"%\{\n]+', ttype),
230 (r'[\'"\\]', ttype),
231 # unhandled string formatting sign
232 (r'%|(\{{1,2})', ttype)
233 # newlines are an error (use "nl" state)
234 ]
215 235
216 tokens = PythonLexer.tokens.copy() 236 tokens = PythonLexer.tokens.copy()
217 tokens['keywords'] = [ 237 tokens['keywords'] = [
218 (words(( 238 (words((
219 'assert', 'async', 'await', 'break', 'continue', 'del', 'elif', 239 'assert', 'async', 'await', 'break', 'continue', 'del', 'elif',
293 (r'(\s+)(import)\b', bygroups(Text, Keyword), '#pop'), 313 (r'(\s+)(import)\b', bygroups(Text, Keyword), '#pop'),
294 (r'\.', Name.Namespace), 314 (r'\.', Name.Namespace),
295 (uni_name, Name.Namespace), 315 (uni_name, Name.Namespace),
296 default('#pop'), 316 default('#pop'),
297 ] 317 ]
298 tokens['strings'] = [ 318 tokens['strings-single'] = innerstring_rules(String.Single)
299 # the old style '%s' % (...) string formatting (still valid in Py3) 319 tokens['strings-double'] = innerstring_rules(String.Double)
300 (r'%(\(\w+\))?[-#0 +]*([0-9]+|[*])?(\.([0-9]+|[*]))?'
301 '[hlL]?[diouxXeEfFgGcrs%]', String.Interpol),
302 # the new style '{}'.format(...) string formatting
303 (r'\{'
304 '((\w+)((\.\w+)|(\[[^\]]+\]))*)?' # field name
305 '(\![sra])?' # conversion
306 '(\:(.?[<>=\^])?[-+ ]?#?0?(\d+)?,?(\.\d+)?[bcdeEfFgGnosxX%]?)?'
307 '\}', String.Interpol),
308 # backslashes, quotes and formatting signs must be parsed one at a time
309 (r'[^\\\'"%\{\n]+', String),
310 (r'[\'"\\]', String),
311 # unhandled string formatting sign
312 (r'%|(\{{1,2})', String)
313 # newlines are an error (use "nl" state)
314 ]
315 320
316 def analyse_text(text): 321 def analyse_text(text):
317 return shebang_matches(text, r'pythonw?3(\.\d)?') 322 return shebang_matches(text, r'pythonw?3(\.\d)?')
318 323
319 324

eric ide

mercurial