Coverage for C:\leo.repo\leo-editor\leo\modes\python.py: 53%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# Leo colorizer control file for python mode.
2# This file is in the public domain.
4# Properties for python mode.
5properties = {
6 "indentNextLines": "\\s*[^#]{3,}:\\s*(#.*)?",
7 "lineComment": "#",
8}
10# Attributes dict for python_main ruleset.
11python_main_attributes_dict = {
12 "default": "null",
13 "digit_re": "",
14 "escape": "\\",
15 "highlight_digits": "true",
16 "ignore_case": "false",
17 "no_word_sep": "",
18}
20# Dictionary of attributes dictionaries for python mode.
21attributesDictDict = {
22 "python_main": python_main_attributes_dict,
23}
25# Keywords dict for python_main ruleset.
26python_main_keywords_dict = {
27 "ArithmeticError": "keyword3",
28 "AssertionError": "keyword3",
29 "AttributeError": "keyword3",
30 "BufferType": "keyword3",
31 "BuiltinFunctionType": "keyword3",
32 "BuiltinMethodType": "keyword3",
33 "ClassType": "keyword3",
34 "CodeType": "keyword3",
35 "ComplexType": "keyword3",
36 "DeprecationWarning": "keyword3",
37 "DictProxyType": "keyword3",
38 "DictType": "keyword3",
39 "DictionaryType": "keyword3",
40 "EOFError": "keyword3",
41 "EllipsisType": "keyword3",
42 "EnvironmentError": "keyword3",
43 "Exception": "keyword3",
44 "False": "keyword3",
45 "FileType": "keyword3",
46 "FloatType": "keyword3",
47 "FloatingPointError": "keyword3",
48 "FrameType": "keyword3",
49 "FunctionType": "keyword3",
50 "GeneratorType": "keyword3",
51 "IOError": "keyword3",
52 "ImportError": "keyword3",
53 "IndentationError": "keyword3",
54 "IndexError": "keyword3",
55 "InstanceType": "keyword3",
56 "IntType": "keyword3",
57 "KeyError": "keyword3",
58 "KeyboardInterrupt": "keyword3",
59 "LambdaType": "keyword3",
60 "ListType": "keyword3",
61 "LongType": "keyword3",
62 "LookupError": "keyword3",
63 "MemoryError": "keyword3",
64 "MethodType": "keyword3",
65 "ModuleType": "keyword3",
66 "NameError": "keyword3",
67 "None": "keyword3",
68 "NoneType": "keyword3",
69 "NotImplemented": "keyword3",
70 "NotImplementedError": "keyword3",
71 "OSError": "keyword3",
72 "ObjectType": "keyword3",
73 "OverflowError": "keyword3",
74 "OverflowWarning": "keyword3",
75 "ReferenceError": "keyword3",
76 "RuntimeError": "keyword3",
77 "RuntimeWarning": "keyword3",
78 "SliceType": "keyword3",
79 "StandardError": "keyword3",
80 "StopIteration": "keyword3",
81 "StringType": "keyword3",
82 "StringTypes": "keyword3",
83 "SyntaxError": "keyword3",
84 "SyntaxWarning": "keyword3",
85 "SystemError": "keyword3",
86 "SystemExit": "keyword3",
87 "TabError": "keyword3",
88 "TracebackType": "keyword3",
89 "True": "keyword3",
90 "TupleType": "keyword3",
91 "TypeError": "keyword3",
92 "TypeType": "keyword3",
93 "UnboundLocalError": "keyword3",
94 "UnboundMethodType": "keyword3",
95 "UnicodeError": "keyword3",
96 "UnicodeType": "keyword3",
97 "UserWarning": "keyword3",
98 "ValueError": "keyword3",
99 "Warning": "keyword3",
100 "WindowsError": "keyword3",
101 "XRangeType": "keyword3",
102 "ZeroDivisionError": "keyword3",
103 "__abs__": "keyword3",
104 "__add__": "keyword3",
105 "__all__": "keyword3",
106 "__author__": "keyword3",
107 "__bases__": "keyword3",
108 "__builtins__": "keyword3",
109 "__call__": "keyword3",
110 "__class__": "keyword3",
111 "__cmp__": "keyword3",
112 "__coerce__": "keyword3",
113 "__contains__": "keyword3",
114 "__debug__": "keyword3",
115 "__del__": "keyword3",
116 "__delattr__": "keyword3",
117 "__delitem__": "keyword3",
118 "__delslice__": "keyword3",
119 "__dict__": "keyword3",
120 "__div__": "keyword3",
121 "__divmod__": "keyword3",
122 "__doc__": "keyword3",
123 "__eq__": "keyword3",
124 "__file__": "keyword3",
125 "__float__": "keyword3",
126 "__floordiv__": "keyword3",
127 "__future__": "keyword3",
128 "__ge__": "keyword3",
129 "__getattr__": "keyword3",
130 "__getattribute__": "keyword3",
131 "__getitem__": "keyword3",
132 "__getslice__": "keyword3",
133 "__gt__": "keyword3",
134 "__hash__": "keyword3",
135 "__hex__": "keyword3",
136 "__iadd__": "keyword3",
137 "__import__": "keyword3",
138 "__imul__": "keyword3",
139 "__init__": "keyword3",
140 "__int__": "keyword3",
141 "__invert__": "keyword3",
142 "__iter__": "keyword3",
143 "__le__": "keyword3",
144 "__len__": "keyword3",
145 "__long__": "keyword3",
146 "__lshift__": "keyword3",
147 "__lt__": "keyword3",
148 "__members__": "keyword3",
149 "__metaclass__": "keyword3",
150 "__mod__": "keyword3",
151 "__mro__": "keyword3",
152 "__mul__": "keyword3",
153 "__name__": "keyword3",
154 "__ne__": "keyword3",
155 "__neg__": "keyword3",
156 "__new__": "keyword3",
157 "__nonzero__": "keyword3",
158 "__oct__": "keyword3",
159 "__or__": "keyword3",
160 "__path__": "keyword3",
161 "__pos__": "keyword3",
162 "__pow__": "keyword3",
163 "__radd__": "keyword3",
164 "__rdiv__": "keyword3",
165 "__rdivmod__": "keyword3",
166 "__reduce__": "keyword3",
167 "__repr__": "keyword3",
168 "__rfloordiv__": "keyword3",
169 "__rlshift__": "keyword3",
170 "__rmod__": "keyword3",
171 "__rmul__": "keyword3",
172 "__ror__": "keyword3",
173 "__rpow__": "keyword3",
174 "__rrshift__": "keyword3",
175 "__rsub__": "keyword3",
176 "__rtruediv__": "keyword3",
177 "__rxor__": "keyword3",
178 "__self__": "keyword3",
179 "__setattr__": "keyword3",
180 "__setitem__": "keyword3",
181 "__setslice__": "keyword3",
182 "__slots__": "keyword3",
183 "__str__": "keyword3",
184 "__sub__": "keyword3",
185 "__truediv__": "keyword3",
186 "__version__": "keyword3",
187 "__xor__": "keyword3",
188 "abs": "keyword2",
189 "and": "keyword1",
190 "apply": "keyword2",
191 "as": "keyword1",
192 "assert": "keyword1",
193 "async": "keyword1", # Python 3.7
194 "await": "keyword1", # Python 3.7.
195 "basestring": "keyword2", # Only in Python 2.
196 "bool": "keyword2",
197 "break": "keyword1",
198 "buffer": "keyword2",
199 "callable": "keyword2",
200 "chr": "keyword2",
201 "class": "keyword1",
202 "@classmethod": "keyword2", # Bug fix: 5/14/2016
203 "cmp": "keyword2",
204 "coerce": "keyword2",
205 "compile": "keyword2",
206 "complex": "keyword2",
207 "continue": "keyword1",
208 "def": "keyword1",
209 "del": "keyword1",
210 "delattr": "keyword2",
211 "dict": "keyword2",
212 "dir": "keyword2",
213 "divmod": "keyword2",
214 "elif": "keyword1",
215 "else": "keyword1",
216 "enumerate": "keyword2",
217 "eval": "keyword2",
218 "except": "keyword1",
219 "exec": "keyword1",
220 "execfile": "keyword2",
221 "file": "keyword2",
222 "filter": "keyword2",
223 "finally": "keyword1",
224 "float": "keyword2",
225 "for": "keyword1",
226 "from": "keyword1",
227 "getattr": "keyword2",
228 "global": "keyword1",
229 "globals": "keyword2",
230 "hasattr": "keyword2",
231 "hash": "keyword2",
232 "hex": "keyword2",
233 "id": "keyword2",
234 "if": "keyword1",
235 "import": "keyword1",
236 "in": "keyword1",
237 "input": "keyword2",
238 "int": "keyword2",
239 "intern": "keyword2",
240 "is": "keyword1",
241 "isinstance": "keyword2",
242 "issubclass": "keyword2",
243 "iter": "keyword2",
244 "lambda": "keyword1",
245 "len": "keyword2",
246 "list": "keyword2",
247 "locals": "keyword2",
248 "long": "keyword2",
249 "nonlocal": "keyword1",
250 "map": "keyword2",
251 "max": "keyword2",
252 "min": "keyword2",
253 "not": "keyword1",
254 "object": "keyword2",
255 "oct": "keyword2",
256 "open": "keyword2",
257 "or": "keyword1",
258 "ord": "keyword2",
259 "pass": "keyword1",
260 "pow": "keyword2",
261 "print": "keyword1",
262 "property": "keyword2",
263 "raise": "keyword1",
264 "range": "keyword2",
265 "raw_input": "keyword2",
266 "reduce": "keyword2",
267 "reload": "keyword2",
268 "repr": "keyword2",
269 "return": "keyword1",
270 "reversed": "keyword2",
271 "round": "keyword2",
272 "set": "keyword2",
273 "setattr": "keyword2",
274 "slice": "keyword2",
275 "sorted": "keyword2",
276 "@staticmethod": "keyword2", # Bug fix: 5/14/2016
277 "str": "keyword2",
278 "sum": "keyword2",
279 "super": "keyword2",
280 "try": "keyword1",
281 "tuple": "keyword2",
282 "type": "keyword2",
283 "unichr": "keyword2",
284 "unicode": "keyword2",
285 "vars": "keyword2",
286 "while": "keyword1",
287 "with": "keyword1", # Fix bug 1174532: Python mode file missing 'with' keyword
288 "xrange": "keyword2",
289 "yield": "keyword1",
290 "zip": "keyword2",
291}
293# Dictionary of keywords dictionaries for python mode.
294keywordsDictDict = {
295 "python_main": python_main_keywords_dict,
296}
298# Rules for python_main ruleset.
300def python_rule0(colorer, s, i):
301 return colorer.match_eol_span(s, i, kind="comment1", seq="#",
302 at_line_start=False, at_whitespace_end=False, at_word_start=False,
303 delegate="", exclude_match=False)
305def python_rule1(colorer, s, i):
306 return colorer.match_span(s, i, kind="literal2", begin="\"\"\"", end="\"\"\"",
307 at_line_start=False, at_whitespace_end=False, at_word_start=False,
308 delegate="", exclude_match=False,
309 no_escape=False, no_line_break=False, no_word_break=False)
311def python_rule2(colorer, s, i):
312 return colorer.match_span(s, i, kind="literal2", begin="'''", end="'''",
313 at_line_start=False, at_whitespace_end=False, at_word_start=False,
314 delegate="", exclude_match=False,
315 no_escape=False, no_line_break=False, no_word_break=False)
317def python_rule3(colorer, s, i):
318 return colorer.match_span(s, i, kind="literal1", begin="\"", end="\"",
319 at_line_start=False, at_whitespace_end=False, at_word_start=False,
320 delegate="", exclude_match=False,
321 no_escape=False, no_line_break=False, no_word_break=False)
323def python_rule4(colorer, s, i):
324 return colorer.match_span(s, i, kind="literal1", begin="'", end="'",
325 at_line_start=False, at_whitespace_end=False, at_word_start=False,
326 delegate="", exclude_match=False,
327 no_escape=False, no_line_break=False, no_word_break=False)
329def python_rule5(colorer, s, i):
330 return colorer.match_seq(s, i, kind="operator", seq="=",
331 at_line_start=False, at_whitespace_end=False, at_word_start=False, delegate="")
333def python_rule6(colorer, s, i):
334 return colorer.match_seq(s, i, kind="operator", seq="!",
335 at_line_start=False, at_whitespace_end=False, at_word_start=False, delegate="")
337def python_rule7(colorer, s, i):
338 return colorer.match_seq(s, i, kind="operator", seq=">=",
339 at_line_start=False, at_whitespace_end=False, at_word_start=False, delegate="")
341def python_rule8(colorer, s, i):
342 return colorer.match_seq(s, i, kind="operator", seq="<=",
343 at_line_start=False, at_whitespace_end=False, at_word_start=False, delegate="")
345def python_rule9(colorer, s, i):
346 return colorer.match_seq(s, i, kind="operator", seq="+",
347 at_line_start=False, at_whitespace_end=False, at_word_start=False, delegate="")
349def python_rule10(colorer, s, i):
350 return colorer.match_seq(s, i, kind="operator", seq="-",
351 at_line_start=False, at_whitespace_end=False, at_word_start=False, delegate="")
353def python_rule11(colorer, s, i):
354 return colorer.match_seq(s, i, kind="operator", seq="/",
355 at_line_start=False, at_whitespace_end=False, at_word_start=False, delegate="")
357def python_rule12(colorer, s, i):
358 return colorer.match_seq(s, i, kind="operator", seq="*",
359 at_line_start=False, at_whitespace_end=False, at_word_start=False, delegate="")
361def python_rule13(colorer, s, i):
362 return colorer.match_seq(s, i, kind="operator", seq=">",
363 at_line_start=False, at_whitespace_end=False, at_word_start=False, delegate="")
365def python_rule14(colorer, s, i):
366 return colorer.match_seq(s, i, kind="operator", seq="<",
367 at_line_start=False, at_whitespace_end=False, at_word_start=False, delegate="")
369def python_rule15(colorer, s, i):
370 return colorer.match_seq(s, i, kind="operator", seq="%",
371 at_line_start=False, at_whitespace_end=False, at_word_start=False, delegate="")
373def python_rule16(colorer, s, i):
374 return colorer.match_seq(s, i, kind="operator", seq="&",
375 at_line_start=False, at_whitespace_end=False, at_word_start=False, delegate="")
377def python_rule17(colorer, s, i):
378 return colorer.match_seq(s, i, kind="operator", seq="|",
379 at_line_start=False, at_whitespace_end=False, at_word_start=False, delegate="")
381def python_rule18(colorer, s, i):
382 return colorer.match_seq(s, i, kind="operator", seq="^",
383 at_line_start=False, at_whitespace_end=False, at_word_start=False, delegate="")
385def python_rule19(colorer, s, i):
386 return colorer.match_seq(s, i, kind="operator", seq="~",
387 at_line_start=False, at_whitespace_end=False, at_word_start=False, delegate="")
389# #1821.
390# def python_rule20(colorer, s, i):
391 # return colorer.match_mark_previous(s, i, kind="function", pattern="(",
392 # at_line_start=False, at_whitespace_end=False, at_word_start=False, exclude_match=True)
394def python_rule21(colorer, s, i):
395 return colorer.match_keywords(s, i)
397url = False
399if url:
400 h_url_regex = r"""(http|https)://[^\s'"]+[\w=/]"""
401 f_url_regex = r"""(file|ftp)://[^\s'"]+[\w=/]"""
403 def python_rule_h_url(colorer, s, i):
404 return colorer.match_seq_regexp(s, i, kind="keyword", regexp=h_url_regex,
405 at_line_start=False, at_whitespace_end=False, at_word_start=False, delegate="")
407 def python_rule_f_url(colorer, s, i):
408 return colorer.match_seq_regexp(s, i, kind="keyword", regexp=f_url_regex,
409 at_line_start=False, at_whitespace_end=False, at_word_start=False, delegate="")
410else:
411 # Always fail.
412 def python_rule_h_url(colorer, s, i):
413 return 0
415 def python_rule_f_url(colorer, s, i):
416 return 0
418# Rules dict for python_main ruleset.
419rulesDict1 = {
420 "!": [python_rule6,],
421 "\"": [python_rule1, python_rule3,],
422 "#": [python_rule0,],
423 "%": [python_rule15,],
424 "&": [python_rule16,],
425 "'": [python_rule2, python_rule4,],
426 # "(": [python_rule20,],
427 "*": [python_rule12,],
428 "+": [python_rule9,],
429 "-": [python_rule10,],
430 "/": [python_rule11,],
431 "0": [python_rule21,],
432 "1": [python_rule21,],
433 "2": [python_rule21,],
434 "3": [python_rule21,],
435 "4": [python_rule21,],
436 "5": [python_rule21,],
437 "6": [python_rule21,],
438 "7": [python_rule21,],
439 "8": [python_rule21,],
440 "9": [python_rule21,],
441 "<": [python_rule8, python_rule14,],
442 "=": [python_rule5,],
443 ">": [python_rule7, python_rule13,],
444 "@": [python_rule21,],
445 "A": [python_rule21,],
446 "B": [python_rule21,],
447 "C": [python_rule21,],
448 "D": [python_rule21,],
449 "E": [python_rule21,],
450 "F": [python_rule_f_url, python_rule21,],
451 "G": [python_rule21,],
452 "H": [python_rule_h_url, python_rule21,],
453 "I": [python_rule21,],
454 "J": [python_rule21,],
455 "K": [python_rule21,],
456 "L": [python_rule21,],
457 "M": [python_rule21,],
458 "N": [python_rule21,],
459 "O": [python_rule21,],
460 "P": [python_rule21,],
461 "Q": [python_rule21,],
462 "R": [python_rule21,],
463 "S": [python_rule21,],
464 "T": [python_rule21,],
465 "U": [python_rule21,],
466 "V": [python_rule21,],
467 "W": [python_rule21,],
468 "X": [python_rule21,],
469 "Y": [python_rule21,],
470 "Z": [python_rule21,],
471 "^": [python_rule18,],
472 "_": [python_rule21,],
473 "a": [python_rule21,],
474 "b": [python_rule21,],
475 "c": [python_rule21,],
476 "d": [python_rule21,],
477 "e": [python_rule21,],
478 "f": [python_rule_f_url, python_rule21,],
479 "g": [python_rule21,],
480 "h": [python_rule_h_url, python_rule21,],
481 "i": [python_rule21,],
482 "j": [python_rule21,],
483 "k": [python_rule21,],
484 "l": [python_rule21,],
485 "m": [python_rule21,],
486 "n": [python_rule21,],
487 "o": [python_rule21,],
488 "p": [python_rule21,],
489 "q": [python_rule21,],
490 "r": [python_rule21,],
491 "s": [python_rule21,],
492 "t": [python_rule21,],
493 "u": [python_rule21,],
494 "v": [python_rule21,],
495 "w": [python_rule21,],
496 "x": [python_rule21,],
497 "y": [python_rule21,],
498 "z": [python_rule21,],
499 "|": [python_rule17,],
500 "~": [python_rule19,],
501}
503# x.rulesDictDict for python mode.
504rulesDictDict = {
505 "python_main": rulesDict1,
506}
508# Import dict for python mode.
509importDict = {}