2020-05-16 19:24:27 +02:00
|
|
|
;; From tree-sitter-python licensed under MIT License
|
|
|
|
|
; Copyright (c) 2016 Max Brunsfeld
|
|
|
|
|
|
|
|
|
|
; Identifier naming conventions
|
|
|
|
|
|
2020-06-02 15:59:13 +02:00
|
|
|
(identifier) @Normal
|
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
|
|
|
|
|
|
|
|
; 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)
|
|
|
|
|
|
|
|
|
|
(type (identifier) @type)
|
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-05-27 22:23:34 +02:00
|
|
|
; Default parameters
|
|
|
|
|
(keyword_argument
|
|
|
|
|
name: (identifier) @parameter)
|
|
|
|
|
; Naming parameters on call-site
|
|
|
|
|
(default_parameter
|
|
|
|
|
name: (identifier) @parameter)
|
|
|
|
|
; 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
|
|
|
|
|
(true) @boolean
|
|
|
|
|
(false) @boolean
|
|
|
|
|
((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
|
|
|
|
|
|
|
|
|
|
"-" @operator
|
2020-05-27 22:23:34 +02:00
|
|
|
"->" @operator
|
2020-05-16 19:24:27 +02:00
|
|
|
"-=" @operator
|
|
|
|
|
"!=" @operator
|
|
|
|
|
"*" @operator
|
|
|
|
|
"**" @operator
|
|
|
|
|
"**=" @operator
|
|
|
|
|
"*=" @operator
|
|
|
|
|
"/" @operator
|
|
|
|
|
"//" @operator
|
|
|
|
|
"//=" @operator
|
|
|
|
|
"/=" @operator
|
|
|
|
|
"&" @operator
|
|
|
|
|
"%" @operator
|
|
|
|
|
"%=" @operator
|
|
|
|
|
"^" @operator
|
|
|
|
|
"+" @operator
|
|
|
|
|
"+=" @operator
|
|
|
|
|
"<" @operator
|
|
|
|
|
"<<" @operator
|
|
|
|
|
"<=" @operator
|
|
|
|
|
"<>" @operator
|
|
|
|
|
"=" @operator
|
|
|
|
|
"==" @operator
|
|
|
|
|
">" @operator
|
|
|
|
|
">=" @operator
|
|
|
|
|
">>" @operator
|
|
|
|
|
"|" @operator
|
|
|
|
|
"~" @operator
|
|
|
|
|
"and" @operator
|
|
|
|
|
"in" @operator
|
|
|
|
|
"is" @operator
|
|
|
|
|
"not" @operator
|
|
|
|
|
"or" @operator
|
|
|
|
|
|
|
|
|
|
; Keywords
|
|
|
|
|
|
2020-05-17 17:07:27 +02:00
|
|
|
"as" @include
|
2020-05-16 19:24:27 +02:00
|
|
|
"assert" @keyword
|
|
|
|
|
"async" @keyword
|
|
|
|
|
"await" @keyword
|
|
|
|
|
"break" @repeat
|
|
|
|
|
"class" @keyword
|
|
|
|
|
"continue" @repeat
|
|
|
|
|
"def" @keyword
|
|
|
|
|
"del" @keyword
|
|
|
|
|
"elif" @conditional
|
|
|
|
|
"else" @conditional
|
|
|
|
|
"except" @keyword
|
|
|
|
|
"exec" @keyword
|
|
|
|
|
"finally" @keyword
|
|
|
|
|
"for" @repeat
|
2020-05-17 17:07:27 +02:00
|
|
|
"from" @include
|
2020-05-16 19:24:27 +02:00
|
|
|
"global" @keyword
|
|
|
|
|
"if" @conditional
|
2020-05-17 17:07:27 +02:00
|
|
|
"import" @include
|
2020-05-16 19:24:27 +02:00
|
|
|
"lambda" @keyword
|
|
|
|
|
"nonlocal" @keyword
|
|
|
|
|
"pass" @keyword
|
|
|
|
|
"print" @keyword
|
|
|
|
|
"raise" @keyword
|
|
|
|
|
"return" @keyword
|
|
|
|
|
"try" @keyword
|
|
|
|
|
"while" @repeat
|
|
|
|
|
"with" @keyword
|
|
|
|
|
"yield" @keyword
|
|
|
|
|
|
|
|
|
|
; Additions for nvim-treesitter
|
|
|
|
|
"(" @punctuation.bracket
|
|
|
|
|
")" @punctuation.bracket
|
|
|
|
|
"[" @punctuation.bracket
|
|
|
|
|
"]" @punctuation.bracket
|
2020-06-02 15:59:13 +02:00
|
|
|
"{" @punctuation.bracket
|
|
|
|
|
"}" @punctuation.bracket
|
|
|
|
|
|
|
|
|
|
(interpolation
|
|
|
|
|
"{" @punctuation.special
|
|
|
|
|
"}" @punctuation.special) @embedded
|
2020-05-16 19:24:27 +02:00
|
|
|
|
|
|
|
|
"," @punctuation.delimiter
|
|
|
|
|
"." @punctuation.delimiter
|
|
|
|
|
":" @punctuation.delimiter
|
|
|
|
|
|
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
|
|
|
|
2020-05-27 22:23:34 +02:00
|
|
|
((attribute
|
2020-06-02 15:59:13 +02:00
|
|
|
attribute: (identifier) @field)
|
|
|
|
|
(match? @field "^([A-Z])@!.*$"))
|
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
|