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