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(comment) @comment
48(string) @string
49(escape_sequence) @escape
50
51[
52 "("
53 ")"
54 "["
55 "]"
56 "{"
57 "}"
58] @punctuation.bracket
59
60(interpolation
61 "{" @punctuation.special
62 "}" @punctuation.special) @embedded
63
64; Docstrings.
65(function_definition
66 "async"?
67 "def"
68 name: (_)
69 (parameters)?
70 body: (block (expression_statement (string) @string.doc)))
71
72[
73 "-"
74 "-="
75 "!="
76 "*"
77 "**"
78 "**="
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 "and"
104 "in"
105 "is"
106 "not"
107 "or"
108 "is not"
109 "not in"
110] @operator
111
112[
113 "as"
114 "assert"
115 "async"
116 "await"
117 "break"
118 "class"
119 "continue"
120 "def"
121 "del"
122 "elif"
123 "else"
124 "except"
125 "exec"
126 "finally"
127 "for"
128 "from"
129 "global"
130 "if"
131 "import"
132 "lambda"
133 "nonlocal"
134 "pass"
135 "print"
136 "raise"
137 "return"
138 "try"
139 "while"
140 "with"
141 "yield"
142 "match"
143 "case"
144] @keyword