on 2a20301 help sign in
helix/runtime/queries/python/highlights.scm
173 lines 3.3 kB history raw
1; Builtin functions
3((call
4 function: (identifier) @function.builtin)
5 (#match?
6 @function.builtin
7 "^(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__)$"))
9; Function calls
11(call
12 function: (attribute attribute: (identifier) @constructor)
13 (#match? @constructor "^[A-Z]"))
14(call
15 function: (identifier) @constructor
16 (#match? @constructor "^[A-Z]"))
18(call
19 function: (attribute attribute: (identifier) @function.method))
21(call
22 function: (identifier) @function)
24; Function definitions
26(function_definition
27 name: (identifier) @constructor
28 (#match? @constructor "^(__new__|__init__)$"))
30(function_definition
31 name: (identifier) @function)
33; Decorators
35(decorator) @function
36(decorator (identifier) @function)
38; Parameters
40((identifier) @variable.builtin
41 (#match? @variable.builtin "^(self|cls)$"))
43(parameters (identifier) @variable.parameter)
44(parameters (typed_parameter (identifier) @variable.parameter))
45(parameters (default_parameter name: (identifier) @variable.parameter))
46(parameters (typed_default_parameter name: (identifier) @variable.parameter))
47(keyword_argument name: (identifier) @variable.parameter)
49; Types
51((identifier) @type.builtin
52 (#match?
53 @type.builtin
54 "^(bool|bytes|dict|float|frozenset|int|list|set|str|tuple)$"))
56; In type hints make everything types to catch non-conforming identifiers
57; (e.g., datetime.datetime) and None
58(type [(identifier) (none)] @type)
59; Handle [] . and | nesting 4 levels deep
60(type
61 (_ [(identifier) (none)]? @type
62 (_ [(identifier) (none)]? @type
63 (_ [(identifier) (none)]? @type
64 (_ [(identifier) (none)]? @type)))))
66(class_definition name: (identifier) @type)
67(class_definition superclasses: (argument_list (identifier) @type))
69; Variables
71((identifier) @constant
72 (#match? @constant "^[A-Z_]{2,}$"))
74((identifier) @type
75 (#match? @type "^[A-Z]"))
77(attribute attribute: (identifier) @variable.other.member)
78(identifier) @variable
80; Literals
83 (none)
84 (true)
85 (false)
86] @constant.builtin
88(integer) @constant.numeric.integer
89(float) @constant.numeric.float
90(comment) @comment
91(string) @string
92(escape_sequence) @constant.character.escape
94(interpolation
95 "{" @punctuation.special
96 "}" @punctuation.special) @embedded
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] @operator
132 "as"
133 "assert"
134 "await"
135 "break"
136 "continue"
137 "elif"
138 "else"
139 "except"
140 "finally"
141 "for"
142 "from"
143 "if"
144 "import"
145 "pass"
146 "raise"
147 "return"
148 "try"
149 "while"
150 "with"
151 "yield"
152] @keyword.control
154(for_statement "in" @keyword.control)
155(for_in_clause "in" @keyword.control)
158 "and"
159 "async"
160 "class"
161 "def"
162 "del"
163 "exec"
164 "global"
165 "in"
166 "is"
167 "lambda"
168 "nonlocal"
169 "not"
170 "or"
171 "print"
172] @keyword