2020-05-16 19:24:27 +02:00
|
|
|
;; From tree-sitter-python licensed under MIT License
|
|
|
|
|
; Copyright (c) 2016 Max Brunsfeld
|
|
|
|
|
|
2020-06-24 16:45:17 +02:00
|
|
|
; Reset highlighing in f-string interpolations
|
|
|
|
|
(interpolation) @Normal
|
2020-05-16 19:24:27 +02:00
|
|
|
|
2020-06-24 16:45:17 +02:00
|
|
|
; Identifier naming conventions
|
2020-05-27 22:23:34 +02:00
|
|
|
((identifier) @type
|
|
|
|
|
(match? @type "^[A-Z]"))
|
2020-05-16 19:24:27 +02:00
|
|
|
((identifier) @constant
|
2020-06-02 15:59:13 +02:00
|
|
|
(match? @constant "^[A-Z][A-Z_0-9]*$"))
|
2020-05-16 19:24:27 +02:00
|
|
|
|
2020-06-21 17:00:17 +02:00
|
|
|
((identifier) @constant.builtin
|
|
|
|
|
(match? @constant.builtin "^__[a-zA-Z0-9_]*__$"))
|
|
|
|
|
|
2020-07-22 16:24:39 +02:00
|
|
|
((attribute
|
|
|
|
|
attribute: (identifier) @field)
|
|
|
|
|
(match? @field "^([A-Z])@!.*$"))
|
|
|
|
|
|
2020-05-16 19:24:27 +02:00
|
|
|
; Function calls
|
|
|
|
|
|
|
|
|
|
(decorator) @function
|
2020-06-02 15:59:13 +02:00
|
|
|
((decorator (dotted_name (identifier) @function))
|
|
|
|
|
(match? @function "^([A-Z])@!.*$"))
|
|
|
|
|
|
|
|
|
|
(call
|
|
|
|
|
function: (identifier) @function)
|
2020-05-16 19:24:27 +02:00
|
|
|
|
|
|
|
|
(call
|
|
|
|
|
function: (attribute
|
|
|
|
|
attribute: (identifier) @method))
|
|
|
|
|
|
2020-06-02 15:59:13 +02:00
|
|
|
((call
|
|
|
|
|
function: (identifier) @constructor)
|
|
|
|
|
(match? @constructor "^[A-Z]"))
|
2020-05-16 19:24:27 +02:00
|
|
|
|
|
|
|
|
((call
|
2020-06-02 15:59:13 +02:00
|
|
|
function: (attribute
|
|
|
|
|
attribute: (identifier) @constructor))
|
2020-05-16 19:24:27 +02:00
|
|
|
(match? @constructor "^[A-Z]"))
|
|
|
|
|
|
|
|
|
|
;; 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 definitions
|
|
|
|
|
|
|
|
|
|
(function_definition
|
|
|
|
|
name: (identifier) @function)
|
|
|
|
|
|
2020-07-18 19:50:45 +02:00
|
|
|
((function_definition
|
|
|
|
|
name: (identifier) @method
|
|
|
|
|
parameters: (parameters
|
|
|
|
|
(identifier) @self) )
|
|
|
|
|
(eq? @self "self"))
|
|
|
|
|
|
|
|
|
|
((function_definition
|
|
|
|
|
name: (identifier) @constructor
|
|
|
|
|
parameters: (parameters
|
|
|
|
|
(identifier) @self) )
|
|
|
|
|
(eq? @self "self")
|
|
|
|
|
(match? @constructor "(__new__|__init__)"))
|
|
|
|
|
|
2020-05-16 19:24:27 +02:00
|
|
|
(type (identifier) @type)
|
2020-07-09 09:36:05 +02:00
|
|
|
(type
|
|
|
|
|
(subscript
|
|
|
|
|
(identifier) @type)) ; type subscript: Tuple[int]
|
2020-06-02 15:59:13 +02:00
|
|
|
|
|
|
|
|
((call
|
2020-05-27 22:23:34 +02:00
|
|
|
function: (identifier) @isinstance
|
|
|
|
|
arguments: (argument_list
|
|
|
|
|
(*)
|
|
|
|
|
(identifier) @type))
|
|
|
|
|
(eq? @isinstance "isinstance"))
|
|
|
|
|
|
|
|
|
|
; Normal parameters
|
2020-05-16 19:24:27 +02:00
|
|
|
(parameters
|
2020-06-02 15:59:13 +02:00
|
|
|
(identifier) @parameter)
|
2020-07-22 16:24:17 +02:00
|
|
|
; Lambda parameters
|
|
|
|
|
(lambda_parameters
|
|
|
|
|
(identifier) @parameter)
|
|
|
|
|
(lambda_parameters
|
|
|
|
|
(tuple
|
|
|
|
|
(identifier) @parameter ))
|
2020-05-27 22:23:34 +02:00
|
|
|
; Default parameters
|
|
|
|
|
(keyword_argument
|
|
|
|
|
name: (identifier) @parameter)
|
|
|
|
|
; Naming parameters on call-site
|
|
|
|
|
(default_parameter
|
|
|
|
|
name: (identifier) @parameter)
|
2020-07-08 17:35:12 +02:00
|
|
|
(typed_parameter
|
|
|
|
|
(identifier) @parameter)
|
|
|
|
|
(typed_default_parameter
|
|
|
|
|
(identifier) @parameter)
|
2020-05-27 22:23:34 +02:00
|
|
|
; Variadic parameters *args, **kwargs
|
|
|
|
|
(parameters
|
|
|
|
|
(list_splat ; *args
|
2020-06-02 15:59:13 +02:00
|
|
|
(identifier) @parameter))
|
2020-05-27 22:23:34 +02:00
|
|
|
(parameters
|
|
|
|
|
(dictionary_splat ; **kwargs
|
2020-06-02 15:59:13 +02:00
|
|
|
(identifier) @parameter))
|
2020-05-27 22:23:34 +02:00
|
|
|
|
2020-05-16 19:24:27 +02:00
|
|
|
|
|
|
|
|
; Literals
|
|
|
|
|
|
|
|
|
|
(none) @constant.builtin
|
2020-06-21 16:32:25 +02:00
|
|
|
[(true) (false)] @boolean
|
2020-05-16 19:24:27 +02:00
|
|
|
((identifier) @constant.builtin
|
|
|
|
|
(match? @constant.builtin "self"))
|
|
|
|
|
|
|
|
|
|
(integer) @number
|
|
|
|
|
(float) @float
|
|
|
|
|
|
|
|
|
|
(comment) @comment
|
|
|
|
|
(string) @string
|
2020-06-02 15:59:13 +02:00
|
|
|
(escape_sequence) @string.escape
|
2020-05-16 19:24:27 +02:00
|
|
|
|
|
|
|
|
; Tokens
|
|
|
|
|
|
2020-06-21 16:32:25 +02:00
|
|
|
[
|
|
|
|
|
"-"
|
|
|
|
|
"-="
|
2020-06-24 16:42:55 +02:00
|
|
|
":="
|
2020-06-21 16:32:25 +02:00
|
|
|
"!="
|
|
|
|
|
"*"
|
|
|
|
|
"**"
|
|
|
|
|
"**="
|
|
|
|
|
"*="
|
|
|
|
|
"/"
|
|
|
|
|
"//"
|
|
|
|
|
"//="
|
|
|
|
|
"/="
|
|
|
|
|
"&"
|
|
|
|
|
"%"
|
|
|
|
|
"%="
|
|
|
|
|
"^"
|
|
|
|
|
"+"
|
|
|
|
|
"+="
|
|
|
|
|
"<"
|
|
|
|
|
"<<"
|
|
|
|
|
"<="
|
|
|
|
|
"<>"
|
|
|
|
|
"="
|
|
|
|
|
"=="
|
|
|
|
|
">"
|
|
|
|
|
">="
|
|
|
|
|
">>"
|
|
|
|
|
"|"
|
|
|
|
|
"~"
|
|
|
|
|
"and"
|
|
|
|
|
"in"
|
|
|
|
|
"is"
|
|
|
|
|
"not"
|
|
|
|
|
"or"
|
2020-08-14 12:57:18 +02:00
|
|
|
"->"
|
2020-06-21 16:32:25 +02:00
|
|
|
] @operator
|
2020-05-16 19:24:27 +02:00
|
|
|
|
|
|
|
|
; Keywords
|
|
|
|
|
|
2020-06-21 16:32:25 +02:00
|
|
|
[
|
|
|
|
|
"assert"
|
2020-06-30 08:14:47 +02:00
|
|
|
"async"
|
2020-06-21 16:32:25 +02:00
|
|
|
"await"
|
|
|
|
|
"class"
|
|
|
|
|
"def"
|
|
|
|
|
"del"
|
|
|
|
|
"except"
|
|
|
|
|
"exec"
|
|
|
|
|
"finally"
|
|
|
|
|
"global"
|
|
|
|
|
"lambda"
|
|
|
|
|
"nonlocal"
|
|
|
|
|
"pass"
|
|
|
|
|
"print"
|
|
|
|
|
"raise"
|
|
|
|
|
"return"
|
|
|
|
|
"try"
|
|
|
|
|
"with"
|
|
|
|
|
"yield"
|
|
|
|
|
] @keyword
|
|
|
|
|
|
|
|
|
|
[ "as" "from" "import"] @include
|
|
|
|
|
|
|
|
|
|
[ "if" "elif" "else" ] @conditional
|
|
|
|
|
|
|
|
|
|
[ "for" "while" "break" "continue" ] @repeat
|
|
|
|
|
|
|
|
|
|
[ "(" ")" "[" "]" "{" "}"] @punctuation.bracket
|
2020-06-02 15:59:13 +02:00
|
|
|
|
|
|
|
|
(interpolation
|
|
|
|
|
"{" @punctuation.special
|
|
|
|
|
"}" @punctuation.special) @embedded
|
2020-05-16 19:24:27 +02:00
|
|
|
|
2020-08-14 12:57:18 +02:00
|
|
|
[ "," "." ":" (ellipsis) ] @punctuation.delimiter
|
2020-05-16 19:24:27 +02:00
|
|
|
|
2020-06-02 15:59:13 +02:00
|
|
|
; Class definitions
|
|
|
|
|
|
2020-05-16 19:24:27 +02:00
|
|
|
(class_definition
|
|
|
|
|
name: (identifier) @type)
|
2020-05-27 22:23:34 +02:00
|
|
|
(class_definition
|
2020-06-02 15:59:13 +02:00
|
|
|
superclasses: (argument_list
|
2020-05-27 22:23:34 +02:00
|
|
|
(identifier) @type))
|
2020-05-16 19:24:27 +02:00
|
|
|
|
|
|
|
|
((class_definition
|
|
|
|
|
body: (block
|
|
|
|
|
(expression_statement
|
|
|
|
|
(assignment
|
|
|
|
|
left: (expression_list
|
2020-06-02 15:59:13 +02:00
|
|
|
(identifier) @field)))))
|
|
|
|
|
(match? @field "^([A-Z])@!.*$"))
|
2020-05-16 19:24:27 +02:00
|
|
|
|
|
|
|
|
;; Error
|
|
|
|
|
(ERROR) @error
|