blob: 8bac99e50d137e0dc50e531e24376a7b18d44cc2 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
|
;; From tree-sitter-python licensed under MIT License
; Copyright (c) 2016 Max Brunsfeld
; Reset highlighing in f-string interpolations
(interpolation) @Normal
; Identifier naming conventions
((identifier) @type
(match? @type "^[A-Z]"))
((identifier) @constant
(match? @constant "^[A-Z][A-Z_0-9]*$"))
((identifier) @constant.builtin
(match? @constant.builtin "^__[a-zA-Z0-9_]*__$"))
((attribute
attribute: (identifier) @field)
(match? @field "^([A-Z])@!.*$"))
; Function calls
(decorator) @function
((decorator (dotted_name (identifier) @function))
(match? @function "^([A-Z])@!.*$"))
(call
function: (identifier) @function)
(call
function: (attribute
attribute: (identifier) @method))
((call
function: (identifier) @constructor)
(match? @constructor "^[A-Z]"))
((call
function: (attribute
attribute: (identifier) @constructor))
(match? @constructor "^[A-Z]"))
;; Builtin functions
((call
function: (identifier) @function.builtin)
(vim-match?
@function.builtin
"^(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__)$"))
;; Function definitions
(function_definition
name: (identifier) @function)
((function_definition
name: (identifier) @method
parameters: (parameters
(identifier) @self) )
(eq? @self "self"))
((function_definition
name: (identifier) @constructor
parameters: (parameters
(identifier) @self) )
(eq? @self "self")
(vim-match? @constructor "(__new__|__init__)"))
(type (identifier) @type)
(type
(subscript
(identifier) @type)) ; type subscript: Tuple[int]
((call
function: (identifier) @isinstance
arguments: (argument_list
(*)
(identifier) @type))
(eq? @isinstance "isinstance"))
; Normal parameters
(parameters
(identifier) @parameter)
((identifier) @parameter.reference
(#is? @parameter.reference parameter))
; Lambda parameters
(lambda_parameters
(identifier) @parameter)
(lambda_parameters
(tuple
(identifier) @parameter ))
; Default parameters
(keyword_argument
name: (identifier) @parameter)
; Naming parameters on call-site
(default_parameter
name: (identifier) @parameter)
(typed_parameter
(identifier) @parameter)
(typed_default_parameter
(identifier) @parameter)
; Variadic parameters *args, **kwargs
(parameters
(list_splat ; *args
(identifier) @parameter))
(parameters
(dictionary_splat ; **kwargs
(identifier) @parameter))
; Literals
(none) @constant.builtin
[(true) (false)] @boolean
((identifier) @constant.builtin
(match? @constant.builtin "self"))
(integer) @number
(float) @float
(comment) @comment
(string) @string
(escape_sequence) @string.escape
; Tokens
[
"-"
"-="
":="
"!="
"*"
"**"
"**="
"*="
"/"
"//"
"//="
"/="
"&"
"%"
"%="
"^"
"+"
"+="
"<"
"<<"
"<="
"<>"
"="
"=="
">"
">="
">>"
"|"
"~"
"and"
"in"
"is"
"not"
"or"
"->"
] @operator
; Keywords
[
"assert"
"async"
"await"
"class"
"def"
"del"
"except"
"exec"
"finally"
"global"
"lambda"
"nonlocal"
"pass"
"print"
"raise"
"return"
"try"
"with"
"yield"
] @keyword
[ "as" "from" "import"] @include
[ "if" "elif" "else" ] @conditional
[ "for" "while" "break" "continue" ] @repeat
[ "(" ")" "[" "]" "{" "}"] @punctuation.bracket
(interpolation
"{" @punctuation.special
"}" @punctuation.special) @embedded
[ "," "." ":" (ellipsis) ] @punctuation.delimiter
; Class definitions
(class_definition
name: (identifier) @type)
(class_definition
superclasses: (argument_list
(identifier) @type))
((class_definition
body: (block
(expression_statement
(assignment
left: (expression_list
(identifier) @field)))))
(match? @field "^([A-Z])@!.*$"))
;; Error
(ERROR) @error
|