highlights.scm

  1(attribute attribute: (identifier) @property)
  2(type (identifier) @type)
  3(generic_type (identifier) @type)
  4
  5; Type alias
  6(type_alias_statement "type" @keyword)
  7
  8; Identifier naming conventions
  9
 10((identifier) @type.class
 11 (#match? @type.class "^[A-Z]"))
 12
 13((identifier) @constant
 14 (#match? @constant "^_*[A-Z][A-Z\\d_]*$"))
 15
 16; TypeVar with constraints in type parameters
 17(type
 18  (tuple (identifier) @type)
 19)
 20
 21; Function calls
 22
 23(decorator
 24  "@" @punctuation.special
 25  (identifier) @function.decorator)
 26
 27(call
 28  function: (attribute attribute: (identifier) @function.method.call))
 29(call
 30  function: (identifier) @function.call)
 31
 32; Function and class definitions
 33
 34(function_definition
 35  name: (identifier) @function.definition)
 36
 37; Class definitions and calling: needs to come after the regex matching above
 38
 39(class_definition
 40  name: (identifier) @type.class.definition)
 41
 42(call
 43  function: (identifier) @type.class.call
 44  (#match? @type.class.call "^[A-Z][A-Z0-9_]*[a-z]"))
 45
 46; Builtin functions
 47
 48((call
 49  function: (identifier) @function.builtin)
 50 (#match?
 51   @function.builtin
 52   "^(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__)$"))
 53
 54; Literals
 55
 56[
 57  (none)
 58  (true)
 59  (false)
 60  (ellipsis)
 61] @constant.builtin
 62
 63[
 64  (integer)
 65  (float)
 66] @number
 67
 68; Self references
 69
 70[
 71  (parameters (identifier) @variable.special)
 72  (attribute (identifier) @variable.special)
 73  (#match? @variable.special "^self|cls$")
 74]
 75
 76(comment) @comment
 77(string) @string
 78(escape_sequence) @string.escape
 79
 80[
 81  "("
 82  ")"
 83  "["
 84  "]"
 85  "{"
 86  "}"
 87] @punctuation.bracket
 88
 89(interpolation
 90  "{" @punctuation.special
 91  "}" @punctuation.special) @embedded
 92
 93; Docstrings.
 94(function_definition
 95  "async"?
 96  "def"
 97  name: (_)
 98  (parameters)?
 99  body: (block . (expression_statement (string) @string.doc)))
100
101(class_definition
102  body: (block
103    . (comment) @comment*
104    . (expression_statement (string) @string.doc)))
105
106(module
107  . (comment) @comment*
108  . (expression_statement (string) @string.doc))
109
110(module
111  (expression_statement (assignment))
112  . (expression_statement (string) @string.doc))
113
114(class_definition
115  body: (block
116    (expression_statement (assignment))
117    . (expression_statement (string) @string.doc)))
118
119(class_definition
120  body: (block
121    (function_definition
122      name: (identifier) @function.method.constructor
123      (#eq? @function.method.constructor "__init__")
124      body: (block
125        (expression_statement (assignment))
126        . (expression_statement (string) @string.doc)))))
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  "and"
161  "in"
162  "is"
163  "not"
164  "or"
165  "is not"
166  "not in"
167] @operator
168
169[
170  "as"
171  "assert"
172  "async"
173  "await"
174  "break"
175  "class"
176  "continue"
177  "def"
178  "del"
179  "elif"
180  "else"
181  "except"
182  "exec"
183  "finally"
184  "for"
185  "from"
186  "global"
187  "if"
188  "import"
189  "lambda"
190  "nonlocal"
191  "pass"
192  "print"
193  "raise"
194  "return"
195  "try"
196  "while"
197  "with"
198  "yield"
199  "match"
200  "case"
201] @keyword