on e680f96 help sign in
helix/runtime/queries/python/highlights.scm
172 lines 3.2 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))
48; Types
50((identifier) @type.builtin
51 (#match?
52 @type.builtin
53 "^(bool|bytes|dict|float|frozenset|int|list|set|str|tuple)$"))
55; In type hints make everything types to catch non-conforming identifiers
56; (e.g., datetime.datetime) and None
57(type [(identifier) (none)] @type)
58; Handle [] . and | nesting 4 levels deep
59(type
60 (_ [(identifier) (none)]? @type
61 (_ [(identifier) (none)]? @type
62 (_ [(identifier) (none)]? @type
63 (_ [(identifier) (none)]? @type)))))
65(class_definition name: (identifier) @type)
66(class_definition superclasses: (argument_list (identifier) @type))
68; Variables
70((identifier) @constant
71 (#match? @constant "^[A-Z_]{2,}$"))
73((identifier) @type
74 (#match? @type "^[A-Z]"))
76(attribute attribute: (identifier) @variable.other.member)
77(identifier) @variable
79; Literals
82 (none)
83 (true)
84 (false)
85] @constant.builtin
87(integer) @constant.numeric.integer
88(float) @constant.numeric.float
89(comment) @comment
90(string) @string
91(escape_sequence) @constant.character.escape
93(interpolation
94 "{" @punctuation.special
95 "}" @punctuation.special) @embedded
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] @operator
131 "as"
132 "assert"
133 "await"
134 "break"
135 "continue"
136 "elif"
137 "else"
138 "except"
139 "finally"
140 "for"
141 "from"
142 "if"
143 "import"
144 "pass"
145 "raise"
146 "return"
147 "try"
148 "while"
149 "with"
150 "yield"
151] @keyword.control
153(for_statement "in" @keyword.control)
154(for_in_clause "in" @keyword.control)
157 "and"
158 "async"
159 "class"
160 "def"
161 "del"
162 "exec"
163 "global"
164 "in"
165 "is"
166 "lambda"
167 "nonlocal"
168 "not"
169 "or"
170 "print"
171] @keyword