mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-10 23:40:04 -04:00
Updated python highlights
* allow for digits in constant names * removed redundant/conflicting rules * added missing hlmap * fixed escape_sequence * more explicit @constructor assignment * added rules for function decoration identifiers
This commit is contained in:
parent
c934ea694c
commit
0b4d4b4140
2 changed files with 32 additions and 45 deletions
|
|
@ -13,6 +13,7 @@ local hlmap = vim.treesitter.TSHighlighter.hl_map
|
||||||
hlmap.error = "Error"
|
hlmap.error = "Error"
|
||||||
hlmap["punctuation.delimiter"] = "Delimiter"
|
hlmap["punctuation.delimiter"] = "Delimiter"
|
||||||
hlmap["punctuation.bracket"] = "Delimiter"
|
hlmap["punctuation.bracket"] = "Delimiter"
|
||||||
|
hlmap["punctuation.special"] = "Delimiter"
|
||||||
|
|
||||||
-- Constants
|
-- Constants
|
||||||
hlmap["constant"] = "Constant"
|
hlmap["constant"] = "Constant"
|
||||||
|
|
|
||||||
|
|
@ -3,31 +3,32 @@
|
||||||
|
|
||||||
; Identifier naming conventions
|
; Identifier naming conventions
|
||||||
|
|
||||||
|
(identifier) @Normal
|
||||||
((import_from_statement
|
|
||||||
name: (dotted_name
|
|
||||||
(identifier)) @type)
|
|
||||||
(match? @type "^[A-Z]"))
|
|
||||||
|
|
||||||
((identifier) @type
|
((identifier) @type
|
||||||
(match? @type "^[A-Z]"))
|
(match? @type "^[A-Z]"))
|
||||||
|
|
||||||
((identifier) @constant
|
((identifier) @constant
|
||||||
(match? @constant "^[A-Z][A-Z_]*$"))
|
(match? @constant "^[A-Z][A-Z_0-9]*$"))
|
||||||
|
|
||||||
; Function calls
|
; Function calls
|
||||||
|
|
||||||
(decorator) @function
|
(decorator) @function
|
||||||
|
((decorator (dotted_name (identifier) @function))
|
||||||
|
(match? @function "^([A-Z])@!.*$"))
|
||||||
|
|
||||||
|
(call
|
||||||
|
function: (identifier) @function)
|
||||||
|
|
||||||
(call
|
(call
|
||||||
function: (attribute
|
function: (attribute
|
||||||
attribute: (identifier) @method))
|
attribute: (identifier) @method))
|
||||||
|
|
||||||
(call
|
((call
|
||||||
function: (identifier) @function)
|
function: (identifier) @constructor)
|
||||||
|
(match? @constructor "^[A-Z]"))
|
||||||
|
|
||||||
((call
|
((call
|
||||||
(identifier) @constructor)
|
function: (attribute
|
||||||
|
attribute: (identifier) @constructor))
|
||||||
(match? @constructor "^[A-Z]"))
|
(match? @constructor "^[A-Z]"))
|
||||||
|
|
||||||
;; Builtin functions
|
;; Builtin functions
|
||||||
|
|
@ -43,9 +44,8 @@
|
||||||
(function_definition
|
(function_definition
|
||||||
name: (identifier) @function)
|
name: (identifier) @function)
|
||||||
|
|
||||||
(identifier) @variable
|
|
||||||
(attribute attribute: (identifier) @property)
|
|
||||||
(type (identifier) @type)
|
(type (identifier) @type)
|
||||||
|
|
||||||
((call
|
((call
|
||||||
function: (identifier) @isinstance
|
function: (identifier) @isinstance
|
||||||
arguments: (argument_list
|
arguments: (argument_list
|
||||||
|
|
@ -84,11 +84,7 @@
|
||||||
|
|
||||||
(comment) @comment
|
(comment) @comment
|
||||||
(string) @string
|
(string) @string
|
||||||
(escape_sequence) @escape
|
(escape_sequence) @string.escape
|
||||||
|
|
||||||
(interpolation
|
|
||||||
"{" @punctuation.special
|
|
||||||
"}" @punctuation.special) @embedded
|
|
||||||
|
|
||||||
; Tokens
|
; Tokens
|
||||||
|
|
||||||
|
|
@ -164,46 +160,36 @@
|
||||||
")" @punctuation.bracket
|
")" @punctuation.bracket
|
||||||
"[" @punctuation.bracket
|
"[" @punctuation.bracket
|
||||||
"]" @punctuation.bracket
|
"]" @punctuation.bracket
|
||||||
|
"{" @punctuation.bracket
|
||||||
|
"}" @punctuation.bracket
|
||||||
|
|
||||||
|
(interpolation
|
||||||
|
"{" @punctuation.special
|
||||||
|
"}" @punctuation.special) @embedded
|
||||||
|
|
||||||
"," @punctuation.delimiter
|
"," @punctuation.delimiter
|
||||||
"." @punctuation.delimiter
|
"." @punctuation.delimiter
|
||||||
":" @punctuation.delimiter
|
":" @punctuation.delimiter
|
||||||
|
|
||||||
|
; Class definitions
|
||||||
|
|
||||||
(class_definition
|
(class_definition
|
||||||
name: (identifier) @type)
|
name: (identifier) @type)
|
||||||
(class_definition
|
(class_definition
|
||||||
superclasses: (argument_list
|
superclasses: (argument_list
|
||||||
(identifier) @type))
|
(identifier) @type))
|
||||||
|
|
||||||
(attribute
|
((attribute
|
||||||
attribute: (identifier) @field)
|
attribute: (identifier) @field)
|
||||||
|
(match? @field "^([A-Z])@!.*$"))
|
||||||
((attribute
|
|
||||||
attribute: (identifier) @constant)
|
|
||||||
(match? @constant "^[A-Z][A-Z_]*$"))
|
|
||||||
|
|
||||||
((attribute
|
|
||||||
attribute: (identifier) @type)
|
|
||||||
(match? @type "^[A-Z][a-z_]+"))
|
|
||||||
|
|
||||||
((attribute
|
|
||||||
object: (identifier) @type)
|
|
||||||
(match? @type "^[A-Z][a-z_]+"))
|
|
||||||
|
|
||||||
(class_definition
|
|
||||||
body: (block
|
|
||||||
(expression_statement
|
|
||||||
(assignment
|
|
||||||
left: (expression_list
|
|
||||||
(identifier) @field)))))
|
|
||||||
|
|
||||||
((class_definition
|
((class_definition
|
||||||
body: (block
|
body: (block
|
||||||
(expression_statement
|
(expression_statement
|
||||||
(assignment
|
(assignment
|
||||||
left: (expression_list
|
left: (expression_list
|
||||||
(identifier) @constant)))))
|
(identifier) @field)))))
|
||||||
(match? @constant "^[A-Z][A-Z_]*$"))
|
(match? @field "^([A-Z])@!.*$"))
|
||||||
|
|
||||||
;; Error
|
;; Error
|
||||||
(ERROR) @error
|
(ERROR) @error
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue