mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-01 19:17:02 -04:00
Add python/highlights.scm from tree-sitter-python
This commit is contained in:
parent
a5c50262d9
commit
57424533a7
2 changed files with 182 additions and 0 deletions
176
queries/python/highlights.scm
Normal file
176
queries/python/highlights.scm
Normal file
|
|
@ -0,0 +1,176 @@
|
|||
;; From tree-sitter-python licensed under MIT License
|
||||
; Copyright (c) 2016 Max Brunsfeld
|
||||
|
||||
; Identifier naming conventions
|
||||
|
||||
|
||||
((import_from_statement
|
||||
name: (dotted_name
|
||||
(identifier)) @type)
|
||||
(match? @type "^[A-Z]"))
|
||||
|
||||
((identifier) @constant
|
||||
(match? @constant "^[A-Z][A-Z_]*$"))
|
||||
|
||||
; Function calls
|
||||
|
||||
(decorator) @function
|
||||
|
||||
(call
|
||||
function: (attribute
|
||||
attribute: (identifier) @method))
|
||||
|
||||
(call
|
||||
function: (identifier) @function)
|
||||
|
||||
((call
|
||||
(identifier) @constructor)
|
||||
(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)
|
||||
|
||||
(identifier) @variable
|
||||
(attribute attribute: (identifier) @property)
|
||||
(type (identifier) @type)
|
||||
(parameters
|
||||
(identifier) @parameter)
|
||||
|
||||
; Literals
|
||||
|
||||
(none) @constant.builtin
|
||||
(true) @boolean
|
||||
(false) @boolean
|
||||
((identifier) @constant.builtin
|
||||
(match? @constant.builtin "self"))
|
||||
|
||||
(integer) @number
|
||||
(float) @float
|
||||
|
||||
(comment) @comment
|
||||
(string) @string
|
||||
(escape_sequence) @escape
|
||||
|
||||
(interpolation
|
||||
"{" @punctuation.special
|
||||
"}" @punctuation.special) @embedded
|
||||
|
||||
; Tokens
|
||||
|
||||
"-" @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
|
||||
"~" @operator
|
||||
"and" @operator
|
||||
"in" @operator
|
||||
"is" @operator
|
||||
"not" @operator
|
||||
"or" @operator
|
||||
|
||||
; Keywords
|
||||
|
||||
"as" @keyword
|
||||
"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
|
||||
"from" @keyword
|
||||
"global" @keyword
|
||||
"if" @conditional
|
||||
"import" @keyword
|
||||
"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
|
||||
|
||||
"," @punctuation.delimiter
|
||||
"." @punctuation.delimiter
|
||||
":" @punctuation.delimiter
|
||||
|
||||
(class_definition
|
||||
name: (identifier) @type)
|
||||
|
||||
(attribute
|
||||
attribute: (identifier) @field)
|
||||
|
||||
((attribute
|
||||
attribute: (identifier) @constant)
|
||||
(match? @constant "^[A-Z][A-Z_]*$"))
|
||||
|
||||
((attribute
|
||||
attribute: (identifier) @type)
|
||||
(match? @type "^[A-Z][a-z_]+"))
|
||||
|
||||
(class_definition
|
||||
body: (block
|
||||
(expression_statement
|
||||
(assignment
|
||||
left: (expression_list
|
||||
(identifier) @field)))))
|
||||
|
||||
((class_definition
|
||||
body: (block
|
||||
(expression_statement
|
||||
(assignment
|
||||
left: (expression_list
|
||||
(identifier) @constant)))))
|
||||
(match? @constant "^[A-Z][A-Z_]*$"))
|
||||
|
||||
;; Error
|
||||
(ERROR) @error
|
||||
|
|
@ -18,6 +18,12 @@
|
|||
(function_definition
|
||||
name: (identifier) @definition.function) @scope
|
||||
|
||||
;; Should be extended to when syntax supported
|
||||
;(function_definition
|
||||
;name: (identifier) @definition.function
|
||||
;body: (block (expression_statement (string) @definition.function.doc)?)) @scope
|
||||
|
||||
|
||||
(class_definition
|
||||
name: (identifier) @definition.type) @scope
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue