diff options
| author | Santos Gallegos <stsewd@protonmail.com> | 2020-08-16 11:44:20 -0500 |
|---|---|---|
| committer | Stephan Seitz <stephan.lauf@yahoo.de> | 2020-08-16 22:00:11 +0200 |
| commit | cf37d143bf29901bb59a3215085944322566568c (patch) | |
| tree | 1ef1f57b08922045661f07de87f55362a0f26f45 /queries/python | |
| parent | Python: update locals (diff) | |
| download | nvim-treesitter-cf37d143bf29901bb59a3215085944322566568c.tar nvim-treesitter-cf37d143bf29901bb59a3215085944322566568c.tar.gz nvim-treesitter-cf37d143bf29901bb59a3215085944322566568c.tar.bz2 nvim-treesitter-cf37d143bf29901bb59a3215085944322566568c.tar.lz nvim-treesitter-cf37d143bf29901bb59a3215085944322566568c.tar.xz nvim-treesitter-cf37d143bf29901bb59a3215085944322566568c.tar.zst nvim-treesitter-cf37d143bf29901bb59a3215085944322566568c.zip | |
Python: update highlights
- Get rid of @self
- Highlight methods correctly
- Highlight self as the first parameter of a method
- Use new syntax (# for predicates, (_) instead of (*) for wildcards)
Diffstat (limited to 'queries/python')
| -rw-r--r-- | queries/python/highlights.scm | 70 |
1 files changed, 37 insertions, 33 deletions
diff --git a/queries/python/highlights.scm b/queries/python/highlights.scm index 8bac99e50..6574fdad7 100644 --- a/queries/python/highlights.scm +++ b/queries/python/highlights.scm @@ -4,24 +4,24 @@ ; Reset highlighing in f-string interpolations (interpolation) @Normal -; Identifier naming conventions +;; Identifier naming conventions ((identifier) @type - (match? @type "^[A-Z]")) + (#match? @type "^[A-Z]")) ((identifier) @constant - (match? @constant "^[A-Z][A-Z_0-9]*$")) + (#match? @constant "^[A-Z][A-Z_0-9]*$")) ((identifier) @constant.builtin - (match? @constant.builtin "^__[a-zA-Z0-9_]*__$")) + (#match? @constant.builtin "^__[a-zA-Z0-9_]*__$")) ((attribute attribute: (identifier) @field) - (match? @field "^([A-Z])@!.*$")) + (#match? @field "^([A-Z])@!.*$")) ; Function calls (decorator) @function ((decorator (dotted_name (identifier) @function)) - (match? @function "^([A-Z])@!.*$")) + (#match? @function "^([A-Z])@!.*$")) (call function: (identifier) @function) @@ -32,12 +32,12 @@ ((call function: (identifier) @constructor) - (match? @constructor "^[A-Z]")) + (#match? @constructor "^[A-Z]")) ((call function: (attribute attribute: (identifier) @constructor)) - (match? @constructor "^[A-Z]")) + (#match? @constructor "^[A-Z]")) ;; Builtin functions @@ -52,19 +52,6 @@ (function_definition name: (identifier) @function) -((function_definition - name: (identifier) @method - parameters: (parameters - (identifier) @self) ) - (eq? @self "self")) - -((function_definition - name: (identifier) @constructor - parameters: (parameters - (identifier) @self) ) - (eq? @self "self") - (vim-match? @constructor "(__new__|__init__)")) - (type (identifier) @type) (type (subscript @@ -73,9 +60,9 @@ ((call function: (identifier) @isinstance arguments: (argument_list - (*) + (_) (identifier) @type)) - (eq? @isinstance "isinstance")) + (#eq? @isinstance "isinstance")) ; Normal parameters (parameters @@ -112,7 +99,7 @@ (none) @constant.builtin [(true) (false)] @boolean ((identifier) @constant.builtin - (match? @constant.builtin "self")) + (#match? @constant.builtin "self")) (integer) @number (float) @float @@ -185,27 +172,31 @@ "yield" ] @keyword -[ "as" "from" "import"] @include +["as" "from" "import"] @include -[ "if" "elif" "else" ] @conditional +["if" "elif" "else"] @conditional -[ "for" "while" "break" "continue" ] @repeat +["for" "while" "break" "continue"] @repeat -[ "(" ")" "[" "]" "{" "}"] @punctuation.bracket +["(" ")" "[" "]" "{" "}"] @punctuation.bracket (interpolation "{" @punctuation.special "}" @punctuation.special) @embedded -[ "," "." ":" (ellipsis) ] @punctuation.delimiter +["," "." ":" (ellipsis)] @punctuation.delimiter -; Class definitions +;; Class definitions (class_definition - name: (identifier) @type) + name: (identifier) @type + body: (block + (function_definition + name: (identifier) @method))) + (class_definition superclasses: (argument_list - (identifier) @type)) + (identifier) @type)) ((class_definition body: (block @@ -213,7 +204,20 @@ (assignment left: (expression_list (identifier) @field))))) - (match? @field "^([A-Z])@!.*$")) + (#match? @field "^([A-Z])@!.*$")) + +((class_definition + (block + (function_definition + name: (identifier) @constructor))) + (#vim-match? @constructor "^(__new__|__init__)$")) + +; First parameter of a method is self or cls. +((class_definition + body: (block + (function_definition + parameters: (parameters . (identifier) @constant.builtin)))) + (#vim-match? @constant.builtin "^(self|obj|cls)$")) ;; Error (ERROR) @error |
