blob: 352940727630c13672f1dc7692f21d0d46711d4c (
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
|
; Builtin functions
((call
function: (identifier) @function.builtin)
(#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 calls
(call
function: (attribute attribute: (identifier) @constructor)
(#match? @constructor "^[A-Z]"))
(call
function: (identifier) @constructor
(#match? @constructor "^[A-Z]"))
(call
function: (attribute attribute: (identifier) @function.method))
(call
function: (identifier) @function)
; Function definitions
(function_definition
name: (identifier) @constructor
(#match? @constructor "^(__new__|__init__)$"))
(function_definition
name: (identifier) @function)
; Decorators
(decorator) @function
(decorator (identifier) @function)
; Parameters
((identifier) @variable.builtin
(#match? @variable.builtin "^(self|cls)$"))
(parameters (identifier) @variable.parameter)
(parameters (typed_parameter (identifier) @variable.parameter))
(parameters (default_parameter name: (identifier) @variable.parameter))
(parameters (typed_default_parameter name: (identifier) @variable.parameter))
(keyword_argument name: (identifier) @variable.parameter)
; Types
((identifier) @type.builtin
(#match?
@type.builtin
"^(bool|bytes|dict|float|frozenset|int|list|set|str|tuple)$"))
; In type hints make everything types to catch non-conforming identifiers
; (e.g., datetime.datetime) and None
(type [(identifier) (none)] @type)
; Handle [] . and | nesting 4 levels deep
(type
(_ [(identifier) (none)]? @type
(_ [(identifier) (none)]? @type
(_ [(identifier) (none)]? @type
(_ [(identifier) (none)]? @type)))))
(class_definition name: (identifier) @type)
(class_definition superclasses: (argument_list (identifier) @type))
; Variables
((identifier) @constant
(#match? @constant "^[A-Z_]{2,}$"))
((identifier) @type
(#match? @type "^[A-Z]"))
(attribute attribute: (identifier) @variable.other.member)
(identifier) @variable
; Literals
[
(none)
(true)
(false)
] @constant.builtin
(integer) @constant.numeric.integer
(float) @constant.numeric.float
(comment) @comment
(string) @string
(escape_sequence) @constant.character.escape
(interpolation
"{" @punctuation.special
"}" @punctuation.special) @embedded
[
"-"
"-="
"!="
"*"
"**"
"**="
"*="
"/"
"//"
"//="
"/="
"&"
"%"
"%="
"^"
"+"
"->"
"+="
"<"
"<<"
"<="
"<>"
"="
":="
"=="
">"
">="
">>"
"|"
"~"
] @operator
[
"as"
"assert"
"await"
"break"
"continue"
"elif"
"else"
"except"
"finally"
"for"
"from"
"if"
"import"
"pass"
"raise"
"return"
"try"
"while"
"with"
"yield"
] @keyword.control
(for_statement "in" @keyword.control)
(for_in_clause "in" @keyword.control)
[
"and"
"async"
"class"
"def"
"del"
"exec"
"global"
"in"
"is"
"lambda"
"nonlocal"
"not"
"or"
"print"
] @keyword
|