MCPcopy Index your code
hub / github.com/python/cpython / make_pat

Function make_pat

Lib/idlelib/colorizer.py:17–68  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

15
16
17def make_pat():
18 kw = r"\b" + any("KEYWORD", keyword.kwlist) + r"\b"
19 match_softkw = (
20 r"^[ \t]*" + # at beginning of line + possible indentation
21 r"(?P<MATCH_SOFTKW>match)\b" +
22 r"(?![ \t]*(?:" + "|".join([ # not followed by ...
23 r"[:,;=^&|@~)\]}]", # a character which means it can't be a
24 # pattern-matching statement
25 r"\b(?:" + r"|".join(keyword.kwlist) + r")\b", # a keyword
26 ]) +
27 r"))"
28 )
29 case_default = (
30 r"^[ \t]*" + # at beginning of line + possible indentation
31 r"(?P<CASE_SOFTKW>case)" +
32 r"[ \t]+(?P<CASE_DEFAULT_UNDERSCORE>_\b)"
33 )
34 case_softkw_and_pattern = (
35 r"^[ \t]*" + # at beginning of line + possible indentation
36 r"(?P<CASE_SOFTKW2>case)\b" +
37 r"(?![ \t]*(?:" + "|".join([ # not followed by ...
38 r"_\b", # a lone underscore
39 r"[:,;=^&|@~)\]}]", # a character which means it can't be a
40 # pattern-matching case
41 r"\b(?:" + r"|".join(keyword.kwlist) + r")\b", # a keyword
42 ]) +
43 r"))"
44 )
45 lazy_softkw = (
46 r"^[ \t]*" + # at beginning of line + possible indentation
47 r"(?P<LAZY_SOFTKW>lazy)" +
48 r"(?=[ \t]+(?:import|from)\b)" # followed by 'import' or 'from'
49 )
50 builtinlist = [str(name) for name in dir(builtins)
51 if not name.startswith('_') and
52 name not in keyword.kwlist]
53 builtin = r"([^.'\"\\#]\b|^)" + any("BUILTIN", builtinlist) + r"\b"
54 comment = any("COMMENT", [r"#[^\n]*"])
55 stringprefix = r"(?i:r|u|f|fr|rf|b|br|rb|t|rt|tr)?"
56 sqstring = stringprefix + r"'[^'\\\n]*(\\.[^'\\\n]*)*'?"
57 dqstring = stringprefix + r'"[^"\\\n]*(\\.[^"\\\n]*)*"?'
58 sq3string = stringprefix + r"'''[^'\\]*((\\.|'(?!''))[^'\\]*)*(''')?"
59 dq3string = stringprefix + r'"""[^"\\]*((\\.|"(?!""))[^"\\]*)*(""")?'
60 string = any("STRING", [sq3string, dq3string, sqstring, dqstring])
61 prog = re.compile("|".join([
62 builtin, comment, string, kw,
63 match_softkw, case_default,
64 case_softkw_and_pattern, lazy_softkw,
65 any("SYNC", [r"\n"]),
66 ]),
67 re.DOTALL | re.MULTILINE)
68 return prog
69
70
71prog = make_pat()

Callers 1

colorizer.pyFile · 0.85

Calls 5

strFunction · 0.85
anyFunction · 0.70
joinMethod · 0.45
startswithMethod · 0.45
compileMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…