highlights(python): use any-of?

This commit is contained in:
Stephan Seitz 2021-05-15 12:29:55 +02:00 committed by Thomas Vigouroux
parent efbb1c66d2
commit fe4f320b66

View file

@ -17,18 +17,34 @@
(#match? @constant.builtin "^__[a-zA-Z0-9_]*__$")) (#match? @constant.builtin "^__[a-zA-Z0-9_]*__$"))
((identifier) @constant.builtin ((identifier) @constant.builtin
(#vim-match? @constant.builtin (#any-of? @constant.builtin
;; https://docs.python.org/3/library/constants.html ;; https://docs.python.org/3/library/constants.html
"^(NotImplemented|Ellipsis|quit|exit|copyright|credits|license)$")) "NotImplemented"
"Ellipsis"
"quit"
"exit"
"copyright"
"credits"
"license"))
((attribute ((attribute
attribute: (identifier) @field) attribute: (identifier) @field)
(#vim-match? @field "^([A-Z])@!.*$")) (#vim-match? @field "^([A-Z])@!.*$"))
((identifier) @type.builtin ((identifier) @type.builtin
(#vim-match? @type.builtin (#any-of? @type.builtin
;; https://docs.python.org/3/library/exceptions.html ;; https://docs.python.org/3/library/exceptions.html
"^(BaseException|Exception|ArithmeticError|BufferError|LookupError|AssertionError|AttributeError|EOFError|FloatingPointError|GeneratorExit|ImportError|ModuleNotFoundError|IndexError|KeyError|KeyboardInterrupt|MemoryError|NameError|NotImplementedError|OSError|OverflowError|RecursionError|ReferenceError|RuntimeError|StopIteration|StopAsyncIteration|SyntaxError|IndentationError|TabError|SystemError|SystemExit|TypeError|UnboundLocalError|UnicodeError|UnicodeEncodeError|UnicodeDecodeError|UnicodeTranslateError|ValueError|ZeroDivisionError|EnvironmentError|IOError|WindowsError|BlockingIOError|ChildProcessError|ConnectionError|BrokenPipeError|ConnectionAbortedError|ConnectionRefusedError|ConnectionResetError|FileExistsError|FileNotFoundError|InterruptedError|IsADirectoryError|NotADirectoryError|PermissionError|ProcessLookupError|TimeoutError|Warning|UserWarning|DeprecationWarning|PendingDeprecationWarning|SyntaxWarning|RuntimeWarning|FutureWarning|ImportWarning|UnicodeWarning|BytesWarning|ResourceWarning)$")) "BaseException" "Exception" "ArithmeticError" "BufferError" "LookupError" "AssertionError" "AttributeError"
"EOFError" "FloatingPointError" "GeneratorExit" "ImportError" "ModuleNotFoundError" "IndexError" "KeyError"
"KeyboardInterrupt" "MemoryError" "NameError" "NotImplementedError" "OSError" "OverflowError" "RecursionError"
"ReferenceError" "RuntimeError" "StopIteration" "StopAsyncIteration" "SyntaxError" "IndentationError" "TabError"
"SystemError" "SystemExit" "TypeError" "UnboundLocalError" "UnicodeError" "UnicodeEncodeError" "UnicodeDecodeError"
"UnicodeTranslateError" "ValueError" "ZeroDivisionError" "EnvironmentError" "IOError" "WindowsError"
"BlockingIOError" "ChildProcessError" "ConnectionError" "BrokenPipeError" "ConnectionAbortedError"
"ConnectionRefusedError" "ConnectionResetError" "FileExistsError" "FileNotFoundError" "InterruptedError"
"IsADirectoryError" "NotADirectoryError" "PermissionError" "ProcessLookupError" "TimeoutError" "Warning"
"UserWarning" "DeprecationWarning" "PendingDeprecationWarning" "SyntaxWarning" "RuntimeWarning"
"FutureWarning" "ImportWarning" "UnicodeWarning" "BytesWarning" "ResourceWarning"))
; Function calls ; Function calls
@ -59,8 +75,13 @@
((call ((call
function: (identifier) @function.builtin) function: (identifier) @function.builtin)
(vim-match? @function.builtin (any-of? @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__)$")) "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 definitions
@ -241,14 +262,14 @@
(block (block
(function_definition (function_definition
name: (identifier) @constructor))) name: (identifier) @constructor)))
(#vim-match? @constructor "^(__new__|__init__)$")) (#any-of? @constructor "__new__" "__init__"))
; First parameter of a method is self or cls. ; First parameter of a method is self or cls.
((class_definition ((class_definition
body: (block body: (block
(function_definition (function_definition
parameters: (parameters . (identifier) @variable.builtin)))) parameters: (parameters . (identifier) @variable.builtin))))
(#vim-match? @variable.builtin "^(self|obj|cls)$")) (#any-of? @variable.builtin "self" "obj" "class"))
;; Error ;; Error
(ERROR) @error (ERROR) @error