1(attribute attribute: (identifier) @property)
2(type (identifier) @type)
3
4; Function calls
5
6(decorator) @function
7
8(call
9 function: (attribute attribute: (identifier) @function.method))
10(call
11 function: (identifier) @function)
12
13; Function definitions
14
15(function_definition
16 name: (identifier) @function)
17
18; Identifier naming conventions
19
20((identifier) @type
21 (#match? @type "^[A-Z]"))
22
23((identifier) @constant
24 (#match? @constant "^_*[A-Z][A-Z\\d_]*$"))
25
26; Builtin functions
27
28((call
29 function: (identifier) @function.builtin)
30 (#match?
31 @function.builtin
32 "^(abs|all|any|ascii|bin|bool|breakpoint|bytearray|bytes|callable|chr|classmethod|compile|complex|delattr|dict|dir|divmod|enumerate|eval|exec|filter|float|format|frozenset|getattr|globals|hasattr|hash|help|hex|id|input|int|isinstance|issubclass|iter|len|list|locals|map|max|memoryview|min|next|object|oct|open|ord|pow|print|property|range|repr|reversed|round|set|setattr|slice|sorted|staticmethod|str|sum|super|tuple|type|vars|zip|__import__)$"))
33
34; Literals
35
36[
37 (none)
38 (true)
39 (false)
40] @constant.builtin
41
42[
43 (integer)
44 (float)
45] @number
46
47; Self references
48
49[
50 (parameters (identifier) @variable.special)
51 (attribute (identifier) @variable.special)
52 (#match? @variable.special "^self$")
53]
54
55(comment) @comment
56(string) @string
57(escape_sequence) @string.escape
58
59[
60 "("
61 ")"
62 "["
63 "]"
64 "{"
65 "}"
66] @punctuation.bracket
67
68(interpolation
69 "{" @punctuation.special
70 "}" @punctuation.special) @embedded
71
72; Docstrings.
73(function_definition
74 "async"?
75 "def"
76 name: (_)
77 (parameters)?
78 body: (block (expression_statement (string) @string.doc)))
79
80[
81 "-"
82 "-="
83 "!="
84 "*"
85 "**"
86 "**="
87 "*="
88 "/"
89 "//"
90 "//="
91 "/="
92 "&"
93 "%"
94 "%="
95 "^"
96 "+"
97 "->"
98 "+="
99 "<"
100 "<<"
101 "<="
102 "<>"
103 "="
104 ":="
105 "=="
106 ">"
107 ">="
108 ">>"
109 "|"
110 "~"
111 "and"
112 "in"
113 "is"
114 "not"
115 "or"
116 "is not"
117 "not in"
118] @operator
119
120[
121 "as"
122 "assert"
123 "async"
124 "await"
125 "break"
126 "class"
127 "continue"
128 "def"
129 "del"
130 "elif"
131 "else"
132 "except"
133 "exec"
134 "finally"
135 "for"
136 "from"
137 "global"
138 "if"
139 "import"
140 "lambda"
141 "nonlocal"
142 "pass"
143 "print"
144 "raise"
145 "return"
146 "try"
147 "while"
148 "with"
149 "yield"
150 "match"
151 "case"
152] @keyword