1(parameter (identifier) @variable)
2(attribute attribute: (identifier) @property)
3(type (identifier) @type)
4
5; Function calls
6
7(decorator) @function
8
9(call
10 function: (attribute attribute: (identifier) @function.method))
11(call
12 function: (identifier) @function)
13
14; Function definitions
15
16(function_definition
17 name: (identifier) @function)
18
19; Identifier naming conventions
20
21((identifier) @type
22 (#match? @type "^[A-Z]"))
23
24((identifier) @constant
25 (#match? @constant "^_*[A-Z][A-Z\\d_]*$"))
26
27; Builtin functions
28
29((call
30 function: (identifier) @function.builtin)
31 (#match?
32 @function.builtin
33 "^(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__)$"))
34
35; Literals
36
37[
38 (none)
39 (true)
40 (false)
41] @constant.builtin
42
43[
44 (integer)
45 (float)
46] @number
47
48; Self references
49
50[
51 (parameters (identifier) @variable.special)
52 (attribute (identifier) @variable.special)
53 (#match? @variable.special "^self$")
54]
55
56(comment) @comment
57(string) @string
58(escape_sequence) @escape
59
60[
61 "("
62 ")"
63 "["
64 "]"
65 "{"
66 "}"
67] @punctuation.bracket
68
69(interpolation
70 "{" @punctuation.special
71 "}" @punctuation.special) @embedded
72
73; Docstrings.
74(function_definition
75 "async"?
76 "def"
77 name: (_)
78 (parameters)?
79 body: (block (expression_statement (string) @string.doc)))
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 "~"
112 "and"
113 "in"
114 "is"
115 "not"
116 "or"
117 "is not"
118 "not in"
119] @operator
120
121[
122 "as"
123 "assert"
124 "async"
125 "await"
126 "break"
127 "class"
128 "continue"
129 "def"
130 "del"
131 "elif"
132 "else"
133 "except"
134 "exec"
135 "finally"
136 "for"
137 "from"
138 "global"
139 "if"
140 "import"
141 "lambda"
142 "nonlocal"
143 "pass"
144 "print"
145 "raise"
146 "return"
147 "try"
148 "while"
149 "with"
150 "yield"
151 "match"
152 "case"
153] @keyword